branch develop updated (04ff1e8 -> 926d024)
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 04ff1e8 hostpage et serveur : OK pour l'activation et la désactivation de modules new d137cb9 hostpage : check now => OK new aa79f07 sauvegarde conf de connection (sans formulaire dynamique) new 926d024 OK pour connexion et lancement des modules avec cette connexion The 3 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 926d024f06d07060fec949d4d039219b9b67cb44 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Mar 12 11:21:13 2015 +0100 OK pour connexion et lancement des modules avec cette connexion commit aa79f0791666ab7525283e8bec54c3e0ececc3e7 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Mar 12 10:11:14 2015 +0100 sauvegarde conf de connection (sans formulaire dynamique) commit d137cb9d839afa5b456ce1ea31464bc5c65a747d Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Mar 11 13:53:45 2015 +0100 hostpage : check now => OK Summary of changes: app/app.py | 10 +++++ app/module_loader.py | 30 +++++++++++--- app/modules/connection_modules/ssh.py | 11 +++-- app/modules/monitoring_modules/disk.py | 2 +- app/modules/storage_modules/shelve_db.py | 69 +++++++++++++++++++++++++++++--- bower.json | 3 +- conf.txt | 3 +- static/js/controllers/headCtrl.js | 2 + static/js/controllers/hostPageCtrl.js | 53 ++++++++++++++++++++---- static/js/mumApp.js | 2 +- views/hostpage.html | 38 +++++++++++++++--- views/index.html | 1 + 12 files changed, 193 insertions(+), 31 deletions(-) -- 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 d137cb9d839afa5b456ce1ea31464bc5c65a747d Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Mar 11 13:53:45 2015 +0100 hostpage : check now => OK --- app/app.py | 5 ++++- static/js/controllers/hostPageCtrl.js | 7 +++++++ views/hostpage.html | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/app.py b/app/app.py index 42536fc..30de1e7 100755 --- a/app/app.py +++ b/app/app.py @@ -146,6 +146,9 @@ def receive(ws): ws.send(json_dumps({"RES_GET_LOADED_MONI_MOD": ml.get_info_mod_monitoring()})) elif code == "SET_MOD_ACTIVATION": ml.update_activated_modules(msg["SET_MOD_ACTIVATION"]) + elif code == "CHECK_NOW": + args = msg["CHECK_NOW"] + ml.run_one_monitoring_module(args['mod_name'], args['addr_host'], None, None) else: break except WebSocketError: # Should be WebSocketError when closing the connection @@ -161,6 +164,6 @@ if __name__ == '__main__': ml.load_all_monitoring_modules() ml.load_all_connection_modules() wsc = WebSocketContainer(ml.get_db()) - process_monitoring.init(ml, wsc) + #process_monitoring.init(ml, wsc) port = int(os.environ.get('PORT', 1337)) run(host='0.0.0.0', port=port, debug=True, server=GeventWebSocketServer) \ No newline at end of file diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index 19effef..62106c8 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -34,6 +34,13 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $routeParams, $mo */ $scope.model = {custom_infos : ''}; + $scope.check = function(modname){ + var args = {}; + args['mod_name'] = modname; + args['addr_host'] = $scope.addr_host; + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CHECK_NOW": args})); + }; + $scope.watch('model.custom_infos', function(){ console.log($scope.model.custom_infos); }) diff --git a/views/hostpage.html b/views/hostpage.html index 729266a..a8d037c 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -23,7 +23,7 @@ <td>{{item.state}}</td> <td>{{item.date}}</td> <td><button type="button" class="btn btn-primary btn-xs" ng-click="open_modal_conf(itemname)">Configure</button></td> - <td><button type="button" class="btn btn-info btn-xs">Check now</button></td> + <td><button type="button" class="btn btn-info btn-xs" ng-click="check(itemname)">Check now</button></td> </tr> </tbody> </table> -- 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 aa79f0791666ab7525283e8bec54c3e0ececc3e7 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Mar 12 10:11:14 2015 +0100 sauvegarde conf de connection (sans formulaire dynamique) --- app/app.py | 7 ++++ app/module_loader.py | 12 +++++-- app/modules/storage_modules/shelve_db.py | 58 ++++++++++++++++++++++++++++++-- bower.json | 3 +- conf.txt | 3 +- static/js/controllers/headCtrl.js | 2 ++ static/js/controllers/hostPageCtrl.js | 46 +++++++++++++++++++++---- static/js/mumApp.js | 2 +- views/hostpage.html | 36 +++++++++++++++++--- views/index.html | 1 + 10 files changed, 152 insertions(+), 18 deletions(-) diff --git a/app/app.py b/app/app.py index 30de1e7..3057687 100755 --- a/app/app.py +++ b/app/app.py @@ -149,11 +149,18 @@ def receive(ws): elif code == "CHECK_NOW": args = msg["CHECK_NOW"] ml.run_one_monitoring_module(args['mod_name'], args['addr_host'], None, None) + elif code == "GET_KEYS_LIST": + ws.send(json_dumps({"KEYS_LIST": ml.get_public_keys_list()})) else: break except WebSocketError: # Should be WebSocketError when closing the connection wsc.remove_websocket(ws) break +""" +@route('/upload', method='POST') +def do_upload(): + upload.save(path) +""" # Lancement du serveur a l'adresse 0.0.0.0:1337 diff --git a/app/module_loader.py b/app/module_loader.py index 4a274e3..49eb291 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -13,6 +13,7 @@ import json import re import pkgutil import sys +import os class ModuleLoader: @@ -29,6 +30,7 @@ class ModuleLoader: fconf.close() self.db_loc = dict_conf['db_location'] self.external_mod_loc = dict_conf['external_modules_location'] + self.public_keys_loc = dict_conf['public_keys_location'] self.db = self.load_db(add_func, rem_func) self.loaded_mod_moni = {} # See load_all_monitoring_modules self.loaded_mod_conn = {} # See load_all_connection_modules @@ -69,6 +71,9 @@ class ModuleLoader: ws.send(json.dumps({"ERROR": hnfe.__str__()})) return None + def create_connection(self, addr_host): + avaliable_conn = self.db.get_conf_conn(addr_host) + def run_all_detection_modules(self, os, conn, db, ws): """ Instanciates and runs every detection_modules listed in the __init__.py file of the package corresponding to @@ -281,9 +286,12 @@ class ModuleLoader: "func" : func_name, "args" : [arg1, ...] } - :return: the result of the called function. Or None if the function does not returns a value. + :return: the result of the called function. Or None if the called function does not returns a value. """ return getattr(self.db, dict_instr['func'])(dict_instr['args']) def update_activated_modules(self, args): - self.db.config_mod_activation(args, self.get_monitoring_modules_list()) \ No newline at end of file + self.db.config_mod_activation(args, self.get_monitoring_modules_list()) + + def get_public_keys_list(self): + return json.dumps(os.listdir(self.public_keys_loc)) \ 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 052e712..1757bc1 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -100,7 +100,7 @@ class shelve_db: if port["portname"] in conn_infos: dict_conn[port["portname"]] = { "priority": 0, - "portid": int(port["portid"]) + "port": int(port["portid"]) } for param in conn_infos[port["portname"]]['params']: dict_conn[port["portname"]][param] = None @@ -390,7 +390,6 @@ class shelve_db: self.close_db() return json.dumps(res) - def remove_host(self, addr_host): """ Removes from the database the host at the adress on parameter. If the host is part of a group, it will be @@ -562,6 +561,61 @@ class shelve_db: finally: self.close_db() + def set_prio_conn(self, args): + """ + Save the priorities of connections modules for a host. + :param args: A dictionary containing: + {'addr_host' : val, + 'priorities':{ + mod_name: val + } + } + """ + addr_host = args['addr_host'] + self.open_db() + try: + for mod in args['priorities']: + self.db['hosts'][addr_host]['conf']['connections'][mod]['priority'] = args['priorities'][mod] + finally: + self.close_db() + + def set_conf_conn(self, args): + """ + Save the connection configuration of a host. + :param args: A dictionary containting: + {'addr_host': val, + 'modname': val, + 'current_config': val} + """ + addr_host = args['addr_host'] + modname = args['modname'] + self.open_db() + try: + for param in args['current_config'][modname]: + self.db['hosts'][addr_host]['conf']['connections'][modname][param] = \ + args['current_config']['ssh'][param] + finally: + self.close_db() + """ + def get_conf_conn(self, addr_host): + ''' + Get the configured connections by priority of a host. + :param addr_host: The IP address of the host. + :return: A list containing): + [{'conn_mod_name': val, 'priority': val, 'args': {arg1: val, ...}}] + ''' + res = [] + self.open_db() + try: + for conn in self.db['hosts'][addr_host]['conf']['connections']: + if self.db['hosts'][addr_host]['conf']['connections'][conn]['priority'] > 0: + dict_conn = {} + dict_conn['conn_mod_name'] = conn + dict_conn['priority'] = self.db['hosts'][addr_host]['conf']['connections'][conn]['priority'] + dict_conn['args'] = + finally: + self.close_db() + """ def add_check(self, addr_host, mod_name, val): """ Called by a monitoring module. diff --git a/bower.json b/bower.json index 2dd7dba..2b7c589 100644 --- a/bower.json +++ b/bower.json @@ -7,7 +7,8 @@ "angular-toastr": "~0.5.2", "angular-route": "~1.2.28", "angular-bootstrap": "~0.12.1", - "angular-sanitize": "~1.2.28" + "angular-sanitize": "~1.2.28", + "angular-file-upload": "~1.1.5" }, "resolutions": { "angular": "~1.2.28" diff --git a/conf.txt b/conf.txt index 008cd5f..99f99da 100644 --- a/conf.txt +++ b/conf.txt @@ -1,2 +1,3 @@ db_location=mum.db -external_modules_location=/home/aguilbaud/external \ No newline at end of file +external_modules_location=/home/aguilbaud/external +public_keys_location=keys/ \ No newline at end of file diff --git a/static/js/controllers/headCtrl.js b/static/js/controllers/headCtrl.js index 10bbc86..f1467c7 100644 --- a/static/js/controllers/headCtrl.js +++ b/static/js/controllers/headCtrl.js @@ -70,6 +70,8 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r $scope.pop_danger("Danger on "+ params[1], params[2]); } break; + case "KEYS_LIST": + $rootScope.$broadcast("keysList", JSON.parse(value)); case "ERROR": toastr.error(value, "Server error"); break; diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index 62106c8..b905f2c 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -225,11 +225,11 @@ mumApp.controller('ModalConnInstanceCtrl', function ($scope, $rootScope, $modalI $scope.isNotConfigured = function(modname){ res = false; - for(param in $scope.current_config[modname]){ + /*for(param in $scope.current_config[modname]){ if($scope.current_config[modname][param] == null){ res = true; } - } + }*/ return res; } @@ -247,7 +247,10 @@ mumApp.controller('ModalConnInstanceCtrl', function ($scope, $rootScope, $modalI $scope.ok = function () { var args = {}; + args['addr_host'] = $scope.conn_args.addr_host; + args['priorities'] = $scope.priorities; + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'set_prio_conn','args': args}})); $modalInstance.close(); }; @@ -270,7 +273,11 @@ mumApp.controller('ModalConnInstanceCtrl', function ($scope, $rootScope, $modalI }; }); -mumApp.controller('ModalConfConnInstanceCtrl', function ($scope, $rootScope, $modalInstance, $templateCache, conf_conn_args) { +mumApp.controller('ModalConfConnInstanceCtrl', function ($scope, $rootScope, $modalInstance, $templateCache, conf_conn_args, FileUploader) { + $scope.uploader = new FileUploader({ + url: '/upload' + }); + $scope.conf_conn_args = conf_conn_args; /* {'addr_host': val, 'modname': val, 'current_config': val} */ @@ -283,16 +290,33 @@ mumApp.controller('ModalConfConnInstanceCtrl', function ($scope, $rootScope, $mo 'params': {param1: type1, param2: type2, ...} => the parameters necessary to create the connection } } */ + $scope.conf_conn = {}; + + $scope.port = $scope.conf_conn_args["current_config"]["ssh"]["port"]; + + $scope.username = $scope.conf_conn_args["current_config"]["ssh"]["username"]; + $scope.public_key = $scope.conf_conn_args["current_config"]["ssh"]["public_key"]; + + $scope.keys_list = []; $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_LOADED_CONN_MOD": ""})); + $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_KEYS_LIST": ""})); + + $scope.$on("keysList", function (event, args) { + $scope.$apply(function(){ + $scope.keys_list = args; + }); + }); + $scope.$on("resGetLoadedConnMod", function (event, args) { $scope.$apply(function(){ $scope.loaded_conn_mods = args; - for(mod in args){ + /*for(mod in args){ //alert(args[mod]); for(param in args[mod]){ + $scope.conf_conn[param] = $scope.conf_conn_args["current_config"][param]; //alert(param); $scope.form += '<div class="row">'; $scope.form += ' <div class="col-xs-3">'; @@ -303,14 +327,22 @@ mumApp.controller('ModalConfConnInstanceCtrl', function ($scope, $rootScope, $mo $scope.form += ' </div>'; $scope.form += '</div>'; } - } - $templateCache.put('templateForm.html', $scope.form); + }*/ + //$templateCache.put('templateForm.html', $scope.form); }); + }); + $scope.ok = function () { - var args = {}; + var args = conf_conn_args; + args['current_config']['ssh'] = {} + args['current_config']['ssh']['port'] = $scope.port; + args['current_config']['ssh']['username'] = $scope.username; + args['current_config']['ssh']['public_key'] = $scope.public_key; + + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'set_conf_conn','args': args}})); $modalInstance.close(); }; diff --git a/static/js/mumApp.js b/static/js/mumApp.js index c6c12c0..bc223ef 100644 --- a/static/js/mumApp.js +++ b/static/js/mumApp.js @@ -1,4 +1,4 @@ -var mumApp = angular.module('mumApp', ['ngSanitize', 'ngRoute', 'ui.bootstrap', 'toastr']); +var mumApp = angular.module('mumApp', ['angularFileUpload', 'ngSanitize', 'ngRoute', 'ui.bootstrap', 'toastr']); mumApp.factory('DataHosts', function(){ return {Items: []}; diff --git a/views/hostpage.html b/views/hostpage.html index a8d037c..b5af0d7 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -162,7 +162,7 @@ <tbody> <tr ng-repeat="(modname, modconf) in current_config"> <td>{{modname}}</td> - <td><input type="number" min="0" ng-model="priorities[modname]" disabled="{{isNotConfigured(modname)}}"></td> + <td><input type="number" min="0" ng-model="priorities[modname]" ng-disabled="isNotConfigured(modname)"></td> <td> <button type="button" class="btn btn-primary" ng-click="open_modal_conf_conn(modname)">Advanced configuration</button> <button type="button" class="btn btn-success">Test</button> @@ -184,11 +184,39 @@ <script type="text/ng-template" id="modal_conf_conn_label.html"> <div class="modal-header"> - <h3 class="modal-title">Advanced settings for {{conf_conn_args['modname']}}</h3>{{loaded_conn_mods}} + <h3 class="modal-title">Advanced settings for {{conf_conn_args['modname']}}</h3> </div> - {{form}} + <div class="modal-body"> - <div ng-include=" 'templateForm.html' "></div> + {{loaded_conn_mods}} + <!--<input type="file" nv-file-select uploader="uploader"/><br/> + <ul> + <li ng-repeat="item in uploader.queue"> + Upload a new key: <span ng-bind="item.file.name"></span><br/> + <button ng-click="item.upload(item, '\keys')">upload</button> + </li> + </ul>--> + <div class="row"> + <div class="col-xs-2"> + <label for="port">Port used</label> + <input type="number" id="port" min="0" ng-model="port"> + </div> + </div> + <div class="row"> + <div class="col-xs-2"> + <label for="public_key">Select a public key</label> + <select class="form-control input-sm" id="public_key" ng-model="public_key" ng-options="key as key for key in keys_list"></select> + </div> + </div> + <div class="row"> + <div class="col-xs-3"> + <label for="usrname">Login</label> + <input type="text" id="usrname" ng-model="username"/> + </div> + </div> + + + <!--<div ng-include=" 'templateForm.html' "></div>--> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="cancel()">Close</button> diff --git a/views/index.html b/views/index.html index 1ac05c3..1bb2ed5 100644 --- a/views/index.html +++ b/views/index.html @@ -19,6 +19,7 @@ <!-- AngularJS --> <script src="bower_components/angular/angular.min.js"></script> + <script src="bower_components/angular-file-upload/angular-file-upload.min.js"></script> <script src="bower_components/angular-sanitize/angular-sanitize.min.js"></script> <script src="bower_components/angular-route/angular-route.min.js"></script> <script src="bower_components/angular-toastr/dist/angular-toastr.min.js"></script> -- 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 926d024f06d07060fec949d4d039219b9b67cb44 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Mar 12 11:21:13 2015 +0100 OK pour connexion et lancement des modules avec cette connexion --- app/app.py | 2 +- app/module_loader.py | 18 ++++++++++++++---- app/modules/connection_modules/ssh.py | 11 ++++++++--- app/modules/monitoring_modules/disk.py | 2 +- app/modules/storage_modules/shelve_db.py | 19 +++++++++++-------- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/app/app.py b/app/app.py index 3057687..f712f68 100755 --- a/app/app.py +++ b/app/app.py @@ -171,6 +171,6 @@ if __name__ == '__main__': ml.load_all_monitoring_modules() ml.load_all_connection_modules() wsc = WebSocketContainer(ml.get_db()) - #process_monitoring.init(ml, wsc) + process_monitoring.init(ml, wsc) port = int(os.environ.get('PORT', 1337)) run(host='0.0.0.0', port=port, debug=True, server=GeventWebSocketServer) \ No newline at end of file diff --git a/app/module_loader.py b/app/module_loader.py index 49eb291..10da678 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -31,18 +31,18 @@ class ModuleLoader: self.db_loc = dict_conf['db_location'] self.external_mod_loc = dict_conf['external_modules_location'] self.public_keys_loc = dict_conf['public_keys_location'] - self.db = self.load_db(add_func, rem_func) + self.db = self.load_db(add_func, rem_func, self.public_keys_loc) self.loaded_mod_moni = {} # See load_all_monitoring_modules self.loaded_mod_conn = {} # See load_all_connection_modules - def load_db(self, add_func, rem_func): + def load_db(self, add_func, rem_func, key_loc): """ Creates an instance of the class shelve_db from storage_modules. :return: an instance of the shelve_db class """ db_name = "shelve_db" db = __import__("modules.storage_modules." + db_name, fromlist=modules.storage_modules) - db_instance = getattr(db, db_name)(self.db_loc, add_func, rem_func) + db_instance = getattr(db, db_name)(self.db_loc, add_func, rem_func, key_loc) return db_instance def get_db(self): @@ -73,6 +73,15 @@ class ModuleLoader: def create_connection(self, addr_host): avaliable_conn = self.db.get_conf_conn(addr_host) + mod_inst = None + if not avaliable_conn == []: + conn = avaliable_conn.pop() + mod_inst = getattr(self.loaded_mod_conn[conn['conn_mod_name']]['imported'], + self.loaded_mod_conn[conn['conn_mod_name']]['class_name'])(addr_host, + conn['args'], + self.public_keys_loc, + modules.CommandNotFoundException) + return mod_inst def run_all_detection_modules(self, os, conn, db, ws): """ @@ -155,6 +164,7 @@ class ModuleLoader: self.loaded_mod_moni[mod_name]['class_name'])(db, addr_host) mod_inst.check() else: + conn = self.create_connection(addr_host) mod_inst = getattr(self.loaded_mod_moni[mod_name]['imported'], self.loaded_mod_moni[mod_name]['class_name'])(conn, db, modules.ModuleNotCompatibleException) @@ -215,7 +225,7 @@ class ModuleLoader: try: loaded_mod = __import__("modules.connection_modules." + mod_name, fromlist=[mod_name]) class_name = getattr(loaded_mod, "get_class_name")() - mod_inst = getattr(loaded_mod, class_name)(None, None, None) + mod_inst = getattr(loaded_mod, class_name)(None, None, None, None) infos_mod = {} infos_mod['imported'] = loaded_mod infos_mod['class_name'] = getattr(mod_inst, 'get_name')() diff --git a/app/modules/connection_modules/ssh.py b/app/modules/connection_modules/ssh.py index b407dc8..8806756 100644 --- a/app/modules/connection_modules/ssh.py +++ b/app/modules/connection_modules/ssh.py @@ -6,16 +6,21 @@ def get_class_name(): class SSH: - def __init__(self, addr_host, params, cnfe): + def __init__(self, addr_host, params, key_loc, cnfe): self.parameters = {"username": "string", "public_key": "file", "port": "int"} self.name = get_class_name() self.addr_host = addr_host self.CommandNotFoundException = cnfe if params is not None: - key = paramiko.RSAKey.from_private_key_file(params['public_key']) + key_path = str(key_loc) + str(params['public_key']) + print key_path + key = paramiko.RSAKey.from_private_key_file(key_path) self.ssh = paramiko.SSHClient() self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - self.ssh.connect(addr_host, username=params['username'], pkey=key, port=params['port']) + self.ssh.connect(addr_host, + username=params['username'], + pkey=key, + port=params['port']) def get_name(self): return self.name diff --git a/app/modules/monitoring_modules/disk.py b/app/modules/monitoring_modules/disk.py index 33ceec1..15c734c 100644 --- a/app/modules/monitoring_modules/disk.py +++ b/app/modules/monitoring_modules/disk.py @@ -51,4 +51,4 @@ class Disk: ) raise exception_inst res_check = int(disk_used) - self.db.add_check(self.conn.get_addr_host(), self.name, res_check) \ No newline at end of file + self.db.add_check(self.conn.get_addr_host(), 'disk', 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 1757bc1..ce7bf7a 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -13,11 +13,12 @@ class shelve_db: Storage module for the persistant objects in Python : Shelve. Every function in need to access the database have to be moved in this class. """ - def __init__(self, db_loc, add_func, rem_func): + def __init__(self, db_loc, add_func, rem_func, key_loc): self.db = None self.db_loc = db_loc self.add_to_monitoring_list = add_func self.rem_to_monitoring_list = rem_func + self.key_loc = key_loc def open_db(self): """ @@ -596,12 +597,12 @@ class shelve_db: args['current_config']['ssh'][param] finally: self.close_db() - """ + def get_conf_conn(self, addr_host): ''' Get the configured connections by priority of a host. :param addr_host: The IP address of the host. - :return: A list containing): + :return: A list containing: [{'conn_mod_name': val, 'priority': val, 'args': {arg1: val, ...}}] ''' res = [] @@ -612,10 +613,12 @@ class shelve_db: dict_conn = {} dict_conn['conn_mod_name'] = conn dict_conn['priority'] = self.db['hosts'][addr_host]['conf']['connections'][conn]['priority'] - dict_conn['args'] = + dict_conn['args'] = self.db['hosts'][addr_host]['conf']['connections'][conn] + res.append(dict_conn) finally: self.close_db() - """ + return res + def add_check(self, addr_host, mod_name, val): """ Called by a monitoring module. @@ -628,6 +631,9 @@ class shelve_db: self.open_db() new_val = {"date": str(datetime.now()), "value" : val} try: + 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] = {} if type(val) == type(True): # if boolean if self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['minor_limit'] and not val: @@ -648,9 +654,6 @@ class shelve_db: 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 # updating the global state of the host -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm