Make PEP8 Happy

pull/2/merge
Raphaël Vinot 2015-02-24 14:31:01 +01:00
parent 59254c8246
commit 33597f97ef
1 changed files with 45 additions and 52 deletions

View File

@ -11,33 +11,29 @@
"""
import sys
import json
from pymisp import PyMISP
from cudeso import misp_key
from cudeso import misp_url
from cudeso import misp_verifycert
source = None
def init():
"""
Initialize PyMISP
Get configuration settings from config file
"""
def init():
global source
source = PyMISP(misp_url, misp_key, misp_verifycert, 'json')
def get_event(event_id):
"""
Get details of an event and add it to the result arrays
:event_id the id of the event
"""
def get_event(event_id):
global network_ip_src, network_ip_dst, network_hostname, network_domain
global app_hostname, app_domain, app_ip_src, app_ip_dst, app_ids_only
@ -52,24 +48,24 @@ def get_event(event_id):
return False
event_core = event_json["Event"]
event_threatlevel_id = event_core["threat_level_id"]
# event_threatlevel_id = event_core["threat_level_id"]
attribute_count = event_core["attribute_count"]
# attribute_count = event_core["attribute_count"]
attribute = event_core["Attribute"]
for attribute in event_core["Attribute"]:
if app_ids_only == True and attribute["to_ids"] == False:
if app_ids_only and not attribute["to_ids"]:
continue
value = attribute["value"]
title = event_core["info"]
if attribute["type"] == "ip-src" and app_ip_src == True:
if attribute["type"] == "ip-src" and app_ip_src:
network_ip_src.append([build_entry(value, event_id, title, "ip-src")])
elif attribute["type"] == "ip-dst" and app_ip_dst == True:
elif attribute["type"] == "ip-dst" and app_ip_dst:
network_ip_dst.append([build_entry(value, event_id, title, "ip-dst")])
elif attribute["type"] == "domain" and app_domain == True:
elif attribute["type"] == "domain" and app_domain:
network_domain.append([build_entry(value, event_id, title, "domain")])
elif attribute["type"] == "hostname" and app_hostname == True:
elif attribute["type"] == "hostname" and app_hostname:
network_hostname.append([build_entry(value, event_id, title, "hostname")])
else:
continue
@ -78,6 +74,7 @@ def get_event(event_id):
return
def build_entry(value, event_id, title, source):
"""
Build the line containing the entry
@ -85,13 +82,11 @@ def get_event(event_id):
:event_id id of the event
:title name of the event
:source from which set was the entry retrieved
"""
def build_entry( value, event_id , title, source ):
global app_printcomment
if app_printcomment == True:
if app_printtitle == True:
if app_printcomment:
if app_printtitle:
return "%s # Event: %s / %s (from %s) " % (value, event_id, title, source)
else:
return "%s # Event: %s (from %s) " % (value, event_id, source)
@ -99,24 +94,23 @@ def build_entry( value, event_id , title, source ):
return value
def print_events():
"""
Print the events from the result arrays
"""
def print_events():
global network_ip_src, network_ip_dst, network_domain, network_hostname
global app_hostname, app_domain, app_ip_src, app_ip_dst, app_ids_only, app_printcomment, app_printtitle
if app_ip_src == True:
if app_ip_src:
for ip in network_ip_src:
print ip[0]
if app_ip_dst == True:
if app_ip_dst:
for ip in network_ip_dst:
print ip[0]
if app_domain == True:
if app_domain:
for ip in network_domain:
print ip[0]
if app_hostname == True:
if app_hostname:
for ip in network_hostname:
print ip[0]
@ -165,4 +159,3 @@ if __name__ == '__main__':
print_events()
else:
print "No filename given, stopping."