def ended(msg, doc): logger = logging.getLogger(__name__) """Generate a document for an end-of-connection event.""" doc["info"]["subtype"] = "end_conn" addr = capture_address(msg) if not addr: logger.warning("No hostname or IP found for this server") return None doc["info"]["server"] = "self" doc["info"]["conn_addr"] = addr # isolate connection number m = END_CONN_NUMBER.search(msg) if not m: logger.warning("malformed new_conn message: no connection number found") return None # do a second search for the actual number n = ANY_NUMBER.search(m.group(0)) doc["info"]["conn_number"] = n.group(0) debug = "Returning new doc for a message of type: initandlisten: end_conn" logger.debug(debug) return doc
def ended(msg, doc): logger = logging.getLogger(__name__) """Generate a document for an end-of-connection event.""" doc["info"]["subtype"] = "end_conn" addr = capture_address(msg) if not addr: logger.warning("No hostname or IP found for this server") return None doc["info"]["server"] = "self" doc["info"]["conn_addr"] = addr # isolate connection number m = END_CONN_NUMBER.search(msg) if not m: logger.warning( "malformed new_conn message: no connection number found") return None # do a second search for the actual number n = ANY_NUMBER.search(m.group(0)) doc["info"]["conn_number"] = n.group(0) debug = "Returning new doc for a message of type: initandlisten: end_conn" logger.debug(debug) return doc
def process(msg, date): """If the given log line fits the critera for this filter, process it and create a document of the following format: doc = { "date" : date, "type" : "status", "msg" : msg, "origin_server" : name, "info" : { "state" : state, "state_code" : int, "server" : "host:port", } } """ result = criteria(msg) if result < 0: return None labels = ["STARTUP1", "PRIMARY", "SECONDARY", "RECOVERING", "FATAL", "STARTUP2", "UNKNOWN", "ARBITER", "DOWN", "ROLLBACK", "REMOVED"] doc = {} doc["date"] = date doc["type"] = "status" doc["info"] = {} doc["msg"] = msg doc["info"]["state_code"] = result doc["info"]["state"] = labels[result] # if this is a startup message, and includes server address, do something special!!! # add an extra field to capture the IP n = capture_address(msg[20:]) if n: if result == 0: doc["info"]["server"] = "self" doc["info"]["addr"] = n else: doc["info"]["server"] = n else: # if no server found, assume self is target doc["info"]["server"] = "self" return doc
def new_conn(msg, doc): """Generate a document for a new connection event.""" doc["info"]["subtype"] = "new_conn" addr = capture_address(msg) if not addr: logger.warning("No hostname or IP found for this server") return None doc["info"]["server"] = "self" doc["info"]["conn_addr"] = addr # isolate connection number m = START_CONN_NUMBER.search(msg) if not m: logger.debug("malformed new_conn message: no connection number found") return None doc["info"]["conn_number"] = m.group(0)[1:] debug = "Returning new doc for a message of type: initandlisten: new_conn" logger.debug(debug) return doc
def new_conn(msg, doc): logger = logging.getLogger(__name__) """Generate a document for a new connection event.""" doc["info"]["subtype"] = "new_conn" addr = capture_address(msg) if not addr: logger.warning("No hostname or IP found for this server") return None doc["info"]["server"] = "self" doc["info"]["conn_addr"] = addr # isolate connection number m = START_CONN_NUMBER.search(msg) if not m: logger.debug("malformed new_conn message: no connection number found") return None doc["info"]["conn_number"] = m.group(0)[1:] debug = "Returning new doc for a message of type: initandlisten: new_conn" logger.debug(debug) return doc