本文整理汇总了Python中common.logger.Logger.debug方法的典型用法代码示例。如果您正苦于以下问题:Python Logger.debug方法的具体用法?Python Logger.debug怎么用?Python Logger.debug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common.logger.Logger
的用法示例。
在下文中一共展示了Logger.debug方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_time_period
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import debug [as 别名]
def validate_time_period(query_tokens):
log = Logger().get('reportserver.manager.utilities')
log.debug("given query_tokens:" + str(query_tokens))
uom = None
units = None
for token in query_tokens:
if '=' in token:
uom,units = token.split('=')
if uom in UnitOfMeasure.get_values(UnitOfMeasure):
units = int(units)
break
else:
uom = None
units = None
# default if we aren't given valid uom and units
#TODO: get this from a config file.
if uom is None or units is None:
uom = "days"
units = 1
log.debug("validate_time_period: " + str(uom) + ": " + str(units))
return (uom, units)
示例2: validate_port_number
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import debug [as 别名]
def validate_port_number(givenStr):
log = Logger().get('reportserver.manager.utilities')
log.debug("given str is: " + givenStr)
try:
return int(givenStr)
except Exception as e:
log.error("Error: Received invalid string to convert to int: " + givenStr)
log.error (str(e))
return None
示例3: __init__
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import debug [as 别名]
class PortManager:
# Port Manager: calls necessary managers and utilities to generate parameters for sql.
# List of valid ports it can receive is taken from the Configuration setup.
#
validPortNumbers = ()
def __init__(self):
self.g_config = GlobalConfig()
self.validPortNumbers = self.g_config.get_ports()
self.date_time_field = self.g_config.get_db_datetime_name()
self.log = Logger().get('reportserver.manager.PortManager.PortManager')
def isPortValid(self, port_number):
if (port_number in self.validPortNumbers):
return True
else:
return False
def getPort(self, port_number, uom, unit):
self.log.info("Retrieving port:" + str(port_number) + "uom:" + uom + " size: " + str(unit))
items = []
if self.isPortValid(port_number):
results = DatabaseHandler().get_json_by_time(port_number, uom, unit)
items = utilities.process_data(results)
port_json = {
'port': str(port_number),
'timespan': uom + "=" + str(unit),
'items':items
}
return port_json
def get_port_attack_count(self, tablename, unit, uom):
fromDate = dateTimeUtility.get_begin_date_iso(unit, uom)
sql = "select count(distinct session) as total_attacks from %s where %s >= '%s' " %(tablename, self.date_time_field, fromDate)
self.log.debug("sql is:" + sql)
result = DatabaseHandler().query_db(sql)[0]
return int(result['total_attacks'])
def get_unique_ips(self, tablename, unit, uom):
fromDate = dateTimeUtility.get_begin_date_iso(unit, uom)
sql = "select count(distinct peerAddress) as unique_ips from %s where %s >= '%s' " % (tablename, self.date_time_field, fromDate)
self.log.debug("sql is:" + sql)
result = DatabaseHandler().query_db(sql)[0]
return int(result['unique_ips'])
示例4: DataManager
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import debug [as 别名]
class DataManager(Thread):
"""
This is the DataManager class, it creates the database, data queue and
the condition variable for synchronization between it, the framework and
the plugins
"""
def __init__(self):
super().__init__()
self.db = Database()
self.db.create_default_database()
self.q = DataQueue()
self.condition = Condition()
self.kill = False
self.logger = Logger().get('database.datamanager.DataManager')
def run(self):
"""
This will insert all data in the queue and then once finished give up
control of the condition variable
"""
while not self.kill:
self.condition.acquire()
if self.q.check_empty():
self.condition.wait()
while not self.q.check_empty():
value = self.q.get_next_item()
Table_Insert.prepare_data_for_insertion(
self.q.dv.table_schema, value)
self.condition.notify()
self.condition.release()
def insert_data(self, data):
"""
Synchronously inserts data into the database.
:param data: A dictionary with a table name as its key and a dictionary
of column names and corresponding values as its value.
"""
self.condition.acquire()
if self.q.insert_into_data_queue(data):
self.condition.notify()
self.condition.release()
def shutdown(self):
self.kill = True
self.condition.acquire()
self.condition.notify()
self.condition.release()
self.join()
self.logger.debug('Data manager has shut down.')
示例5: __init__
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import debug [as 别名]
class DatabaseHandler:
def __init__(self):
self.global_config = GlobalConfig()
self.db_path = self.global_config['Database']['path']
self.log = Logger().get('reportserver.dao.DatabaseHandler.DatabaseHandler')
# Connect to given database.
# Defaults to the honeypot db, but another path can be passed in (mainly for testing).
# Database needs to exist first.
def connect(self, database_name):
if (database_name == None):
database_name = self.db_path
if not os.path.exists(database_name):
self.log.error("Database does not exist in path: " + database_name)
return None
try:
conn = sqlite3.connect(database_name)
except sqlite3.OperationalError as oe:
self.log.error("****Problem connecting to database*** at: " + database_name)
self.log.error(oe)
else:
return conn
# Query DB and return JSON
def query_db(self, query, args=(), one=False, db=None):
#print ("#debug args are: " +str(args))
cur = self.connect(db).cursor()
cur.execute(query, args)
r = [dict((cur.description[i][0], value) \
for i, value in enumerate(row)) for row in cur.fetchall()]
cur.connection.close()
return (r[0] if r else None) if one else r
# Unit of Measure could be "weeks", "days", "hours", "minutes".
# Return all data from the DB within that measure of time as JSON.
def get_json_by_time(self, portnumber, uom, units):
begin_date_iso = dateTimeUtility.get_begin_date_iso(uom, units)
tableName = self.global_config.get_plugin_config(portnumber)['table']
date_time_field = self.global_config.get_db_datetime_name()
# query = query_db("SELECT * FROM %s where (datetime > '%s')" % (tableName, query_date_iso))
queryString = "SELECT * FROM %s where %s >= '%s' order by id, %s" % (tableName, date_time_field, begin_date_iso, date_time_field)
#args = (tableName, date_time_field, begin_date_iso)
self.log.info("queryString is: " + str(queryString))
#print ("args to use: " + str(args))
results = self.query_db(queryString)
self.log.debug("results: " + str(results))
return results
示例6: __init__
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import debug [as 别名]
class IpsServiceHandler:
def __init__(self):
self.log = Logger().get("reportserver.manager.IpsServiceHandler.py")
def process(self, rqst, path_tokens, query_tokens):
uom = None
units = None
self.log.info("processing ipaddress request:" + str(path_tokens) + str(query_tokens))
try:
time_period = utilities.validate_time_period(query_tokens)
uom = time_period[0]
units = time_period[1]
except ValueError:
rqst.badRequest(units)
return
if len(path_tokens) == 5:
ipaddress = path_tokens[4].strip()
self.log.debug("requested: " + str(ipaddress))
if ipaddress is not None or ipaddress is not "":
try:
ipaddress = utilities.validate_ipaddress(ipaddress)
self.get_ips_data_by_time(rqst, ipaddress, uom, units)
except ValueError:
rqst.badRequest(badIpAddress)
return
elif ipaddress == None or ipaddress == "":
self.get_ips_data_by_time(rqst, "", uom, units)
else:
rqst.badRequest()
return
elif len(path_tokens) == 4:
self.get_ips_list_json(rqst, uom, units)
else:
rqst.badRequest()
return
def get_ips_data_by_time(self, rqst, ipaddress, uom, units):
ips_manager = IpsManager()
addressjsondata = ips_manager.get_data(ipaddress, uom, units)
if addressjsondata is not None:
# send response:
rqst.sendJsonResponse(addressjsondata, 200)
else:
rqst.notFound()
def get_ips_list_json(self, rqst, uom, units):
response = "{not implemented yet.}"
rqst.sendJsonResponse(response, 200)
示例7: __init__
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import debug [as 别名]
class IpsManager:
# Ips Manager: calls necessary managers and utilities to generate parameters for sql.
#
validPortNumbers = ()
def __init__(self):
self.g_config = GlobalConfig()
self.valid_port_numbers = self.g_config.get_ports()
self.date_time_field = self.g_config.get_db_datetime_name()
self.log = Logger().get('reportserver.manager.IpsManager.py')
def get_data(self, ipaddress, uom, unit):
self.log.info("Retrieving ipaddress data: " + str(ipaddress) + " uom: " + uom + " size: " + str(unit))
port_data = []
for port in self.valid_port_numbers:
results = self.get_json_by_ip(port, ipaddress, uom, unit)
items = utilities.process_data(results)
port_data.append({port:items})
port_json = {
'ipaddress': str(ipaddress),
'timespan': uom + "=" + str(unit),
'ports':port_data
}
return port_json
def get_json_by_ip(self, portnumber, ipaddress, uom, units):
begin_date_iso = dateTimeUtility.get_begin_date_iso(uom, units)
table_name = self.g_config.get_plugin_config(portnumber)['table']
date_time_field = self.g_config.get_db_datetime_name()
# query = query_db("SELECT * FROM %s where (datetime > '%s')" % (tableName, query_date_iso))
queryString = "SELECT * FROM %s where %s >= '%s' and peerAddress = '%s' order by id, %s" % (
table_name, date_time_field, begin_date_iso, ipaddress, date_time_field)
# args = (tableName, date_time_field, begin_date_iso)
self.log.info("queryString is: " + str(queryString))
# print ("args to use: " + str(args))
results = DatabaseHandler().query_db(queryString)
self.log.debug("results: " + str(results))
return results
示例8: validate_time_period
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import debug [as 别名]
def validate_time_period(query_tokens):
log = Logger().get('reportserver.manager.utilities')
log.debug("given query_tokens:" + str(query_tokens))
uom = None
units = None
for token in query_tokens:
if '=' in token:
uom,units = token.split('=')
if uom in UnitOfMeasure.get_values(UnitOfMeasure):
units = int(units)
break
else:
uom = None
units = None
#print("\n#debug validate_time_period: " + str(uom) + ": " + str(units))
return (uom, units)
示例9: IPInfoAgent
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import debug [as 别名]
class IPInfoAgent(Thread):
def __init__(self, peer_address, framework, instance_name):
super().__init__()
self.log = Logger().get('recon.ipinfoagent.IPInfoAgent')
self.peer_address = peer_address
self.cache = IPInfoCache()
self.framework = framework
self.instance_name = instance_name
def run(self):
peer_info = self.cache[self.peer_address]
if not peer_info:
request_str = 'http://ipinfo.io/' + self.peer_address
self.log.debug('making REST request to ' + request_str)
response = requests.get(request_str, timeout=10)
peer_info = response.json()
peer_info['timestamp'] = datetime.now()
if 'loc' in peer_info:
lat, long = peer_info['loc'].split(',')
peer_info['lat'] = float(lat)
peer_info['long'] = float(long)
del(peer_info['loc'])
self.cache[self.peer_address] = peer_info
else:
self.log.debug('ipinfo.io data for ' +
self.peer_address +
' is still cached')
peer_info['plugin_instance'] = self.instance_name
clean_dict = {}
known_cols = ['ip', 'hostname', 'city', 'region', 'country', 'lat',
'long', 'org', 'postal', 'timestamp', 'plugin_instance']
for col in known_cols:
if col in peer_info:
clean_dict[col] = peer_info[col]
self.framework.insert_data({'ipInfo': clean_dict})
self.log.debug('ipinfo.io data for ' +
self.peer_address +
': ' +
str(peer_info))
示例10: P0fAgent
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import debug [as 别名]
class P0fAgent(Thread):
def __init__(self, peer_address, framework, session):
super().__init__()
self.config = GlobalConfig()
self.framework = framework
self.fs_sock = self.config['Framework']['p0f.fs_sock']
self.log = Logger().get('recon.p0fagent.P0fAgent')
self.peer_address = peer_address
self.session = session
def run(self):
p0f = P0f(self.fs_sock)
peer_info = None
try:
peer_info = p0f.get_info(self.peer_address)
except P0fException as e:
self.log.warn('p0f request failed for ' +
self.peer_address +
': ' + str(e))
return
except KeyError as e:
self.log.warn('p0f couldn\'t find any info for ' +
self.peer_address)
return
except ValueError as e:
self.log.warn('p0f returned bad data for ' +
self.peer_address)
return
except FileNotFoundError as e:
self.log.error('p0f filesystem socket not found')
return
except Exception as e:
self.log.error('unknown p0f error occurred on address ' +
self.peer_address + ': ' + str(e))
return
# prettify C/null-terminated byte arrays in p0f info dict
for key in peer_info.keys():
if type(peer_info[key]) == bytes:
decoded = peer_info[key].decode('utf-8')
peer_info[key] = decoded.partition('\x00')[0]
elif type(peer_info[key]) == datetime:
peer_info[key] = peer_info[key].isoformat()
elif type(peer_info[key]) == timedelta:
peer_info[key] = str(int(peer_info[key].total_seconds()))
elif type(peer_info[key]) == int:
peer_info[key] = str(peer_info[key])
data = { 'p0f': {
'session': self.session,
'first_seen': peer_info['first_seen'],
'last_seen': peer_info['last_seen'],
'uptime': peer_info['uptime'],
'last_nat': peer_info['last_nat'],
'last_chg': peer_info['last_chg'],
'distance': peer_info['distance'],
'bad_sw': peer_info['bad_sw'],
'os_name': peer_info['os_name'],
'os_flavor': peer_info['os_flavor'],
'os_match_q': peer_info['os_match_q'],
'http_name': peer_info['http_name'],
'http_flavor': peer_info['http_flavor'],
'total_conn': peer_info['total_conn'],
'link_type': peer_info['link_type'],
'language': peer_info['language']
}
}
self.framework.insert_data(data)
self.log.debug('p0f info for ' +
self.peer_address +
': ' +
str(peer_info))
示例11: PortsServiceHandler
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import debug [as 别名]
class PortsServiceHandler():
def __init__(self):
self.log = Logger().get('reportserver.server.PortServiceHandler.PortServiceHandler')
def process(self, rqst, path_tokens, query_tokens):
uom = None
units = None
self.log.info("processing ports request:" + str(path_tokens) + str(query_tokens))
if len(query_tokens) > 0:
try:
time_period = utilities.validate_time_period(query_tokens)
uom = time_period[0]
units = time_period[1]
except ValueError:
rqst.badRequest(units)
return
# default if we aren't given valid uom and units
if uom is None or units is None:
uom = "days"
units = 1
if len(path_tokens) == 5:
portNbr = utilities.validate_port_number(path_tokens[4])
self.log.debug("requested: " + str(portNbr))
if portNbr is not None and 0 < portNbr < 9000:
self.get_port_data_by_time(rqst, portNbr, uom, units)
elif portNbr == None or "":
self.get_port_list_json(rqst, uom, units)
else:
rqst.badRequest()
return
elif len(path_tokens) == 4:
self.get_port_list_json(rqst, uom, units)
else:
rqst.badRequest()
return
def get_port_list_json(self,rqst, uom, units):
jsondata = self.construct_port_summary_list(rqst, uom, units)
rqst.sendJsonResponse(jsondata, 200)
def get_port_data_by_time(self, rqst, portnumber, uom, units):
portmgr = PortManager()
portjsondata = portmgr.getPort(portnumber, uom, units)
if portjsondata is not None:
# send response:
rqst.sendJsonResponse(portjsondata, 200)
else:
rqst.notFound()
def construct_port_summary_list(self, rqst, uom, units):
g_config = GlobalConfig()
plugins_dictionary = g_config.get_plugin_dictionary()
json_list = []
for key, val in plugins_dictionary.items():
json_list.append(self.construct_port_summary(rqst, val['port'], val['table'], uom, units))
return json_list
def construct_port_summary(self, rqst, portnumber, tablename, uom, units):
portmgr = PortManager()
port_attacks = portmgr.get_port_attack_count(tablename, uom, units)
unique_ips = portmgr.get_unique_ips(tablename, uom, units)
timespan = uom+"="+str(units)
response_json = {
'port': str(portnumber),
'total_attacks': str(port_attacks),
'unique_ipaddresses': str(unique_ips),
'timespan':timespan,
'rel_link': rqst.get_full_url_path() + "/ports/" + str(portnumber)+"?" + timespan
}
return response_json
示例12: __init__
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import debug [as 别名]
class _Framework:
def __init__(self, plugin_cfg_path, global_cfg_path):
self._global_config = GlobalConfig(plugin_cfg_path, global_cfg_path)
self._plugin_imports = {}
self._listener_list= {}
self._running_plugins_list = []
self._data_manager = None
self._shutting_down = False
self._log = None
self._pid = os.getpid()
def start(self):
self.set_shutdown_hook()
print('Press Ctrl+C to exit.')
if not self.drop_permissions():
return
self._global_config.read_global_config()
self.start_logging()
self._global_config.read_plugin_config()
self._data_manager = DataManager()
self._data_manager.start()
self.start_listeners()
def start_logging(self):
log_path = self._global_config['Framework']['logName']
log_level = self._global_config['Framework']['logLevel']
self._log = Logger(log_path, log_level).get('framework.frmwork.Framework')
self._log.info('RECCE7 started (PID %d)' % self._pid)
@staticmethod
def drop_permissions():
if os.getuid() != 0:
return True
dist_name = os.getenv('RECCE7_OS_DIST')
users_dict = {
'centos': ('nobody', 'nobody'),
'debian': ('nobody', 'nogroup')
}
if dist_name not in users_dict:
print(
'Unable to lower permission level - not continuing as\n'
'superuser. Please set the environment variable\n'
'RECCE7_OS_DIST to one of:\n\tcentos\n\tdebian\n'
'or rerun as a non-superuser.')
return False
lowperm_user = users_dict[dist_name]
nobody_uid = pwd.getpwnam(lowperm_user[0]).pw_uid
nogroup_gid = grp.getgrnam(lowperm_user[1]).gr_gid
os.setgroups([])
os.setgid(nogroup_gid)
os.setuid(nobody_uid)
os.umask(0o077)
return True
def create_import_entry(self, port, name, clsname):
imp = import_module('plugins.' + name)
self._plugin_imports[port] = getattr(imp, clsname)
def start_listeners(self):
ports = self._global_config.get_ports()
for port in ports:
plugin_config = self._global_config.get_plugin_config(port)
module = plugin_config['module']
clsname = plugin_config['moduleClass']
self.create_import_entry(port, module, clsname)
address = self._global_config['Framework']['listeningAddress']
listener = NetworkListener(address, plugin_config, self)
listener.start()
self._listener_list[port] = listener
def set_shutdown_hook(self):
signal.signal(signal.SIGINT, self.shutdown)
def shutdown(self, *args):
self._shutting_down = True
self._log.debug('Shutting down network listeners')
for listener in self._listener_list.values():
listener.shutdown()
self._log.debug('Shutting down plugins')
for plugin in self._running_plugins_list:
plugin.shutdown()
self._log.debug('Shutting down data manager')
self._data_manager.shutdown()
print('Goodbye!')
#
# Framework API
#
#.........这里部分代码省略.........