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 b52c260056c477b1d44043c76b3e5efc2b938dbc Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Tue Feb 24 17:02:26 2015 +0100 test monitoring sur localhost : OK --- app/app.py | 2 ++ app/modules/monitoring_modules/unix/disk.py | 3 +- app/modules/monitoring_modules/unix/memory.py | 4 +-- .../monitoring_modules/unix/updated_packages.py | 8 ++--- app/modules/storage_modules/shelve_db.py | 39 ++++++++++++++++------ static/js/controllers/mainCtrl.js | 10 ++++++ 6 files changed, 46 insertions(+), 20 deletions(-) diff --git a/app/app.py b/app/app.py index 4a07abf..4fb4db3 100755 --- a/app/app.py +++ b/app/app.py @@ -44,6 +44,8 @@ class ThreadDetect(threading.Thread): for ip in json.loads(scanned_ip): conn = module_loader.load_conn("ssh", ip, "aguilbaud", "/home/aguilbaud/.ssh/id_rsa") module_loader.run_all_detection_modules(db.get_host_os(ip), conn, db, self.ws) + module_loader.run_all_monitoring_modules("unix", conn, db, self.ws) + print "done" @route('/') diff --git a/app/modules/monitoring_modules/unix/disk.py b/app/modules/monitoring_modules/unix/disk.py index 4e7ac7d..c6f3d28 100644 --- a/app/modules/monitoring_modules/unix/disk.py +++ b/app/modules/monitoring_modules/unix/disk.py @@ -1,6 +1,5 @@ __author__ = 'aguilbaud' -import json import re """ @@ -32,5 +31,5 @@ class disk: "disk", self.conn.get_addr_host() ) raise exception_inst - res_check = json.dumps({"disk": int(disk_used)}) + res_check = int(disk_used) self.db.add_check(self.conn.get_addr_host(), "disk", res_check) \ No newline at end of file diff --git a/app/modules/monitoring_modules/unix/memory.py b/app/modules/monitoring_modules/unix/memory.py index adc30d4..1c2f146 100644 --- a/app/modules/monitoring_modules/unix/memory.py +++ b/app/modules/monitoring_modules/unix/memory.py @@ -1,5 +1,5 @@ __author__ = 'aguilbaud' -import json + import re @@ -31,5 +31,5 @@ class memory: "memory", self.conn.get_addr_host() ) raise exception_inst - res_check = json.dumps({"memory": memused * 100 / int(memtotal)}) + res_check = memused * 100 / int(memtotal) self.db.add_check(self.conn.get_addr_host(), "memory", res_check) \ No newline at end of file diff --git a/app/modules/monitoring_modules/unix/updated_packages.py b/app/modules/monitoring_modules/unix/updated_packages.py index a0642fc..6e66832 100644 --- a/app/modules/monitoring_modules/unix/updated_packages.py +++ b/app/modules/monitoring_modules/unix/updated_packages.py @@ -1,9 +1,7 @@ __author__ = 'alexis' -import json - class updated_packages: - def __init__(self, conn, db): + def __init__(self, conn, db, mnce): self.conn = conn self.db = db @@ -12,7 +10,7 @@ class updated_packages: stdout = self.conn.exec_command(cmd) tab_res = stdout.split(':') if len(tab_res) == 2: - res_check = json.dumps({'non_updated_packages': False}) + res_check = False else: - res_check = json.dumps({'non_updated_packages': True}) + res_check = True self.db.add_check(self.conn.get_addr_host(), "updated_packages", res_check) \ No newline at end of file diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 5467a3e..1a1ebea 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -73,6 +73,8 @@ class shelve_db: self.db["hosts"][addr_host]["conf"]["interventions"] = [] # Create structure for monitoring data self.db["hosts"][addr_host]["monitoring"] = {} + # Create structure for global status of host + self.db["hosts"][addr_host]["status"] = {} # Create structure for archiving data self.db["hosts"][addr_host]["archive"] = {} finally: @@ -119,18 +121,16 @@ class shelve_db: :param conn_list: A list of all connection modules avaliable :return: """ - res = [] + dict_conn = {} cpt = 1 for port in dict_nmap_res['openports']: if port["portname"] in conn_list: - dict_conn = {} dict_conn[port["portname"]] = { "priority": cpt, "portid": int(port["portid"]), } - res.append(dict_conn) cpt += 1 - return res + return dict_conn def get_hosts(self): """ @@ -170,15 +170,15 @@ class shelve_db: info_host = {} info_host["addr"] = detected["addr"] info_host["name"] = detected["hostname"] - if "status" in self.db["hosts"][host]["monitoring"]: - info_host["status"] = self.db["hosts"][host]["monitoring"]["status"] + if "status" in self.db["hosts"][host]["status"]: + info_host["status"] = self.db["hosts"][host]["status"]["state"] else: info_host["status"] = "" info_host["group"] = [] for group in self.db["hosts"][host]["conf"]["groups"]: info_host["group"].append({"name": group}) - if "date" in self.db["hosts"][host]["monitoring"]: - info_host["last_check"] = self.db["hosts"][host]["monitoring"]["date"] + if "date" in self.db["hosts"][host]["status"]: + info_host["last_check"] = self.db["hosts"][host]["status"]["date"] else: info_host["last_check"] = 0 res.append(info_host) @@ -275,20 +275,37 @@ class shelve_db: :param val: the value observed """ self.open_db() - new_val = {"date": datetime.now()} + new_val = {"date": datetime.now(), "value" : val} try: - if val >= self.db['hosts']['conf']['monitorig'][mod_name]['minor_limit']: + if val >= self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['minor_limit']: new_val['state'] = 'warning' - elif val >= self.db['hosts']['conf']['monitorig'][mod_name]['major_limit']: + elif val >= self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['major_limit']: new_val['state'] = 'danger' else: new_val['state'] = 'success' + if mod_name not in self.db['hosts'][addr_host]["monitoring"]: + self.db['hosts'][addr_host]["monitoring"][mod_name] = {} previous_val = self.db['hosts'][addr_host]["monitoring"][mod_name] self.db['hosts'][addr_host]['monitoring'][mod_name] = new_val + # updating the global state of the host + self.db['hosts'][addr_host]['status']['date'] = new_val['date'] + if 'state' not in self.db['hosts'][addr_host]['status']: + self.db['hosts'][addr_host]['status']['state'] = new_val['state'] + else: + state = 'success' + for mod_name in self.db['hosts'][addr_host]['monitoring']: + if self.db['hosts'][addr_host]['monitoring'][mod_name]['state'] == 'danger': + state = 'danger' + elif self.db['hosts'][addr_host]['monitoring'][mod_name]['state'] == 'warning' \ + and not state == 'danger': + state = 'warning' + self.db['hosts'][addr_host]['status']['state'] = state # now performing archiving + """ if mod_name in self.db['hosts'][addr_host]['archive']: self.db['hosts'][addr_host]['archive'][mod_name] = \ self.update_stats(self.db['hosts'][addr_host]['archive'][mod_name], val) + """ finally: self.close_db() diff --git a/static/js/controllers/mainCtrl.js b/static/js/controllers/mainCtrl.js index f24a3fe..6762f89 100644 --- a/static/js/controllers/mainCtrl.js +++ b/static/js/controllers/mainCtrl.js @@ -4,21 +4,27 @@ mumApp.config(function($routeProvider){ $routeProvider .when('/',{ templateUrl : 'dashboard.html', + controller : 'mainController' }) .when('/dashboard',{ templateUrl : 'dashboard.html', + controller : 'mainController' }) .when('/groups',{ templateUrl : 'groups.html', + controller : 'mainController' }) .when('/hostpage/:param',{ templateUrl : 'hostpage.html', + controller : 'mainController' }) .when('/notifications',{ templateUrl : 'notifications.html', + controller : 'mainController' }) .when('/profile',{ templateUrl : 'profile.html', + controller : 'mainController' }) .when('/scan',{ templateUrl : 'scan.html', @@ -26,15 +32,19 @@ mumApp.config(function($routeProvider){ }) .when('/settings',{ templateUrl : 'settings.html', + controller : 'mainController' }) .when('/signin',{ templateUrl : 'signin.html', + controller : 'mainController' }) .when('/stats',{ templateUrl : 'stats.html', + controller : 'mainController' }) .when('/users',{ templateUrl : 'users.html', + controller : 'mainController' }) .otherwise({ redirectTo: '/' -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.