branch develop updated (dada3f9 -> f761f90)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository mum. See http://git.chorem.org/mum.git from dada3f9 changed bootstrap.sh in order to parameter bottle for angular.js new d9ab090 installation details on readme new f761f90 ping request is now the monitoring by default, if any configuration for the host have been done The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit f761f908bb1e145e81825ae048a5ba268bd87b6f Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Feb 27 11:19:18 2015 +0100 ping request is now the monitoring by default, if any configuration for the host have been done commit d9ab090dfeb605214863b100e6901a75155f785f Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Feb 26 16:47:15 2015 +0100 installation details on readme Summary of changes: README | 35 +++++++-- app/app.py | 9 ++- app/module_loader.py | 12 ++- app/modules/monitoring_modules/__init__.py | 3 +- app/modules/monitoring_modules/ping.py | 27 +++++++ app/modules/storage_modules/shelve_db.py | 117 +++++++++++++++++++---------- app/process_monitoring.py | 12 ++- 7 files changed, 161 insertions(+), 54 deletions(-) create mode 100644 app/modules/monitoring_modules/ping.py -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 d9ab090dfeb605214863b100e6901a75155f785f Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Feb 26 16:47:15 2015 +0100 installation details on readme --- README | 35 ++++++++++++++++++++++++++++++----- app/process_monitoring.py | 1 - 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/README b/README index c488041..1bcbfb2 100644 --- a/README +++ b/README @@ -1,5 +1,30 @@ ---------------------- -Installation procedure: ---------------------- -- bower install -- ./bootsrap.sh +------------ +Installation +------------ +Get the sources: +- git clone https://git.chorem.org/mum.git +- cd mum + +If bower is not installed: (as root) +- apt-get install curl +- curl -sL https://deb.nodesource.com/setup | bash - +- apt-get install -y nodejs +(Packages for other distrib : https://github.com/joyent/node/wiki/installing-node.js-via-package-manager) + +Install Bower : +npm install -g bower + +Install bower dependancies: +bower install + +This program needs python 2.7: (as root) +apt-get install python2.7 +apt-get install python2.7-dev + +Install python dependancies (needs Pip): +./boostrap.sh + +Launch the server : +./run.sh + +The service will be avaliable on 0.0.0.0:1337 \ No newline at end of file diff --git a/app/process_monitoring.py b/app/process_monitoring.py index 8ddbb04..80b06ec 100644 --- a/app/process_monitoring.py +++ b/app/process_monitoring.py @@ -85,7 +85,6 @@ class RunMonitoring(threading.Thread): self.wsc = wsc def run(self): - print "running" sys.stdout.flush() for dict_mod in self.list_dict_mod: print "Launching " + str(dict_mod['os']) + "." + str(dict_mod['mod_name']) + " on " + str(dict_mod['addr']) -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 f761f908bb1e145e81825ae048a5ba268bd87b6f Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Feb 27 11:19:18 2015 +0100 ping request is now the monitoring by default, if any configuration for the host have been done --- app/app.py | 9 ++- app/module_loader.py | 12 ++- app/modules/monitoring_modules/__init__.py | 3 +- app/modules/monitoring_modules/ping.py | 27 +++++++ app/modules/storage_modules/shelve_db.py | 117 +++++++++++++++++++---------- app/process_monitoring.py | 11 ++- 6 files changed, 131 insertions(+), 48 deletions(-) diff --git a/app/app.py b/app/app.py index ea748f7..c51e833 100755 --- a/app/app.py +++ b/app/app.py @@ -38,12 +38,16 @@ class ThreadDetect(threading.Thread): def run(self): db = module_loader.load_db() - conn_mod_list = module_loader.get_conection_modules_list() scanned_ip = module_loader.run_nmap_detection(self.param, db, self.ws, module_loader.get_conection_modules_list(), module_loader.get_info_mod_monitoring()) if scanned_ip is not None: self.ws.send(json.dumps({SUCCESS_MODULE: scanned_ip})) + for ip in json.loads(scanned_ip): + monitoring_intructions = db.get_monitoring_instructions(ip) + for instr in monitoring_intructions: + process_monitoring.add_to_waiting_list(instr) + """ # now launching full detection for ip in json.loads(scanned_ip): conn = module_loader.load_conn("ssh", ip, "aguilbaud", "/home/aguilbaud/.ssh/id_rsa") @@ -53,6 +57,7 @@ class ThreadDetect(threading.Thread): process_monitoring.add_to_waiting_list(instr) #module_loader.run_all_monitoring_modules("unix", conn, db, self.ws) # adding entries on process monitoring + """ @route('/') def index(section='home'): @@ -136,6 +141,8 @@ def receive(ws): start_first_detection(msg[NMAP_SCAN_DEMAND], ws) elif code == GET_HOSTS_DEMAND: db = module_loader.load_db() + hosts= db.get_hosts() + print hosts ws.send(json.dumps({GET_HOSTS_RESPONSE: db.get_hosts()})) del db elif code == HOST_INFO_DEMAND: diff --git a/app/module_loader.py b/app/module_loader.py index 93913d3..b232840 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -120,10 +120,17 @@ def run_one_monitoring_module(mod_name, addr_host, os, conn, db, ws): :param db: an instance of a storage module :param ws: a websocket connection if the function have been called from a client. Is None otherwise """ - if conn is None: - conn = load_conn("ssh", addr_host, "aguilbaud", "/home/aguilbaud/.ssh/id_rsa") if db is None: db = load_db() + if conn is None: + if os is None and mod_name == 'ping': + # in this case, the connection have not been configurated yet, so we just launch a ping check + ping_mod = __import__("modules.monitoring_modules.ping", fromlist=modules.monitoring_modules.special_modules) + ping_mod_inst = getattr(ping_mod, "ping")(db, addr_host) + ping_mod_inst.check() +""" + else: + conn = load_conn("ssh", addr_host, "aguilbaud", "/home/aguilbaud/.ssh/id_rsa") __import__("modules.monitoring_modules." + os) mod = __import__("modules.monitoring_modules." + os + "." + mod_name, fromlist=modules.monitoring_modules.unix.__all__) mod_instance = getattr(mod, mod_name)(conn, db, modules.ModuleNotCompatibleException) # on appelle le constructeur @@ -137,6 +144,7 @@ def run_one_monitoring_module(mod_name, addr_host, os, conn, db, ws): print cnfe.__str__() if ws is not None: ws.send(json.dumps({"40": cnfe.__str__()})) +""" def get_info_mod_monitoring(): diff --git a/app/modules/monitoring_modules/__init__.py b/app/modules/monitoring_modules/__init__.py index 9735bce..aa0ac17 100644 --- a/app/modules/monitoring_modules/__init__.py +++ b/app/modules/monitoring_modules/__init__.py @@ -1,2 +1,3 @@ __author__ = 'aguilbaud' -__all__ = ['unix'] \ No newline at end of file +__all__ = ['unix'] +special_modules = ['ping'] \ No newline at end of file diff --git a/app/modules/monitoring_modules/ping.py b/app/modules/monitoring_modules/ping.py new file mode 100644 index 0000000..7c3600a --- /dev/null +++ b/app/modules/monitoring_modules/ping.py @@ -0,0 +1,27 @@ +__author__ = 'aguilbaud' + +import pexpect + +class ping: + + def __init__(self, db, addr_host): + self.db = db + self.addr_host = addr_host + + def check(self): + res_check = False + try: + child = pexpect.spawn('ping '+ self.addr_host + ' -c 1') + while child.isalive(): + child.expect('packets transmitted, ') + child.expect(' received') + res = child.before + res_check = res == "1" + except pexpect.EOF: + res_check = False + #self.db.add_check(self.addr_host, "ping", res_check) + except pexpect.TIMEOUT: + res_check = False + #self.db.add_check(self.addr_host, "ping", False) + finally: + self.db.add_check(self.addr_host, "ping", 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 bd26a76..7644003 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -64,15 +64,11 @@ 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"]["connections"] = {} #self.init_conn(json.loads(nmap_res), list_mod_conn) 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"]["monitoring"] = self.generate_global_conf(dict_mod_info, + addr_host, 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 ? self.db["hosts"][addr_host]["conf"]["custom_info"] = "" self.db["hosts"][addr_host]["conf"]["interventions"] = [] @@ -85,41 +81,59 @@ class shelve_db: finally: self.close_db() - def generate_global_conf(self, dict_mod_info, os): + def generate_global_conf(self, dict_mod_info, addr_host, os_host): """ Configures automatically the monitoring for a host for each of the monitoring modules avaliable, in function of the unit of the result of the monitoring module. + By default, only the ping monitoring is activated, while the connection is not configured and tje os not + detected :param dict_mod_info: dictionary containing informations about all notification modules, in the form: [monitoring_module_name][{'block':val, 'unit': val}] - :return a list containing the default parameters for each monitoring module + :return a list containing the default parameters for each monitoring module (at least ping) """ res = {} - 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 + if not self.db["hosts"][addr_host]["conf"]["connections"] == {} and not os_host == 'unknown': + if os_host not in dict_mod_info: + print "OS " + os_host + " is not supported by the monitoring modules currently loaded." + else: + for mod in dict_mod_info[os_host]: + mod_conf = {} + mod_conf['block'] = dict_mod_info[os_host][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_host][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 + # configure for ping monitoring in any case + ping_conf = {} + ping_conf['block'] = 'network' + ping_conf['activated'] = True + ping_conf['check_frequency'] = 60 + ping_conf['nb_minute'] = 30 + ping_conf['nb_hour'] = 12 + ping_conf['nb_day'] = 15 + ping_conf['nb_week'] = 2 + ping_conf['nb_month'] = 6 + ping_conf['nb_year'] = None + ping_conf['unit'] = 'bool' + ping_conf['minor_limit'] = False + ping_conf['major_limit'] = True + res['ping'] = ping_conf return res def init_conn(self, dict_nmap_res, conn_list): @@ -222,7 +236,10 @@ class shelve_db: detected = json.loads(self.db["hosts"][host]["detected"]["nmap"]) info_host = {} info_host["addr"] = detected["addr"] - info_host["name"] = detected["hostname"] + if 'hostname' in detected: + info_host["name"] = detected["hostname"] + else: + info_host["name"] = "" if "state" in self.db["hosts"][host]["status"]: info_host["status"] = self.db["hosts"][host]["status"]["state"] else: @@ -242,6 +259,8 @@ class shelve_db: elif self.db["hosts"][host]["monitoring"][mod]["state"] == "danger": info_host["danger"].append(mod) res.append(info_host) + except Exception as e: + print e.__str__() finally: self.close_db() return json.dumps(res) @@ -377,13 +396,28 @@ class shelve_db: self.open_db() new_val = {"date": str(datetime.now()), "value" : val} try: - if val >= self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['minor_limit']: - new_val['state'] = 'warning' - elif val >= self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['major_limit']: - new_val['state'] = 'danger' + if type(val) == type(True): + # if boolean + if self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['minor_limit'] and not val: + # if warning set for fail and fail occures + new_val['state'] = 'warning' + elif self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['major_limit'] and not val: + # if danger set for fail and fail occures + new_val['state'] = 'danger' + else: + new_val['state'] = 'success' else: - new_val['state'] = 'success' + # if numerical value + if val >= self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['minor_limit']: + # if value is above waning limit + new_val['state'] = 'warning' + elif val >= self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['major_limit']: + # if value is above danger limit + new_val['state'] = 'danger' + else: + new_val['state'] = 'success' if mod_name not in self.db['hosts'][addr_host]["monitoring"]: + # creating the monitoring structure for this module if not exists 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 @@ -392,6 +426,7 @@ class shelve_db: if 'state' not in self.db['hosts'][addr_host]['status']: self.db['hosts'][addr_host]['status']['state'] = new_val['state'] else: + # now updating the global state of the host (most recent check and worst state for all modules) state = 'success' for mod_name in self.db['hosts'][addr_host]['monitoring']: if self.db['hosts'][addr_host]['monitoring'][mod_name]['state'] == 'danger': diff --git a/app/process_monitoring.py b/app/process_monitoring.py index 80b06ec..90c1d0c 100644 --- a/app/process_monitoring.py +++ b/app/process_monitoring.py @@ -87,7 +87,12 @@ class RunMonitoring(threading.Thread): def run(self): sys.stdout.flush() for dict_mod in self.list_dict_mod: - print "Launching " + str(dict_mod['os']) + "." + str(dict_mod['mod_name']) + " on " + str(dict_mod['addr']) - sys.stdout.flush() - run_one_monitoring_module(dict_mod['mod_name'], dict_mod['addr'], dict_mod['os'], None, None, None) + if dict_mod['mod_name'] == 'ping': + print "Launching " + str(dict_mod['mod_name']) + " request on " + str(dict_mod['addr']) + sys.stdout.flush() + run_one_monitoring_module(dict_mod['mod_name'], dict_mod['addr'], None, None, None, None) + else: + print "Launching " + str(dict_mod['os']) + "." + str(dict_mod['mod_name']) + " on " + str(dict_mod['addr']) + sys.stdout.flush() + run_one_monitoring_module(dict_mod['mod_name'], dict_mod['addr'], dict_mod['os'], None, None, None) self.wsc.notify_state_change() \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm