1. Jing Wang
  2. SADIT

Commits

wangjing  committed 1849b52

Bug Fix, no need to specify EXPORT_ABNORMAL_FLOW_PARA_FILE when this funcation is not enabled.

  • Participants
  • Parent commits b303cad
  • Branches default

Comments (0)

Files changed (2)

File Configure/Anomaly.py

View file
  • Ignore whitespace
 from .mod_util import choose_ip_addr
 
 
-EXPORT_ABNORMAL_FLOW_PARA_FILE = os.environ['EXPORT_ABNORMAL_FLOW_PARA_FILE']
+EXPORT_ABNORMAL_FLOW_PARA_FILE = os.environ.get('EXPORT_ABNORMAL_FLOW_PARA_FILE')
 
 
 # from numpy import cumsum, diff
         self._config_traffic()
 
     def _export_ip_addr(self):
+        if EXPORT_ABNORMAL_FLOW_PARA_FILE is None:
+            raise Exception("need to set EXPORT_ABNORMAL_FLOW_PARA_FILE"
+                            "environment variable before export abnormal ip"
+                            "address")
         fid = open(EXPORT_ABNORMAL_FLOW_PARA_FILE, 'w')
-        fid.write( ' '.join([str(i) for i in self.ano_node.ipdests]) )
+        fid.write(' '.join([str(i) for i in self.ano_node.ipdests]))
         fid.close()
 
+
     def export_ano_flow_para(self):
         """export para to help to export ano flows"""
         self._export_ip_addr()

File Configure/MarkovAnomaly.py

View file
  • Ignore whitespace
 import copy
 
 
-EXPORT_ABNORMAL_FLOW_PARA_FILE = os.environ['EXPORT_ABNORMAL_FLOW_PARA_FILE']
+EXPORT_ABNORMAL_FLOW_PARA_FILE = os.environ.get('EXPORT_ABNORMAL_FLOW_PARA_FILE')
 
 
 class MarkovAnomaly(Anomaly):
         # import ipdb;ipdb.set_trace()
 
     def export_ano_flow_para(self):
+        if EXPORT_ABNORMAL_FLOW_PARA_FILE is None:
+            raise Exception("need to set EXPORT_ABNORMAL_FLOW_PARA_FILE"
+                            "environment variable before export abnormal ip"
+                            "address")
+
         self.ano_flow_para = copy.deepcopy(self.ano_desc)
         self.ano_flow_para['ano_node_ipdests'] = self.ano_node.ipdests
         zdump(self.ano_flow_para, EXPORT_ABNORMAL_FLOW_PARA_FILE) # For export abnormal flows