本文整理汇总了Python中common.logger.Logger.error方法的典型用法代码示例。如果您正苦于以下问题:Python Logger.error方法的具体用法?Python Logger.error怎么用?Python Logger.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common.logger.Logger
的用法示例。
在下文中一共展示了Logger.error方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import error [as 别名]
class DataQueue:
def __init__(self):
self.dataQueue = queue.Queue()
self.dv = datavalidator.DataValidator()
self.log = Logger().get('database.dataqueue.DataQueue')
"""we want to check the data here and fail early
if the data is good then we want to put it in the data queue
we will want another python script for the validations (datavalidator.py)
we need to enforce type constraints because the database will not
see datavalidator.py"""
def insert_into_data_queue(self, value):
if not self.dv.run_all_checks(value):
self.log.error('--> Validation failed! Unable to add data '
'into data queue: ' +
str(value))
return False
try:
self.dataQueue.put(value)
except queue.Full as e:
self.log.critical('Data queue is full!')
finally:
return True
def get_next_item(self):
item = self.dataQueue.get()
self.dataQueue.task_done()
return item
def check_empty(self):
result = self.dataQueue.empty()
return result
示例2: validate_port_number
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import error [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: get_date_delta
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import error [as 别名]
def get_date_delta(iso_date_from, iso_date_to):
try:
date_from = dateutil.parser.parse(iso_date_from)
date_to = dateutil.parser.parse(iso_date_to)
delta = date_to - date_from
except Exception as e:
log = Logger().get('reportserver.manager.utilities')
log.error("Error: " + str(e))
delta = 0
return str(delta)
示例4: __init__
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import error [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:
self.log.error("Problem connecting to database at: " + database_name)
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
示例5: NetworkListener
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import error [as 别名]
class NetworkListener(Thread):
def __init__(self, listening_address, config, framework):
super().__init__()
self._config = config
self._listening_address = listening_address
self._port = config['port']
self._framework = framework
self._session_socket = None
self._lock = Lock()
self._running = False
self.__connection_count = 0
self._logger = Logger().get('framework.networklistener.NetworkListener')
@property
def connection_count(self):
with self._lock:
return self.__connection_count
@connection_count.setter
def connection_count(self, val):
with self._lock:
self.__connection_count = val
# Override
def run(self):
self._running = True
self._logger.info('%s plugin listener started on port %d'
% (self._config['moduleClass'], self._port))
while self._running:
self._session_socket = socket.socket(
socket.AF_INET, socket.SOCK_STREAM)
self._session_socket.setsockopt(
socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self._session_socket.bind((self._listening_address, self._port))
self._session_socket.listen(1)
self.start_listening(self._session_socket)
self._session_socket.close()
self.connection_count += 1
self._logger.info('%s plugin listener on port %d shutting down'
% (self._config['moduleClass'], self._port))
self._session_socket = None
def start_listening(self, local_socket):
try:
(new_socket, addr) = local_socket.accept()
if self._running:
self._logger.info('New connection from %s on port %d'
% (addr, self._port))
self._framework.spawn(new_socket, self._config)
except ConnectionAbortedError as e:
if not self._running:
return
raise e
except OSError as e:
if e.errno == 22 and not self._running:
return
raise e
except Exception as e:
self._logger.error('Error on connection: %s' % e)
raise e
def shutdown(self):
self._running = False
if self._session_socket:
if platform.system() == 'Linux':
self._session_socket.shutdown(socket.SHUT_RDWR)
else:
self._session_socket.close()
self.join()
示例6: __init__
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import error [as 别名]
class DataValidator:
def __init__(self):
self.config = GlobalConfig()
self.table_schema = {}
self.tables = []
self.log = Logger().get('database.datavalidator.DataValidator')
self.get_schema_from_database()
# for updating tables and table schema class variables
def update_tables_and_schema(self):
self.table_schema.clear()
self.tables.clear()
self.get_schema_from_database()
def get_schema_from_database(self):
connection = sqlite3.connect(self.config['Database']['path'])
cursor = connection.cursor()
#will want to loop here through all tables found and store each schema
#as an element in a list, this will require code changes throughout this file
db_rows = cursor.execute(
"SELECT name "
"FROM sqlite_master "
"WHERE type = 'table';").fetchall()
#transform list of tuples to a list of strings
for row in db_rows:
self.tables.append(row[0])
for table in self.tables:
table_def = cursor.execute('PRAGMA table_info(' + table + ');').fetchall()
self.table_schema[table] = table_def
cursor.close()
# return the class level variable tables
def get_tables(self):
return self.tables
# return the class level variable table_schema
def get_schema(self):
return self.table_schema
# Ensure exactly one table is written to at a time
def check_value_len(self, value):
if len(value) != 1:
self.log.error('Plugin tried to save ' +
str(len(value)) +
'table(s) in one save')
return False
return True
# Checks that the value is actually a dictionary
def check_value_is_dict(self, value):
if not isinstance(value, dict):
self.log.error('Plugin attempted to save non-dictionary type: ' +
str(type(value)))
return False
return True
# Checks that the key in the dictionary is a string
def check_key_in_dict_string(self, value):
key = get_first_key_value_of_dictionary(value)
if not isinstance(key, str):
self.log.error('Table name must be a string: got ' +
str(type(key)) +
' instead')
return False
return True
# Checks that the key in the dictionary is
# a real table name in the database
def check_key_is_valid_table_name(self,value):
table_name = get_first_key_value_of_dictionary(value)
if table_name not in self.tables:
self.log.error('No such table: ' + table_name)
return False
return True
# Checks that the row data is actually a dictionary
def check_row_value_is_dict(self,value):
key = get_first_key_value_of_dictionary(value)
if not isinstance(value.get(key), dict):
self.log.error('Row data must be a dictionary: got ' +
str(type(value.get(key))) +
' instead')
return False
return True
#checks that all of the keys in the row data are strings
def check_all_col_names_strings(self,value):
key = get_first_key_value_of_dictionary(value)
dict = value.get(key)
count = len(dict.keys())
compare = 0
for key in dict.keys():
if isinstance(key,str):
compare += 1
return count == compare
# Verifies that no additional columns were provided by a
# plugin that aren't referred to in the database schema.
def check_all_col_exist(self, value):
key = get_first_key_value_of_dictionary(value)
#.........这里部分代码省略.........
示例7: P0fAgent
# 需要导入模块: from common.logger import Logger [as 别名]
# 或者: from common.logger.Logger import error [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))