branch develop updated (017493c -> dea769f)
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 017493c notifications page : possibilité d'ajouter un utilisateur à la liste des inscrits d'un groupe et d'un hôte new dea769f chargement dynamique des modules de notification The 1 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 dea769f40075d9b8052ccdc28778a49cc4fb3c87 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Mar 19 16:38:18 2015 +0100 chargement dynamique des modules de notification Summary of changes: app/app.py | 3 + app/module_loader.py | 40 +++- app/modules/notification_modules/email_notif.py | 6 +- static/js/controllers/headCtrl.js | 3 + static/js/controllers/notificationsCtrl.js | 10 + views/notifications.html | 271 ++++++++++++------------ 6 files changed, 197 insertions(+), 136 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 dea769f40075d9b8052ccdc28778a49cc4fb3c87 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Mar 19 16:38:18 2015 +0100 chargement dynamique des modules de notification --- app/app.py | 3 + app/module_loader.py | 40 +++- app/modules/notification_modules/email_notif.py | 6 +- static/js/controllers/headCtrl.js | 3 + static/js/controllers/notificationsCtrl.js | 10 + views/notifications.html | 271 ++++++++++++------------ 6 files changed, 197 insertions(+), 136 deletions(-) diff --git a/app/app.py b/app/app.py index 15a5180..e1afd3a 100755 --- a/app/app.py +++ b/app/app.py @@ -144,6 +144,8 @@ def receive(ws): 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()})) + 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()})) elif code == "SET_MOD_ACTIVATION": # asked from hostpage, at the block activation conf ml.update_activated_modules(msg["SET_MOD_ACTIVATION"]) elif code == "SET_CONF_MOD": # asked from hostpage, at the monitoring module configuration @@ -179,6 +181,7 @@ if __name__ == '__main__': ml.load_all_monitoring_modules() ml.load_all_connection_modules() ml.load_all_detection_modules() + ml.load_all_notification_modules() wsc = WebSocketContainer(ml.get_db()) process_monitoring.init(ml, wsc) port = int(os.environ.get('PORT', 1337)) diff --git a/app/module_loader.py b/app/module_loader.py index 7442759..9ee6ac4 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -33,8 +33,9 @@ class ModuleLoader: self.public_keys_loc = dict_conf['keys_location'] 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_detect = {} # See load_all_detection_modules + self.loaded_mod_detect = {} # See load_all_detection_modules self.loaded_mod_conn = {} # See load_all_connection_modules + self.loaded_mod_notif = {} # See load_all_notification_modules def load_db(self, add_func, rem_func, key_loc): """ @@ -291,6 +292,43 @@ class ModuleLoader: res[mod] = self.loaded_mod_conn[mod]['params'] return json.dumps(res) + def load_all_notification_modules(self): + """ + Instanciates and stores the informations about each notification modules avaliable + on the loaded_mod_notif attribute. + """ + for importer, mod_name, ispkg in pkgutil.iter_modules(["app/modules/notification_modules/"]): + if mod_name not in sys.modules and not mod_name == 'websocket_container': + try: + loaded_mod = __import__("modules.notification_modules." + mod_name, fromlist=[mod_name]) + class_name = getattr(loaded_mod, "get_class_name")() + mod_inst = getattr(loaded_mod, class_name)(None, None) + infos_mod = {} + infos_mod['imported'] = loaded_mod + infos_mod['class_name'] = getattr(mod_inst, 'get_name')() + infos_mod['params'] = getattr(mod_inst, 'get_parameters')() + self.loaded_mod_notif[mod_name] = infos_mod + except AttributeError: + print "Error : internal notification module " + mod_name + " could not have been loaded. " + + def get_info_mod_notification(self): + """ + Get informations about of the connection modules loaded and their parameters necessary to instanciate the + connection. The type of the parameters is necessary for the web application in order to show a corresponding + form (can be 'string' for a textfield, 'int' for a number field, 'file' for a file location). + :return: a JSON string containing informations about the connection modules: + { + mod_name: + { + 'params': {param1: type1, param2: type2, ...} => the parameters necessary to create the connection + } + } + """ + res = {} + for mod in self.loaded_mod_notif: + res[mod] = self.loaded_mod_notif[mod]['params'] + return json.dumps(res) + def update_global_conf(self): """ Asks the database to update the configuration if new monitoring modules are added in function of the diff --git a/app/modules/notification_modules/email_notif.py b/app/modules/notification_modules/email_notif.py index 826ae6a..09f495e 100644 --- a/app/modules/notification_modules/email_notif.py +++ b/app/modules/notification_modules/email_notif.py @@ -10,9 +10,13 @@ def get_class_name(): class EMail: def __init__(self, msg, params): + self.name = get_class_name() self.msg = msg self.params = params - self.parameters = {"users": "dict", "smtp_server": "string"} # dict = {user: {'username': val, 'email'; val}} + self.parameters = {"users": "dict", "smtp_server": "string"} # dict = {user: {'username': val, 'email'; val}} + + def get_name(self): + return self.name def get_parameters(self): return self.parameters diff --git a/static/js/controllers/headCtrl.js b/static/js/controllers/headCtrl.js index 9472c04..6560902 100644 --- a/static/js/controllers/headCtrl.js +++ b/static/js/controllers/headCtrl.js @@ -46,6 +46,9 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r case "RES_GET_LOADED_MONI_MOD": $rootScope.$broadcast("resGetLoadedMoniMod", JSON.parse(value)); break; + case "RES_GET_LOADED_NOTIF_MOD": + $rootScope.$broadcast("resGetLoadedNotifMod", JSON.parse(value)); + break; case "RES_CALL_FUNC_DB": // Get a result after calling a funcion on the db $rootScope.$broadcast("resCall", JSON.parse(value)); break; diff --git a/static/js/controllers/notificationsCtrl.js b/static/js/controllers/notificationsCtrl.js index fc4af3e..38fcfe0 100644 --- a/static/js/controllers/notificationsCtrl.js +++ b/static/js/controllers/notificationsCtrl.js @@ -17,6 +17,16 @@ mumApp.controller('notificationsCtrl', function($scope, $rootScope, $modal, Data ] */ + $scope.notif_mods = {}; + + $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_LOADED_NOTIF_MOD": ""})); + + $scope.$on("resGetLoadedNotifMod", function (event, args) { + $scope.$apply(function(){ + $scope.notif_mods = args; + }); + }); + $scope.subscriber_data = {}; $scope.allGroups = function(){ diff --git a/views/notifications.html b/views/notifications.html index f4afc3a..9647ed8 100644 --- a/views/notifications.html +++ b/views/notifications.html @@ -2,7 +2,8 @@ <div class="col-md-offset-2 main"> <h1 class="page-header">Who to notify?</h1> <!--<h2 class="sub-header">They will be applied on each new host you will add.</h2>--> - {{subscriber_data}} + {{subscriber_data}}<br/> + {{notif_mods}} <form> <div class="row"> <div class="col-lg-6"> @@ -39,139 +40,141 @@ </form> - <p>Check the box if you want the user to be notified by the correspondant service.</p> - <p>The value represents the numbers of notifications that should occure since the last login of the user.</p> - <p>The notification will be sent to the user, by this service, once this value is reached.</p> - <table class="table table-bordered"> - <thead> - <tr> - <th>User <button type="button" class="btn btn-primary btn-xs" ng-click="open_modal_add_subscriber()">Add...</button></th> - <th>Notification service </th> - <th>Minor notifications</th> - <th>Major notifications</th> - </tr> - </thead> - <tbody> - <tr> - <td rowspan="3">G.G.</td> - <td>Browser</td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="jcbrowsermincheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="jcbrowserminnb" placeholder="1"> - </div> - </td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="jcbrowsermajcheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="jcbrowsermajnb" placeholder="1"> - </div> - </td> - </tr> - <tr> - <td>E-mail</td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="jcmailmincheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="jcmailminnb" placeholder="1"> - </div> - </td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="jcmailmajcheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="jcmailmajnb" placeholder="1"> - </div> - </td> - </tr> - <tr> - <td>SMS</td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="jcsmsmincheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="jcsmsminnb" placeholder="1"> - </div> - </td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="jcsmsmajcheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="jcsmsmajnb" placeholder="1"> - </div> - </td> - </tr> - <tr> - <td rowspan="3">J.C.</td> - <td>Browser</td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="ggbrowserminchecj"> - </span> - <input type="number" min="1" class="form-control" aria-label="ggbrowserminnb" placeholder="1"> - </div> - </td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="ggbrowsermajcheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="ggbrowsermajnb" placeholder="1"> - </div> - </td> - </tr> - <tr> - <td>E-mail</td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="ggmailmincheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="ggmailminnb" placeholder="1"> - </div> - </td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="ggmailmajcheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="ggmailmajnb" placeholder="1"> - </div> - </td> - </tr> - <tr> - <td>SMS</td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="ggsmsmincheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="ggsmsminnb" placeholder="1"> - </div> - </td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="ggsmsmajcheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="ggsmsmajnb" placeholder="1"> - </div> - </td> - </tr> - </tbody> - </table> - <button type="button" class="btn btn-default">Discard changes</button> - <button type="button" class="btn btn-primary">Save changes</button> + <div ng-show="selected_host!='' || selected_grp!=''"> + <p>Check the box if you want the user to be notified by the correspondant service.</p> + <p>The value represents the numbers of notifications that should occure since the last login of the user.</p> + <p>The notification will be sent to the user, by this service, once this value is reached.</p> + <table class="table table-bordered"> + <thead> + <tr> + <th>User <button type="button" class="btn btn-primary btn-xs" ng-click="open_modal_add_subscriber()">Add...</button></th> + <th>Notification service </th> + <th>Minor notifications</th> + <th>Major notifications</th> + </tr> + </thead> + <tbody> + <tr> + <td rowspan="3">G.G.</td> + <td>Browser</td> + <td> + <div class="input-group"> + <span class="input-group-addon"> + <input type="checkbox" aria-label="jcbrowsermincheck"> + </span> + <input type="number" min="1" class="form-control" aria-label="jcbrowserminnb" placeholder="1"> + </div> + </td> + <td> + <div class="input-group"> + <span class="input-group-addon"> + <input type="checkbox" aria-label="jcbrowsermajcheck"> + </span> + <input type="number" min="1" class="form-control" aria-label="jcbrowsermajnb" placeholder="1"> + </div> + </td> + </tr> + <tr> + <td>E-mail</td> + <td> + <div class="input-group"> + <span class="input-group-addon"> + <input type="checkbox" aria-label="jcmailmincheck"> + </span> + <input type="number" min="1" class="form-control" aria-label="jcmailminnb" placeholder="1"> + </div> + </td> + <td> + <div class="input-group"> + <span class="input-group-addon"> + <input type="checkbox" aria-label="jcmailmajcheck"> + </span> + <input type="number" min="1" class="form-control" aria-label="jcmailmajnb" placeholder="1"> + </div> + </td> + </tr> + <tr> + <td>SMS</td> + <td> + <div class="input-group"> + <span class="input-group-addon"> + <input type="checkbox" aria-label="jcsmsmincheck"> + </span> + <input type="number" min="1" class="form-control" aria-label="jcsmsminnb" placeholder="1"> + </div> + </td> + <td> + <div class="input-group"> + <span class="input-group-addon"> + <input type="checkbox" aria-label="jcsmsmajcheck"> + </span> + <input type="number" min="1" class="form-control" aria-label="jcsmsmajnb" placeholder="1"> + </div> + </td> + </tr> + <tr> + <td rowspan="3">J.C.</td> + <td>Browser</td> + <td> + <div class="input-group"> + <span class="input-group-addon"> + <input type="checkbox" aria-label="ggbrowserminchecj"> + </span> + <input type="number" min="1" class="form-control" aria-label="ggbrowserminnb" placeholder="1"> + </div> + </td> + <td> + <div class="input-group"> + <span class="input-group-addon"> + <input type="checkbox" aria-label="ggbrowsermajcheck"> + </span> + <input type="number" min="1" class="form-control" aria-label="ggbrowsermajnb" placeholder="1"> + </div> + </td> + </tr> + <tr> + <td>E-mail</td> + <td> + <div class="input-group"> + <span class="input-group-addon"> + <input type="checkbox" aria-label="ggmailmincheck"> + </span> + <input type="number" min="1" class="form-control" aria-label="ggmailminnb" placeholder="1"> + </div> + </td> + <td> + <div class="input-group"> + <span class="input-group-addon"> + <input type="checkbox" aria-label="ggmailmajcheck"> + </span> + <input type="number" min="1" class="form-control" aria-label="ggmailmajnb" placeholder="1"> + </div> + </td> + </tr> + <tr> + <td>SMS</td> + <td> + <div class="input-group"> + <span class="input-group-addon"> + <input type="checkbox" aria-label="ggsmsmincheck"> + </span> + <input type="number" min="1" class="form-control" aria-label="ggsmsminnb" placeholder="1"> + </div> + </td> + <td> + <div class="input-group"> + <span class="input-group-addon"> + <input type="checkbox" aria-label="ggsmsmajcheck"> + </span> + <input type="number" min="1" class="form-control" aria-label="ggsmsmajnb" placeholder="1"> + </div> + </td> + </tr> + </tbody> + </table> + <button type="button" class="btn btn-default">Discard changes</button> + <button type="button" class="btn btn-primary">Save changes</button> + </div> </div> <script type="text/ng-template" id="modal_add_subscriber_label.html"> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm