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 d2a9fd9c325ae5277d82afdc7854d0b76ab7c886 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Apr 22 14:02:03 2015 +0200 modules that don't need a connection launched separately (ping, http, smtp) + autoconf after scan also for these ones --- app/module_loader.py | 25 ++++++++++++++++++++----- app/modules/monitoring_modules/http.py | 19 ++++++++++++++----- app/modules/monitoring_modules/ping.py | 2 +- app/modules/monitoring_modules/smtp.py | 19 ++++++++++++++----- app/modules/storage_modules/shelve_db.py | 5 ++--- 5 files changed, 51 insertions(+), 19 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index fd6ac6e..174ce9c 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -277,12 +277,27 @@ class ModuleLoader: :param part_name: the name of the part to check :param addr_host: the IP address of the host """ - if part_name == 'ping': - res_check = getattr(self.loaded_mod_moni['ping']['modules']['ping']['imported'], - 'check')(addr_host) - dict_notif = self.db.add_check(addr_host, part_name, res_check) - self.run_notification_modules(dict_notif) + 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'] + try: + res_check = getattr(self.loaded_mod_moni[part_name]['modules'][part_name]['imported'], + 'check')(addr_host, + port_list, + modules.CommandNotFoundException) + dict_notif = self.db.add_check(addr_host, part_name, res_check) + self.run_notification_modules(dict_notif) + except modules.CommandNotFoundException.CommandNotFoundException: + print "No port " + part_name + " on " + addr_host + \ + ". This part checking have been deactivated." + process_monitoring.remove_to_waiting_list(addr_host, part_name) + dict_deactivation_request = {} + dict_deactivation_request['addr_host'] = addr_host + dict_deactivation_request['activated'] = {part_name: False} + self.db.config_mod_activation(dict_deactivation_request) else: + # to check this part, it is necessary to create a connection with the host... # getting all availiable connections for this part to check compatible_conn = self.loaded_mod_moni[part_name]['compatible_conn'] conf_conn = self.db.get_conf_conn(addr_host) diff --git a/app/modules/monitoring_modules/http.py b/app/modules/monitoring_modules/http.py index 7e102e2..56d3327 100644 --- a/app/modules/monitoring_modules/http.py +++ b/app/modules/monitoring_modules/http.py @@ -9,11 +9,20 @@ unit = "bool" connection = "" -def check(addr_host, http_port): +def check(addr_host, port_list, cnfe): res_http_check = False + http_port_found = False try: - res_http_check = urllib2.urlopen("http://" + addr_host + ":" + str(http_port)).getcode() == 200 + for i in range(len(port_list)): + if port_list[i]['portname'] == part: + http_port_found = True + res_http_check = urllib2.urlopen("http://" + addr_host + ":" + str(port_list[i]['portid']) + ).getcode() == 200 + if not http_port_found: + exception_inst = getattr(cnfe, "CommandNotFoundException")( + part, addr_host + ) + raise exception_inst + return res_http_check except urllib2.URLError: - pass - finally: - return res_http_check \ No newline at end of file + res_http_check = False \ No newline at end of file diff --git a/app/modules/monitoring_modules/ping.py b/app/modules/monitoring_modules/ping.py index a3da3c1..c433507 100644 --- a/app/modules/monitoring_modules/ping.py +++ b/app/modules/monitoring_modules/ping.py @@ -10,7 +10,7 @@ unit = "bool" connection = "" -def check(addr_host): +def check(addr_host, port_list, cnfe): res_check = False try: child = pexpect.spawn('ping '+ addr_host + ' -c 1') diff --git a/app/modules/monitoring_modules/smtp.py b/app/modules/monitoring_modules/smtp.py index 4eee977..f21ae0a 100644 --- a/app/modules/monitoring_modules/smtp.py +++ b/app/modules/monitoring_modules/smtp.py @@ -9,11 +9,20 @@ unit = "bool" connection = "" -def check(addr_host, smtp_port): +def check(addr_host, port_list, cnfe): res_smtp_check = True + smtp_port_found = False try: - s = smtplib.SMTP(addr_host, smtp_port) + for i in range(len(port_list)): + if port_list[i]['portname'] == part: + smtp_port_found = True + s = smtplib.SMTP(addr_host, str(port_list[i]['portid'])) + s.quit() + if not smtp_port_found: + exception_inst = getattr(cnfe, "CommandNotFoundException")( + part, addr_host + ) + raise exception_inst + return res_smtp_check except Exception: - res_smtp_check = False - finally: - return res_smtp_check \ No newline at end of file + res_smtp_check = False \ 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 290d35d..d32612a 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -193,6 +193,7 @@ class shelve_db: self.db["hosts"][addr_host]["monitoring"] = {} # Create structure for global status of host self.db["hosts"][addr_host]["status"] = {} + self.db["hosts"][addr_host]["status"]["state"] = "" # Create structure for archiving data self.db["hosts"][addr_host]["archive"] = {} except Exception: @@ -414,9 +415,7 @@ class shelve_db: res['hostname'] = json.loads(self.db['hosts'][addr_host]['detected']['nmap'])['hostname'] else: res['hostname'] = '' - res['monitoring'] = {} - for mod in self.db['hosts'][addr_host]['monitoring']: - res['monitoring'][mod] = self.db['hosts'][addr_host]['monitoring'][mod] + res['monitoring'] = self.db['hosts'][addr_host]['monitoring'] res['detected'] = {} for mod in self.db['hosts'][addr_host]['detected']: res['detected'][mod] = json.loads(self.db['hosts'][addr_host]['detected'][mod]) -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.