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 e920a7c52d608ca92f2917696c88c65e22dc9975 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Jun 10 14:53:59 2015 +0200 failures itterations added for notifications. reset on hostpage --- app/module_loader.py | 2 +- app/modules/storage_modules/shelve_db.py | 35 +++++++++++++++++++++++++++++--- views/hostpage.html | 6 ++++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index 5a05c7a..3399d87 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -294,7 +294,7 @@ class ModuleLoader: if part_name in self.loaded_mod_moni[part_name]['modules'] and \ getattr(self.loaded_mod_moni[part_name]['modules'][part_name]['imported'], 'connection') == "": # the module which check this part doesn't need a connection - port_list = self.db.get_host_informations(addr_host)['detected']['nmap']['openports'] + port_list = self.db.get_nmap_result(addr_host)['openports'] try: res_check = getattr(self.loaded_mod_moni[part_name]['modules'][part_name]['imported'], 'check')(addr_host, diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 185a0b2..91cd226 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -258,6 +258,9 @@ class shelve_db: # Create structure for archiving data self.db["hosts"][addr_host]["archive"] = {} self.db["hosts"][addr_host]["stats"] = {} + # set the initial number of failures to 0 + self.db['hosts'][addr_host]['status']['nb_warning'] = 0 + self.db['hosts'][addr_host]['status']['nb_danger'] = 0 except Exception: print traceback.format_exc() finally: @@ -487,6 +490,27 @@ class shelve_db: res['interventions'] = self.db['hosts'][addr_host]['conf']['interventions'] res['status'] = self.db['hosts'][addr_host]['status']['state'] res['display_name'] = self.db['hosts'][addr_host]['conf']['display_name'] + res['nb_warning'] = self.db['hosts'][addr_host]['status']['nb_warning'] + res['nb_danger'] = self.db['hosts'][addr_host]['status']['nb_danger'] + # we reset here the number of failures sent + self.db['hosts'][addr_host]['status']['nb_warning'] = 0 + self.db['hosts'][addr_host]['status']['nb_danger'] = 0 + except Exception: + print traceback.format_exc() + finally: + self.close_db() + return res + + def get_nmap_result(self, addr_host): + """ + Returns the stored nmap result of a host. + :param addr_host: The IP address of the host + :return: a dictionary containing the nmap result + """ + self.open_db() + res = {} + try: + res = json.loads(self.db['hosts'][addr_host]['detected']['nmap']) except Exception: print traceback.format_exc() finally: @@ -894,7 +918,6 @@ class shelve_db: dict_new_val, self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['minor_limit'], self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['major_limit']) - previous_val = self.db['hosts'][addr_host]["monitoring"][mod_name] self.db['hosts'][addr_host]['monitoring'][mod_name] = dict_new_val # updating the global state of the host self.db['hosts'][addr_host]['status']['date'] = dict_new_val['date'] @@ -912,6 +935,10 @@ class shelve_db: self.db['hosts'][addr_host]['status']['state'] = state # create a notification structure if the state is not a success if not dict_new_val['state'] == 'success': + # incrementation of the number of corresponding failures + self.db['hosts'][addr_host]['status']['nb_' + dict_new_val['state']] += 1 + #print mod_name + #print self.db['hosts'][addr_host]['status']['nb_' + dict_new_val['state']] dict_notif = self.create_notif_structure(addr_host, mod_name, dict_new_val['state']) # updating and saving statistics self.db['hosts'][addr_host]['stats'][mod_name] = \ @@ -1063,7 +1090,8 @@ class shelve_db: for notif_mod in self.db['hosts'][addr_host]['conf']['subscribers'][username][notif_type]: #{'priority': int, 'activated': bool} param_notif = self.db['hosts'][addr_host]['conf']['subscribers'][username][notif_type][notif_mod] - if param_notif['activated']: + if param_notif['activated'] and \ + param_notif['priority'] == self.db['hosts'][addr_host]['status']['nb_' + status]: if notif_mod not in dict_notif: dict_notif[notif_mod] = [] dict_notif[notif_mod].append({'user': self.db['users'][username]['settings'], @@ -1077,7 +1105,8 @@ class shelve_db: for username in self.db['groups'][group]['subscribers']: for notif_mod in self.db['groups'][group]['subscribers'][username][notif_type]: param_notif = self.db['groups'][group]['subscribers'][username][notif_type][notif_mod] - if param_notif['activated']: + if param_notif['activated'] and \ + param_notif['priority'] == self.db['hosts'][addr_host]['status']['nb_' + status]: title = "[Mum] " + status + " for " + addr_host + " on group " + group msg = "Mum reported a " + status + " from the " + moni_mod + " module on host " + \ addr_host + " member of group " + group + "." diff --git a/views/hostpage.html b/views/hostpage.html index c81d91f..f204aa5 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -1,6 +1,6 @@ <div class="col-md-offset-2 main"> - <h1 class="page-header">Current state of + <h1 class="page-header">Current state of <span ng-click="show_display_name_input = true" ng-show="show_display_name_input == false" style="text-decoration:underline"> @@ -21,7 +21,9 @@ <small> {{items.hostname}} ({{addr_host}}) </small> - </h1> + </h1> + + <p>There has been {{items.nb_warning}} warning(s) and {{items.nb_danger}} danger(s) since the last visit on this page.</p> <button type="button" class="btn btn-primary btn-xs" -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.