branch develop updated (925de3c -> 9af4a08)
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 925de3c hostpage: le champ pour corriger l'os détecté est un menu déroulant. new a7dbf94 notifications: bilan de toutes les notif new 9af4a08 surcharge des modules de monitoring 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 9af4a08881702be613fe21aae23e0b22504e5fd5 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Apr 1 11:54:05 2015 +0200 surcharge des modules de monitoring commit a7dbf94ba8a9d0c9df769f27f7f18478583f28cb Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Tue Mar 31 10:58:05 2015 +0200 notifications: bilan de toutes les notif Summary of changes: app/module_loader.py | 79 ++++++++++++---------- app/modules/monitoring_modules/disk.py | 74 +++++++------------- app/modules/monitoring_modules/memory.py | 72 +++++++------------- app/modules/monitoring_modules/ping.py | 59 ++++++---------- app/modules/monitoring_modules/updated_packages.py | 38 +++-------- app/mum.py | 34 ++++++---- static/js/controllers/headCtrl.js | 3 + static/js/controllers/hostPageCtrl.js | 4 +- static/js/controllers/notificationsCtrl.js | 33 ++++++++- static/js/controllers/settingsCtrl.js | 3 + static/js/mumApp.js | 4 +- views/hostpage.html | 5 +- views/notifications.html | 41 +++++++++++ 13 files changed, 226 insertions(+), 223 deletions(-) create mode 100644 static/js/controllers/settingsCtrl.js -- 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 a7dbf94ba8a9d0c9df769f27f7f18478583f28cb Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Tue Mar 31 10:58:05 2015 +0200 notifications: bilan de toutes les notif --- app/module_loader.py | 52 +++++++++++++++++------------- app/mum.py | 34 +++++++++++-------- static/js/controllers/headCtrl.js | 3 ++ static/js/controllers/hostPageCtrl.js | 4 +-- static/js/controllers/notificationsCtrl.js | 33 ++++++++++++++++++- static/js/controllers/settingsCtrl.js | 3 ++ static/js/mumApp.js | 4 +-- views/hostpage.html | 5 ++- views/notifications.html | 41 +++++++++++++++++++++++ 9 files changed, 137 insertions(+), 42 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index bfde9ca..33ff089 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -168,27 +168,28 @@ class ModuleLoader: print "Error : internal monitoring module " + mod_name + " could not have been loaded. " # Now for external modules: - sys.path.insert(0, self.conf['external_modules_location']) # Adding the external diretory into pythonpath - for importer, mod_name, ispkg in pkgutil.iter_modules([self.conf['external_modules_location']]): - if mod_name not in sys.modules: - try: - loaded_mod = __import__(mod_name, fromlist=[mod_name]) - class_name = getattr(loaded_mod, "get_class_name")() - mod_inst = getattr(loaded_mod, class_name)(None, None, None) - infos_mod = {} - infos_mod['imported'] = loaded_mod - infos_mod['class_name'] = getattr(mod_inst, 'get_name')() - infos_mod['compatible_os'] = getattr(mod_inst, 'get_compatible_os')() - for os in infos_mod['compatible_os']: - if os not in self.compatible_os_list: - self.compatible_os_list.append(os) - infos_mod['block'] = getattr(mod_inst, 'get_block')() - infos_mod['unit'] = getattr(mod_inst, 'get_unit')() - infos_mod['external'] = True - self.loaded_mod_moni[mod_name] = infos_mod - except AttributeError: - print "Error : external monitoring module " + mod_name + " could not have been loaded. " - print "Please verify that every necessary methods have been implemented." + if self.conf['external_modules_location'] is not None: + sys.path.insert(0, self.conf['external_modules_location']) # Adding the external diretory into pythonpath + for importer, mod_name, ispkg in pkgutil.iter_modules([self.conf['external_modules_location']]): + if mod_name not in sys.modules: + try: + loaded_mod = __import__(mod_name, fromlist=[mod_name]) + class_name = getattr(loaded_mod, "get_class_name")() + mod_inst = getattr(loaded_mod, class_name)(None, None, None) + infos_mod = {} + infos_mod['imported'] = loaded_mod + infos_mod['class_name'] = getattr(mod_inst, 'get_name')() + infos_mod['compatible_os'] = getattr(mod_inst, 'get_compatible_os')() + for os in infos_mod['compatible_os']: + if os not in self.compatible_os_list: + self.compatible_os_list.append(os) + infos_mod['block'] = getattr(mod_inst, 'get_block')() + infos_mod['unit'] = getattr(mod_inst, 'get_unit')() + infos_mod['external'] = True + self.loaded_mod_moni[mod_name] = infos_mod + except AttributeError: + print "Error : external monitoring module " + mod_name + " could not have been loaded. " + print "Please verify that every necessary methods have been implemented." def run_one_monitoring_module(self, mod_name, addr_host, conn, db): """ @@ -411,4 +412,11 @@ class ModuleLoader: def get_host_info(self, addr_host): host_info = self.db.get_host_informations(addr_host) host_info['compatible_os_list'] = self.compatible_os_list - return host_info \ No newline at end of file + return host_info + + def get_all_subscriptions(self): + res = {} + users = self.db.get_users(None) + for user in users: + res[user] = (self.db.get_user_subscriptions(user)) + return res \ No newline at end of file diff --git a/app/mum.py b/app/mum.py index ed5add2..eaf1e25 100755 --- a/app/mum.py +++ b/app/mum.py @@ -128,7 +128,7 @@ def receive(ws): start_first_detection(msg["NMAP_SCAN_DEMAND"], ml, ws) elif code == "LAUNCH_FULL_DETECTION": # asked from hostpage ml.run_all_detection_modules(msg["LAUNCH_FULL_DETECTION"]) - ws.send(json_dumps({"SUCCESS_MODULE": "Full detection"})) + ws.send(json.dumps({"SUCCESS_MODULE": "Full detection"})) elif code == "GET_HOSTS": # asked from head controller db = ml.get_db() ws.send(json.dumps({"RES_GET_HOSTS": db.get_hosts()})) @@ -142,11 +142,13 @@ def receive(ws): }}) ws.send(msg) elif code == "GET_LOADED_CONN_MOD": # asked from hostpage, at the connection configuration - ws.send(json_dumps({"RES_GET_LOADED_CONN_MOD": ml.get_info_mod_conn()})) + ws.send(json.dumps({"RES_GET_LOADED_CONN_MOD": ml.get_info_mod_conn()})) elif code == "GET_LOADED_MONI_MOD": # asked from hostpage, at the block activation conf - ws.send(json_dumps({"RES_GET_LOADED_MONI_MOD": ml.get_info_mod_monitoring()})) + ws.send(json.dumps({"RES_GET_LOADED_MONI_MOD": ml.get_info_mod_monitoring()})) elif code == "GET_LOADED_NOTIF_MOD": # asekd from notification parameters page - ws.send(json_dumps({"RES_GET_LOADED_NOTIF_MOD": ml.get_info_mod_notification()})) + ws.send(json.dumps({"RES_GET_LOADED_NOTIF_MOD": ml.get_info_mod_notification()})) + elif code == "GET_ALL_SUBSCRIPTIONS": # asekd from notification parameters page + ws.send(json.dumps({"RES_GET_ALL_SUBSCRIPTIONS": ml.get_all_subscriptions()})) elif code == "SET_MOD_ACTIVATION": # asked from hostpage, at the block activation conf ml.update_activated_modules(msg["SET_MOD_ACTIVATION"]) elif code == "TEST_CONN": @@ -163,7 +165,7 @@ def receive(ws): args = msg["CHECK_NOW"] ml.run_one_monitoring_module(args['mod_name'], args['addr_host'], None, None) elif code == "GET_KEYS_LIST": # asked from hostpage, at the connection configuration - ws.send(json_dumps({"KEYS_LIST": ml.get_public_keys_list()})) + ws.send(json.dumps({"KEYS_LIST": ml.get_public_keys_list()})) else: break except WebSocketError: # Should be WebSocketError when closing the connection @@ -187,16 +189,20 @@ if __name__ == '__main__': global wsc # creating the parser for the command line arguments - parser = argparse.ArgumentParser() - parser.add_argument("conf_loc", help="the location of the configuration file (can be relative)") - parser.add_argument("--server_port", type=int, help="the port of the service. REQUIRED") - parser.add_argument("--server_addr", help="the address of the service. REQUIRED") - parser.add_argument("--db_location", help="the location of the shelve database. REQUIRED") - parser.add_argument("--external_modules_location", help="the location of the external monitoring modules. REQUIRED") + parser = argparse.ArgumentParser(description="Mum (Machines Under Monotoring) is a web-oriented and modulable " + "monitoring service.", + epilog="The following fields must be specified on the configuration file or by " + "arguments in order to launch the service: server_port, server_addr, " + "db_location.") + parser.add_argument("conf_loc", help="the location of the configuration file (can be relative from the launcher)") + parser.add_argument("--server_port", type=int, help="the port of the service.") + parser.add_argument("--server_addr", help="the address of the service.") + parser.add_argument("--db_location", help="the location of the shelve database.") + parser.add_argument("--external_modules_location", help="the location of the external monitoring modules.") parser.add_argument("--keys_location", help="the location of the directory containing the SSH keys.") - parser.add_argument("--smtp_server", help="the name of the SMTP server to send e-mail notifications") - parser.add_argument("--smtp_port", help="the port of the SMTP server") - parser.add_argument("--smtp_address", help="the e-mail address of the sender for the e-mail notifications") + parser.add_argument("--smtp_server", help="name of the SMTP server to send e-mail notifications") + parser.add_argument("--smtp_port", help="port number of the SMTP server") + parser.add_argument("--smtp_address", help="e-mail address of the sender for e-mail notifications") args = parser.parse_args() # creating the default conf structure from the configuration file diff --git a/static/js/controllers/headCtrl.js b/static/js/controllers/headCtrl.js index f70426a..eea029c 100644 --- a/static/js/controllers/headCtrl.js +++ b/static/js/controllers/headCtrl.js @@ -50,6 +50,9 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r case "RES_GET_LOADED_NOTIF_MOD": $rootScope.$broadcast("resGetLoadedNotifMod", obj[key]); break; + case "RES_GET_ALL_SUBSCRIPTIONS": + $rootScope.$broadcast("resGetAllSubscriptions", obj[key]); + break; case "RES_CALL_FUNC_DB": // Get a result after calling a funcion on the db $rootScope.$broadcast("resCall", obj[key]); break; diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index 90963f2..809517b 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -36,7 +36,7 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar } */ $scope.update_os_name = function(){ - args = {}; + var args = {}; args['addr_host'] = $scope.addr_host; args['new_os_name'] = $scope.model.new_os; $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'update_os_name', 'args': args}})); @@ -106,7 +106,7 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar }; $scope.remove_host = function(){ - args = {}; + var args = {}; args['addr_host'] = $scope.addr_host; $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'remove_host', 'args': args}})); } diff --git a/static/js/controllers/notificationsCtrl.js b/static/js/controllers/notificationsCtrl.js index 71764f2..e9330b6 100644 --- a/static/js/controllers/notificationsCtrl.js +++ b/static/js/controllers/notificationsCtrl.js @@ -19,9 +19,18 @@ mumApp.controller('notificationsCtrl', function($scope, $rootScope, $modal, $rou $scope.subtitle = ""; + $scope.all_subscriptions = {}; // {user1: {'hosts': {addr_host: {'major': {}, 'minor': {}}}, 'groups': {...}}, ... } + $scope.notif_mods = {}; // {notif_mod :{param1:val1, param2:val2, ...}} - $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_LOADED_NOTIF_MOD": ""})); + $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_ALL_SUBSCRIPTIONS": ""})); + + $scope.$on("resGetAllSubscriptions", function (event, args) { + $scope.$apply(function(){ + $scope.all_subscriptions = args; + }); + $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_LOADED_NOTIF_MOD": ""})); + }); $scope.$on("resGetLoadedNotifMod", function (event, args) { $scope.$apply(function(){ @@ -47,6 +56,28 @@ mumApp.controller('notificationsCtrl', function($scope, $rootScope, $modal, $rou return res; }; + $scope.is_activated = function(struct){ // {modname:{"priority":int,"activated":bool}, ...} + res = false; + if(struct != {}){ + for(mod in struct){ + if(struct[mod].activated){ + res = true; + } + } + } + return res; + } + + $scope.get_activated = function(struct){ // {modname:{"priority":int,"activated":bool}, ...} + res = []; + for(mod in struct){ + if(struct[mod].activated){ + res[res.length] = mod + " at " + struct[mod].priority; + } + } + return res; + } + $scope.selected_grp = ""; // string $scope.selected_host = ""; // {"status":"success","group":["all","g1"],"addr":"127.0.0.1","danger":[],"last_check":"2015-03-20 15:32:19.897431","warning":[],"name":"localhost"} diff --git a/static/js/controllers/settingsCtrl.js b/static/js/controllers/settingsCtrl.js new file mode 100644 index 0000000..f548909 --- /dev/null +++ b/static/js/controllers/settingsCtrl.js @@ -0,0 +1,3 @@ +mumApp.controller('settingsCtrl', function($scope, $rootScope) { + +}); \ No newline at end of file diff --git a/static/js/mumApp.js b/static/js/mumApp.js index 15d9897..5151687 100644 --- a/static/js/mumApp.js +++ b/static/js/mumApp.js @@ -39,8 +39,8 @@ mumApp.config(function($routeProvider){ controller : 'scanCtrl' }) .when('/settings',{ - templateUrl : 'settings.html' - //controller : 'mainController' + templateUrl : 'settings.html', + controller : 'settingsCtrl' }) .when('/signin',{ templateUrl : 'signin.html' diff --git a/views/hostpage.html b/views/hostpage.html index ef15943..189dc14 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -1,7 +1,10 @@ <div class="col-md-offset-2 main"> <h1 class="page-header">Current state of {{addr_host}} <small>{{items.hostname}}</small></h1> - <button type="button" class="btn btn-primary btn-xs" ng-click="open_modal_block()">Activate/Deactivate</button> + <button type="button" class="btn btn-primary btn-xs" + ng-click="open_modal_block()" + popover="Activate or deactivate monitoring modules by block." + popover-trigger="mouseenter">Activate/Deactivate</button> <button type="button" class="btn btn-primary btn-xs" ng-click="open_modal_conn()">Connection settings</button> <button type="button" class="btn btn-info btn-xs" ng-click="launch_detection()">Launch a full detection</button> <button type="button" class="btn btn-danger btn-xs" ng-click="remove_host()">Remove this host</button> diff --git a/views/notifications.html b/views/notifications.html index 181a7eb..1d6a182 100644 --- a/views/notifications.html +++ b/views/notifications.html @@ -1,6 +1,47 @@ <div class="col-md-offset-2 main"> <h1 class="page-header">Who to notify? <small>{{subtitle}}</small></h1> + <h3 ng-repeat-start="(username, user) in all_subscriptions">{{username}}</h3> + <dl ng-repeat-end + ng-repeat-start="(addr_host, host) in user.hosts"> + <dt>{{addr_host}}</dt> + <dd ng-show="is_activated(host.major)">Major: {{get_activated(host.major)}}</dd> + <dd ng-show="is_activated(host.minor)">Minor: {{get_activated(host.minor)}}</dd> + </dl> + <dl ng-repeat-end + ng-repeat="(grp_name, grp) in user.groups"> + <dt>{{grp_name}}</dt> + <dd ng-show="is_activated(grp.major)">Major: {{get_activated(grp.major)}}</dd> + <dd ng-show="is_activated(grp.minor)">Minor: {{get_activated(grp.minor)}}</dd> + </dl> + <!--<table class="table table-hover" ng-repeat="(username, user) in all_subscriptions"> + + <thead> + <tr> + <th>Host</th> + <th>Notification service</th> + <th>Minor</th> + <th>Major</th> + </tr> + </thead> + <tbody> + <tr ng-repeat-start="(addr_host, host) in all_subscriptions.user.hosts"> + <td>{{addr_host}}</td> + </tr> + <tr ng-repeat-end + ng-repeat="(notif_mod_name, notif_mod) in host.minor"> + <td></td> + <td>{{notif_mod_name}}</td> + <td> + {{notif_mod.gzkf}} + {{notif_mod.priority}} + </td> + <td> + {{user_subscriptions.hosts[addr_host].major[notif_mod_name].priority}} + </td> + </tr> + </tbody> + </table>--> <form> <div class="row"> <div class="col-lg-6"> -- 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 9af4a08881702be613fe21aae23e0b22504e5fd5 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Apr 1 11:54:05 2015 +0200 surcharge des modules de monitoring --- app/module_loader.py | 65 +++++++++---------- app/modules/monitoring_modules/disk.py | 74 ++++++++-------------- app/modules/monitoring_modules/memory.py | 72 +++++++-------------- app/modules/monitoring_modules/ping.py | 59 ++++++----------- app/modules/monitoring_modules/updated_packages.py | 38 +++-------- 5 files changed, 108 insertions(+), 200 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index 33ff089..1ed2863 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -148,20 +148,14 @@ class ModuleLoader: if mod_name not in sys.modules: try: loaded_mod = __import__("modules.monitoring_modules." + mod_name, fromlist=[mod_name]) - class_name = getattr(loaded_mod, "get_class_name")() - if mod_name == 'ping': - mod_inst = getattr(loaded_mod, class_name)(None, None) - else: - mod_inst = getattr(loaded_mod, class_name)(None, None, None) infos_mod = {} infos_mod['imported'] = loaded_mod - infos_mod['class_name'] = getattr(mod_inst, 'get_name')() - infos_mod['compatible_os'] = getattr(mod_inst, 'get_compatible_os')() + infos_mod['compatible_os'] = getattr(loaded_mod, 'compatible_os') for os in infos_mod['compatible_os']: if os not in self.compatible_os_list: self.compatible_os_list.append(os) - infos_mod['block'] = getattr(mod_inst, 'get_block')() - infos_mod['unit'] = getattr(mod_inst, 'get_unit')() + infos_mod['block'] = getattr(loaded_mod, 'block') + infos_mod['unit'] = getattr(loaded_mod, 'unit') infos_mod['external'] = False self.loaded_mod_moni[mod_name] = infos_mod except AttributeError: @@ -172,24 +166,29 @@ class ModuleLoader: sys.path.insert(0, self.conf['external_modules_location']) # Adding the external diretory into pythonpath for importer, mod_name, ispkg in pkgutil.iter_modules([self.conf['external_modules_location']]): if mod_name not in sys.modules: - try: - loaded_mod = __import__(mod_name, fromlist=[mod_name]) - class_name = getattr(loaded_mod, "get_class_name")() - mod_inst = getattr(loaded_mod, class_name)(None, None, None) - infos_mod = {} - infos_mod['imported'] = loaded_mod - infos_mod['class_name'] = getattr(mod_inst, 'get_name')() - infos_mod['compatible_os'] = getattr(mod_inst, 'get_compatible_os')() - for os in infos_mod['compatible_os']: - if os not in self.compatible_os_list: - self.compatible_os_list.append(os) - infos_mod['block'] = getattr(mod_inst, 'get_block')() - infos_mod['unit'] = getattr(mod_inst, 'get_unit')() - infos_mod['external'] = True - self.loaded_mod_moni[mod_name] = infos_mod - except AttributeError: - print "Error : external monitoring module " + mod_name + " could not have been loaded. " - print "Please verify that every necessary methods have been implemented." + loaded_mod = __import__(mod_name, fromlist=[mod_name]) + if mod_name in self.loaded_mod_moni: # if the module overrides an internal one + for attr in dir(loaded_mod): # for each attribute on the external module + if not re.search('^_{2}\S*_{2}$', attr): # we override each declarated attribute + # (we don't override those named __*__) + setattr(self.loaded_mod_moni[mod_name]['imported'], + attr, + getattr(loaded_mod, attr)) + else: # otherwise, we save the external module normally + try: + infos_mod = {} + infos_mod['imported'] = loaded_mod + infos_mod['compatible_os'] = getattr(loaded_mod, 'compatible_os') + for os in infos_mod['compatible_os']: + if os not in self.compatible_os_list: + self.compatible_os_list.append(os) + infos_mod['block'] = getattr(loaded_mod, 'block') + infos_mod['unit'] = getattr(loaded_mod, 'unit') + infos_mod['external'] = True + self.loaded_mod_moni[mod_name] = infos_mod + except AttributeError: + print "Error : external monitoring module " + mod_name + " could not have been loaded. " + print "Please verify that every necessary methods have been implemented." def run_one_monitoring_module(self, mod_name, addr_host, conn, db): """ @@ -202,17 +201,15 @@ class ModuleLoader: if db is None: db = self.get_db() if mod_name == 'ping': - mod_inst = getattr(self.loaded_mod_moni[mod_name]['imported'], - self.loaded_mod_moni[mod_name]['class_name'])(db, addr_host) - mod_inst.check() + dict_notif = getattr(self.loaded_mod_moni[mod_name]['imported'], + 'check')(db, addr_host) + self.run_notification_modules(dict_notif) else: conn = self.create_connection(addr_host) if conn is not None: - mod_inst = getattr(self.loaded_mod_moni[mod_name]['imported'], - self.loaded_mod_moni[mod_name]['class_name'])(conn, db, - modules.ModuleNotCompatibleException) try: - dict_notif = mod_inst.check() + dict_notif = getattr(self.loaded_mod_moni[mod_name]['imported'], + 'check')(conn, db, modules.ModuleNotCompatibleException) self.run_notification_modules(dict_notif) except modules.ModuleNotCompatibleException.ModuleNotCompatibleException as mnce: print mnce.__str__() diff --git a/app/modules/monitoring_modules/disk.py b/app/modules/monitoring_modules/disk.py index 93a1e32..41cfd3d 100644 --- a/app/modules/monitoring_modules/disk.py +++ b/app/modules/monitoring_modules/disk.py @@ -3,52 +3,28 @@ __author__ = 'aguilbaud' import re -def get_class_name(): - return "Disk" - - -class Disk: - """ - Check and returns the percentage of disk used ( = percentage of use of the partition mounted on /) - """ - def __init__(self, conn, db, mnce): - self.conn = conn - self.db = db - self.name = get_class_name() - self.compatible_os = ['linux', 'unix'] - self.block = "hardware" - self.unit = '%' - self.ModuleNotCompatibleException = mnce - - def get_name(self): - return self.name - - def get_compatible_os(self): - return self.compatible_os - - def get_block(self): - return self.block - - def get_unit(self): - return self.unit - - def check(self): - cmd = "df -h" - stdout = self.conn.exec_command(cmd) - disk_used = None - ignore = True - for line in stdout.splitlines(): - # we ignore the first line which contains no value - if ignore: - ignore = False - else: - values = line.split() - if values[len(values)-1] == "/": - disk_used = re.sub("[^0-9]", "", values[len(values)-2]) - if disk_used is None: - exception_inst = getattr(self.ModuleNotCompatibleException, "ModuleNotCompatibleException")( - "disk", self.conn.get_addr_host() - ) - raise exception_inst - res_check = int(disk_used) - return self.db.add_check(self.conn.get_addr_host(), 'disk', res_check) \ No newline at end of file +compatible_os = ['linux', 'unix'] +block = "hardware" +unit = "%" + + +def check(conn, db, mnce): + cmd = "df -h" + stdout = conn.exec_command(cmd) + disk_used = None + ignore = True + for line in stdout.splitlines(): + # we ignore the first line which contains no value + if ignore: + ignore = False + else: + values = line.split() + if values[len(values)-1] == "/": + disk_used = re.sub("[^0-9]", "", values[len(values)-2]) + if disk_used is None: + exception_inst = getattr(mnce, "ModuleNotCompatibleException")( + "disk", conn.get_addr_host() + ) + raise exception_inst + res_check = int(disk_used) + return db.add_check(conn.get_addr_host(), 'disk', res_check) \ No newline at end of file diff --git a/app/modules/monitoring_modules/memory.py b/app/modules/monitoring_modules/memory.py index 87c69f6..7cafb09 100644 --- a/app/modules/monitoring_modules/memory.py +++ b/app/modules/monitoring_modules/memory.py @@ -3,51 +3,27 @@ __author__ = 'aguilbaud' import re -def get_class_name(): - return "Memory" - - -class Memory: - """ - Check and returns the percentage of total memory used of the machine - """ - def __init__(self, conn, db, mnce): - self.conn = conn - self.db = db - self.name = get_class_name() - self.compatible_os = ['linux', 'unix'] - self.block = "hardware" - self.unit = '%' - self.ModuleNotCompatibleException = mnce - - def get_name(self): - return self.name - - def get_compatible_os(self): - return self.compatible_os - - def get_block(self): - return self.block - - def get_unit(self): - return self.unit - - def check(self): - cmd = "cat /proc/meminfo" - stdout = self.conn.exec_command(cmd) - memfree = 0 - memtotal = 0 - for line in stdout.splitlines(): - tab_res = line.split(':') - if(tab_res[0]) == 'MemTotal': - memtotal = re.sub("[^0-9]", "", tab_res[1]) - elif(tab_res[0]) == 'MemFree': - memfree = re.sub("[^0-9]", "", tab_res[1]) - memused = int(memtotal) - int(memfree) - if memused == 0: - exception_inst = getattr(self.ModuleNotCompatibleException, "ModuleNotCompatibleException")( - "memory", self.conn.get_addr_host() - ) - raise exception_inst - res_check = memused * 100 / int(memtotal) - return self.db.add_check(self.conn.get_addr_host(), "memory", res_check) \ No newline at end of file +compatible_os = ['linux', 'unix'] +block = "hardware" +unit = "%" + + +def check(conn, db, mnce): + cmd = "cat /proc/meminfo" + stdout = conn.exec_command(cmd) + memfree = 0 + memtotal = 0 + for line in stdout.splitlines(): + tab_res = line.split(':') + if(tab_res[0]) == 'MemTotal': + memtotal = re.sub("[^0-9]", "", tab_res[1]) + elif(tab_res[0]) == 'MemFree': + memfree = re.sub("[^0-9]", "", tab_res[1]) + memused = int(memtotal) - int(memfree) + if memused == 0: + exception_inst = getattr(mnce, "ModuleNotCompatibleException")( + "memory", conn.get_addr_host() + ) + raise exception_inst + res_check = memused * 100 / int(memtotal) + return db.add_check(conn.get_addr_host(), "memory", res_check) \ No newline at end of file diff --git a/app/modules/monitoring_modules/ping.py b/app/modules/monitoring_modules/ping.py index b9ad35a..6fbea01 100644 --- a/app/modules/monitoring_modules/ping.py +++ b/app/modules/monitoring_modules/ping.py @@ -3,44 +3,23 @@ __author__ = 'aguilbaud' import pexpect -def get_class_name(): - return "Ping" - - -class Ping: - - def __init__(self, db, addr_host): - self.db = db - self.name = get_class_name() - self.compatible_os = [] - self.block = "" - self.unit = 'bool' - self.addr_host = addr_host - - def get_name(self): - return self.name - - def get_compatible_os(self): - return self.compatible_os - - def get_block(self): - return self.block - - def get_unit(self): - return self.unit - - def check(self): +compatible_os = [] +block = "" +unit = "bool" + + +def check(db, addr_host): + res_check = False + try: + child = pexpect.spawn('ping '+ 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 + except pexpect.TIMEOUT: 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 - except pexpect.TIMEOUT: - res_check = False - finally: - return self.db.add_check(self.addr_host, "ping", res_check) \ No newline at end of file + finally: + return db.add_check(addr_host, "ping", res_check) \ No newline at end of file diff --git a/app/modules/monitoring_modules/updated_packages.py b/app/modules/monitoring_modules/updated_packages.py index d511039..817d275 100644 --- a/app/modules/monitoring_modules/updated_packages.py +++ b/app/modules/monitoring_modules/updated_packages.py @@ -1,34 +1,14 @@ __author__ = 'aguilbaud' -def get_class_name(): - return "UpdatedPackages" +compatible_os = ['linux', 'unix'] +block = "software" +unit = "bool" -class UpdatedPackages: - def __init__(self, conn, db, mnce): - self.conn = conn - self.db = db - self.name = get_class_name() - self.compatible_os = ['linux', 'unix'] - self.block = "software" - self.unit = "bool" - - def get_name(self): - return self.name - - def get_compatible_os(self): - return self.compatible_os - - def get_block(self): - return self.block - - def get_unit(self): - return self.unit - - def check(self): - cmd = "apt-get upgrade -s" - stdout = self.conn.exec_command(cmd) - tab_res = stdout.split(':') - res_check = len(tab_res) <= 2 - return self.db.add_check(self.conn.get_addr_host(), "updated_packages", res_check) \ No newline at end of file +def check(conn, db, mnce): + cmd = "apt-get upgrade -s" + stdout = conn.exec_command(cmd) + tab_res = stdout.split(':') + res_check = len(tab_res) <= 2 + return db.add_check(conn.get_addr_host(), "updated_packages", res_check) \ 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