def insert(self, attack_event):
"""Function inserts attack-related data into the database
Args:
attack_event : dictionary containing attack-related information
"""
cursor = self.connection.cursor()
try:
cursor.execute("""
INSERT INTO events (ethernet_source, ip_source, port_source, ethernet_destination, ip_destination, port_destination, ethernet_type, protocol, info, raw_packet)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)""", (
str(attack_event["ethernet_src"]),
str(attack_event["ip_src"]),
str(attack_event["port_src"]),
str(attack_event["ethernet_dst"]),
str(attack_event["ip_dst"]),
str(attack_event["port_dst"]),
str(attack_event["ethernet_type"]),
str(attack_event["protocol"]),
str(attack_event["info"]),
str(attack_event["raw_pkt"])
))
self.connection.commit()
except (AttributeError, MySQLdb.OperationalError):
logger.error('Error: Cannot insert attack event into database.')
评论列表
文章目录