This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository mum. See http://git.chorem.org/mum.git commit 7fe4e89a17f134660bcb69a2c1e9fe2f78abee8b Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Feb 25 15:28:05 2015 +0100 first part of ProcessMonitoring --- app/modules/storage_modules/shelve_db.py | 58 ++++++++++++++++++-------------- app/process_monitoring.py | 58 ++++++++++++++++++++++++++++++++ static/js/controllers/mainCtrl.js | 2 +- views/scan.html | 4 +-- 4 files changed, 94 insertions(+), 28 deletions(-) diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 5c78984..ef26d36 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -64,8 +64,13 @@ class shelve_db: self.db["hosts"][addr_host]["detected"]["nmap"] = nmap_res # Preconfiguration self.db["hosts"][addr_host]["conf"] = {} - self.db["hosts"][addr_host]["conf"]["monitoring"] = self.generate_global_conf(dict_mod_info, - json.loads(nmap_res)['os']) + os_host = json.loads(nmap_res)['os'] + if os_host == 'unknown': + # TODO : may throw exception here + print "OS of " + addr_host + " cannot have been detected. Monitoring cannot be autoconfigurated." + self.db["hosts"][addr_host]["conf"]["monitoring"] = {} + else: + self.db["hosts"][addr_host]["conf"]["monitoring"] = self.generate_global_conf(dict_mod_info, os_host) self.db["hosts"][addr_host]["conf"]["groups"] = ["all"] # Every host is in group "all" self.db["hosts"][addr_host]["conf"]["connections"] = self.init_conn(json.loads(nmap_res), list_mod_conn) self.db["hosts"][addr_host]["conf"]["subscribers"] = {} # Add current user automatically ? @@ -89,29 +94,32 @@ class shelve_db: :return a list containing the default parameters for each monitoring module """ res = {} - for mod in dict_mod_info[os]: - mod_conf = {} - mod_conf['block'] = dict_mod_info[os][mod]['block'] - mod_conf['activated'] = True - mod_conf['check_frequency'] = 60 - mod_conf['nb_minute'] = 30 - mod_conf['nb_hour'] = 12 - mod_conf['nb_day'] = 15 - mod_conf['nb_week'] = 2 - mod_conf['nb_month'] = 6 - mod_conf['nb_year'] = None - unit = dict_mod_info[os][mod]['unit'] - mod_conf['unit'] = unit - if unit == '%': - mod_conf['minor_limit'] = 95 - mod_conf['major_limit'] = 100 - elif unit == 'bool': - mod_conf['minor_limit'] = True - mod_conf['major_limit'] = False - else: - mod_conf['minor_limit'] = 8 - mod_conf['major_limit'] = 10 - res[mod] = mod_conf + if os not in dict_mod_info: + print "OS " + os + " is not supported by the monitoring modules currently loaded." + else: + for mod in dict_mod_info[os]: + mod_conf = {} + mod_conf['block'] = dict_mod_info[os][mod]['block'] + mod_conf['activated'] = True + mod_conf['check_frequency'] = 60 + mod_conf['nb_minute'] = 30 + mod_conf['nb_hour'] = 12 + mod_conf['nb_day'] = 15 + mod_conf['nb_week'] = 2 + mod_conf['nb_month'] = 6 + mod_conf['nb_year'] = None + unit = dict_mod_info[os][mod]['unit'] + mod_conf['unit'] = unit + if unit == '%': + mod_conf['minor_limit'] = 95 + mod_conf['major_limit'] = 100 + elif unit == 'bool': + mod_conf['minor_limit'] = True + mod_conf['major_limit'] = False + else: + mod_conf['minor_limit'] = 8 + mod_conf['major_limit'] = 10 + res[mod] = mod_conf return res def init_conn(self, dict_nmap_res, conn_list): diff --git a/app/process_monitoring.py b/app/process_monitoring.py new file mode 100644 index 0000000..7c76a41 --- /dev/null +++ b/app/process_monitoring.py @@ -0,0 +1,58 @@ +__author__ = 'aguilbaud' + +import threading +from datetime import datetime +from datetime import timedelta +import time + + +class ProcessMonitoring(threading.Thread): + """ + Runs the monitoring modules at the specified time. + Attributes : - waiting_queue : a list containing structured data concerning the monitring modules to launch + in the form + { + 'addr' : val, => the IP address of the host + 'os', val, => the operating system of the host + 'mod_name', val, => the name of the monitoring module + 'time', val, => the time at when to launch the monitoring module + 'freq', val => the frequency check (in seconds) + } + The data are ordored by crescent time. This is for optimize the complexity when poping the most recent time. + We could use here the deque structure from Python in order to use optimized poping left, but this structure + don't have implemented the insert() function, which is used for adding new data and keep the queue ordored. + - buffer_launcher : a list containing structured data of the same type than waiting_queue, + but elements here have to be executed for check. + """ + def __init__(self): + threading.Thread.__init__(self) + self.waiting_queue = [] + self.buffer_launcher = [] + + def run(self): + while True: + if not self.waiting_queue == []: + while self.waiting_queue[len(self.waiting_queue) - 1]['time'] <= datetime.now(): + dict_mod = self.waiting_queue.pop(len(self.waiting_queue) - 1) + self.buffer_launcher.append(dict_mod) + dict_mod['time'] = dict_mod['time'] + timedelta(seconds=dict_mod['freq']) + self.add_to_waiting_queue(dict_mod) + time.sleep(1) + + def add_to_waiting_queue(self, dict_mod): + if self.waiting_queue == []: + self.waiting_queue.append(dict_mod) + else: + pos_queue = 0 + while pos_queue < len(self.waiting_queue) and dict_mod['time'] <= self.waiting_queue[pos_queue]['time']: + pos_queue += 1 + self.waiting_queue.insert(pos_queue, dict_mod) + +""" +class RunMonitoring(threading.Thread): + def __init__(self, list_of_dict_mod): + threading.Thread.__init__(self) + self.list_of_dict_mod = list_of_dict_mod + + def run(self): + """ \ No newline at end of file diff --git a/static/js/controllers/mainCtrl.js b/static/js/controllers/mainCtrl.js index 5a29c00..c71643f 100644 --- a/static/js/controllers/mainCtrl.js +++ b/static/js/controllers/mainCtrl.js @@ -129,7 +129,7 @@ mumApp.controller('mainController', ['$scope', 'toastr', '$interval', '$filter', break; case 30: $scope.$apply(function(){ - $scope.status = value; + $scope.state = value; }); toastr.info(value, "Current status is :"); /* diff --git a/views/scan.html b/views/scan.html index 4965ce4..d99fc8e 100644 --- a/views/scan.html +++ b/views/scan.html @@ -9,8 +9,8 @@ </form> </div> <div ng-show="validated == true"> - {{state}} - {{ip_scanned}} + <p>{{state}}</p> + <p>Scanned IP : {{ip_scanned}}</p> </div> </div> </div> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.