def notify(timestamp: int, node: valid_node_name, cage: valid_cage_name, level: one_of("INFO", "WARNING", "ERROR", "ALERT"), message: str): assert __cage__ == "health_monitor" current_timestamp = int(time()) message_ts = localtime(timestamp) current_ts = localtime(current_timestamp) if abs(timestamp - current_timestamp) <= 5: time_mark = "" elif message_ts.tm_yday == current_ts.tm_yday: time_mark = strftime(" (%H:%M:%S)", message_ts) else: time_mark = strftime(" (%Y-%m-%d %H:%M:%S)", message_ts) message = "{0:s}.{1:s}{2:s}: {3:s}".format(node, cage, time_mark, message) if level == "INFO": pmnc.notify.info(message) elif level == "WARNING": pmnc.notify.warning(message) elif level == "ERROR": pmnc.notify.error(message) elif level == "ALERT": pmnc.notify.alert(message)
def __init__(self, name: str, *, server_address: (str, int), connect_timeout: float, response_timeout: float, ping_interval: optional(float), system_id: str, password: str, system_type: str, esme_ton: byte, esme_npi: byte, esme_addr: str, esme_type: one_of("rcvr", "xmit", "xcvr"), request_timeout: optional(float) = None, **kwargs): # this kwargs allows for extra application-specific # settings in config_interface_smpp_X.py self._name = name self._response_timeout = response_timeout if ping_interval: self._ping_timeout = Timeout(ping_interval) self._ping_response_timeout = Timeout(response_timeout) else: self._ping_timeout = self._ping_response_timeout = None self._ping_request = None self._in_q = InterlockedQueue() self._out_q = InterlockedQueue() self._inflight = InflightRequests() self._ceased = Event() if esme_type == "rcvr": bind_pdu = BindReceiverPDU elif esme_type == "xmit": bind_pdu = BindTransmitterPDU elif esme_type == "xcvr": bind_pdu = BindTransceiverPDU self._create_connection = \ lambda: _SMPPConnection(name, self._in_q, self._out_q, self._inflight, server_address = server_address, connect_timeout = connect_timeout, response_timeout = response_timeout, system_id = system_id, password = password, system_type = system_type, esme_ton = esme_ton, esme_npi = esme_npi, esme_addr = esme_addr, bind_pdu = bind_pdu) self._request_timeout = request_timeout or \ pmnc.config_interfaces.get("request_timeout") # this is now static if pmnc.request.self_test == __name__: # self-test self._process_request = kwargs["process_request"]
def notify(timestamp: int, node: valid_node_name, cage: valid_cage_name, level: one_of("INFO", "WARNING", "ERROR", "ALERT"), message: str): assert __cage__ == "health_monitor" current_timestamp = int(time()) message_ts = localtime(timestamp) current_ts = localtime(current_timestamp) if abs(timestamp - current_timestamp) <= 5: time_mark = "" elif message_ts.tm_yday == current_ts.tm_yday: time_mark = strftime(" (%H:%M:%S)", message_ts) else: time_mark = strftime(" (%Y-%m-%d %H:%M:%S)", message_ts) pmnc.log.message("[{0:s}] {1:s}.{2:s}{3:s}: {4:s}".\ format(level, node, cage, time_mark, message))
def __init__(self, name: str, *, source_addr_ton: byte, source_addr_npi: byte, source_addr: str, asynchronous: bool, pack_7bit: optional(bool) = None, frag_method: optional(one_of("sar", "udh")) = None): TransactionalResource.__init__(self, name) self._interface_name = name.split("/", 1)[0] self._source_addr_ton = source_addr_ton self._source_addr_npi = source_addr_npi self._source_addr = source_addr self._asynchronous = asynchronous self._pack_7bit = pack_7bit or False self._frag_method = frag_method self._interface = None
def __init__(self, name: str, in_q: with_attr("push"), out_q: with_attr("pop"), inflight: with_attr("add", "remove"), *, server_address: (str, int), connect_timeout: float, response_timeout: float, system_id: str, password: str, system_type: str, esme_ton: byte, esme_npi: byte, esme_addr: str, bind_pdu: one_of(BindReceiverPDU, BindTransmitterPDU, BindTransceiverPDU)): self._name = name # input and output queues and inflight requests registry are external # to the connection object and remain persistent across disconnects to # prevent losing packets self._in_q = in_q self._out_q = out_q self._inflight = inflight self._server_address = server_address self._connect_timeout = connect_timeout self._response_timeout = response_timeout self._bind_pdu = \ bind_pdu.create(system_id = system_id.encode("ascii", "replace"), password = password.encode("ascii", "replace"), system_type = system_type.encode("ascii", "replace"), interface_version = 0x34, addr_ton = esme_ton, addr_npi = esme_npi, address_range = esme_addr.encode("ascii", "replace")) self._bound = Event() self._failed = Event()
def wu_process_event(self, node: str, cage: str, up_down: one_of("up", "down"), probe_result: optional(dict)): try: # see for how long the request was on the execution queue up to this moment # and whether it has expired in the meantime, if it did there is no reason # to proceed and we simply bail out if pmnc.request.expired: pmnc.log.error("request has expired and will not be processed") success = False return # goes through finally section below with pmnc.performance.request_processing(): self._process_event(node, cage, up_down, probe_result) except: pmnc.log.error(exc_string()) # log and ignore success = False else: success = True finally: # the request ends itself pmnc.interfaces.end_request(success) # possibly way after deadline