branch develop updated (488d527 -> 131a4f4)
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 488d527 suppression de mum.conf new a895f09 process_monitoring proprement arreté après KeyboardInterrupt new 856c7de correction structure templates new ebfe3a4 groups: les hôtes peuvent être ajoutés à un groupe new 131a4f4 groups: les hôtes peuvent être retirés d'un groupe + changement du res de get_host() concernant les groupes => pb du filtre des groupes résolu The 4 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 131a4f4e743ca31961f89f673810b44a5b787880 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Tue Mar 17 13:44:43 2015 +0100 groups: les hôtes peuvent être retirés d'un groupe + changement du res de get_host() concernant les groupes => pb du filtre des groupes résolu commit ebfe3a42c3930a3cf413c3b1051abf669536f774 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Tue Mar 17 10:36:39 2015 +0100 groups: les hôtes peuvent être ajoutés à un groupe commit 856c7dee5a0bd6eaf9485dda4ec431201d1ec114 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Mar 16 09:43:01 2015 +0100 correction structure templates commit a895f0985534383f4f97077d1bab30b65a8882c5 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Mar 13 15:12:17 2015 +0100 process_monitoring proprement arreté après KeyboardInterrupt Summary of changes: .gitignore | 3 +- README | 9 +- app/app.py | 4 +- app/module_loader.py | 2 +- app/modules/detection_modules/nmap_detection.py | 4 +- app/modules/notification_modules/email_notif.py | 29 +++++ app/modules/storage_modules/shelve_db.py | 94 +++++++++-------- app/process_monitoring.py | 4 +- bootstrap.sh => install.sh | 8 +- static/js/controllers/groupCtrl.js | 134 +++++++++++++++++++----- views/groups.html | 37 +++++-- views/hostpage.html | 4 +- views/index.html | 12 ++- views/notifications.html | 40 ++++--- views/profile.html | 4 +- views/scan.html | 3 - views/settings.html | 4 +- 17 files changed, 270 insertions(+), 125 deletions(-) create mode 100644 app/modules/notification_modules/email_notif.py rename bootstrap.sh => install.sh (71%) -- 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 a895f0985534383f4f97077d1bab30b65a8882c5 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Mar 13 15:12:17 2015 +0100 process_monitoring proprement arreté après KeyboardInterrupt --- .gitignore | 3 ++- app/app.py | 4 +++- app/process_monitoring.py | 4 +++- bootstrap.sh | 8 ++++---- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 3e1bfa5..057b930 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ res.xml mum.db */pyc /*.pyc -*/*.pyc \ No newline at end of file +*/*.pyc +mum.conf \ No newline at end of file diff --git a/app/app.py b/app/app.py index 36c9804..a7f4962 100755 --- a/app/app.py +++ b/app/app.py @@ -179,4 +179,6 @@ if __name__ == '__main__': wsc = WebSocketContainer(ml.get_db()) 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 + run(host='0.0.0.0', port=port, server=GeventWebSocketServer) + # after ending + process_monitoring.end = True diff --git a/app/process_monitoring.py b/app/process_monitoring.py index 357613b..c056d7f 100644 --- a/app/process_monitoring.py +++ b/app/process_monitoring.py @@ -7,6 +7,7 @@ import time import sys waiting_list = [] +end = False def init(ml,wsc): @@ -45,9 +46,10 @@ class ProcessMonitoring(threading.Thread): If it is the case, it will add this element to the launching list, as well with the previous elements having the same launching date. """ + global end global waiting_list ready_to_launch = False - while True: + while not end: if not waiting_list == []: modules_to_run = [] while waiting_list[len(waiting_list) - 1]['time'] <= datetime.now(): diff --git a/bootstrap.sh b/bootstrap.sh index d3e4e99..589c9be 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -10,10 +10,10 @@ sed -i 's/{{/[[/g' venv/lib/python2.7/site-packages/bottle.py sed -i 's/}}/]]/g' venv/lib/python2.7/site-packages/bottle.py #creating the configuration file -touch toto.conf -echo "db_location=$HOME/.mum/mum.db" >> toto.conf -echo "external_modules_location=$HOME/.mum/external" >> toto.conf -echo "keys_location=$HOME/.mum/keys/" >> toto.conf +touch mum.conf +echo "db_location=$HOME/.mum/mum.db" >> mum.conf +echo "external_modules_location=$HOME/.mum/external" >> mum.conf +echo "keys_location=$HOME/.mum/keys/" >> mum.conf # creating the basic folders mkdir $HOME/.mum -- 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 856c7dee5a0bd6eaf9485dda4ec431201d1ec114 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Mar 16 09:43:01 2015 +0100 correction structure templates --- app/app.py | 2 +- app/modules/storage_modules/shelve_db.py | 44 ++++++++++++++++++-------------- views/hostpage.html | 3 ++- views/index.html | 12 +++++---- views/notifications.html | 40 ++++++++++++++--------------- views/profile.html | 4 +-- views/scan.html | 3 --- views/settings.html | 4 +-- 8 files changed, 56 insertions(+), 56 deletions(-) diff --git a/app/app.py b/app/app.py index a7f4962..8ffda84 100755 --- a/app/app.py +++ b/app/app.py @@ -179,6 +179,6 @@ if __name__ == '__main__': wsc = WebSocketContainer(ml.get_db()) process_monitoring.init(ml, wsc) port = int(os.environ.get('PORT', 1337)) - run(host='0.0.0.0', port=port, server=GeventWebSocketServer) + run(host='0.0.0.0', port=port, debug=True, server=GeventWebSocketServer) # after ending process_monitoring.end = True diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 4e2f75e..d03b7c3 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -346,25 +346,31 @@ class shelve_db: Get every informations necessary for the hostpage summary page. :param addr_host: the IP address of the host :return: informations concerning this host on the form : - { - 'host_name': val, - 'monitoring':{ - mod_name:{ - 'state':val, - 'value':val, - 'unit':val, - 'last_check':date - } - } - 'activated_monitoring':{ - mod_name: bool - } - 'detection':{ - mod_name:res - } - 'custom_info';val - 'interventions':list - } + { + "interventions":list, + "detected": + { + modname: + { + key:val, + ... + } + } + "hostname":val, + "monitoring": + { + modname: + { + "date":val, + "state":val, + "value":val + } + }, + 'activated_monitoring':{ + mod_name: bool + }, + "custom_infos":val + } """ self.open_db() res = {} diff --git a/views/hostpage.html b/views/hostpage.html index 31f2734..e89aea9 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -396,4 +396,5 @@ </div> </div> </div> - --> \ No newline at end of file + --> + </div> \ No newline at end of file diff --git a/views/index.html b/views/index.html index 1bb2ed5..f273638 100644 --- a/views/index.html +++ b/views/index.html @@ -80,11 +80,13 @@ <div id="main"> <div ng-view></div> </div> - <!-- Bootstrap core JavaScript - ================================================== --> - <!-- Placed at the end of the document so the pages load faster - <script src="bower_components/jquery/dist/jquery.min.js"></script> - <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>--> + <!-- Bootstrap core JavaScript + ================================================== --> + <!-- Placed at the end of the document so the pages load faster + <script src="bower_components/jquery/dist/jquery.min.js"></script> + <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>--> + </div> + </div> </body> </html> diff --git a/views/notifications.html b/views/notifications.html index 6b25851..172e172 100644 --- a/views/notifications.html +++ b/views/notifications.html @@ -153,28 +153,26 @@ <button type="button" class="btn btn-default">Discard changes</button> <button type="button" class="btn btn-primary">Save changes</button> </div> - </div> -</div> -<div class="modal fade" id="modal_add" tabindex="-1" role="dialog" aria-labelledby="modal_add_label" aria-hidden="true"> - <div class="modal-dialog"> - <div class="modal-content"> - <div class="modal-header"> - <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> - <h4 class="modal-title" id="modal_add_label">Add users to this group/host</h4> - </div> - <div class="modal-body"> - <select multiple class="form-control"> - <option>D.D.</option> - <option>J.D.</option> - <option>X.R.</option> - </select> - </div> - <div class="modal-footer"> - <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> - <button type="button" class="btn btn-primary">Add selected</button> + <div class="modal fade" id="modal_add" tabindex="-1" role="dialog" aria-labelledby="modal_add_label" aria-hidden="true"> + <div class="modal-dialog"> + <div class="modal-content"> + <div class="modal-header"> + <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> + <h4 class="modal-title" id="modal_add_label">Add users to this group/host</h4> + </div> + <div class="modal-body"> + <select multiple class="form-control"> + <option>D.D.</option> + <option>J.D.</option> + <option>X.R.</option> + </select> + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> + <button type="button" class="btn btn-primary">Add selected</button> + </div> + </div> </div> </div> - </div> -</div> diff --git a/views/profile.html b/views/profile.html index cf30c2a..df1c645 100644 --- a/views/profile.html +++ b/views/profile.html @@ -113,6 +113,4 @@ </tr> </tbody> </table> - </div> - </div> -</div> + </div> \ No newline at end of file diff --git a/views/scan.html b/views/scan.html index 53e22f1..4eb2162 100644 --- a/views/scan.html +++ b/views/scan.html @@ -15,6 +15,3 @@ <p>Scanned IP : {{ip_scanned}}</p> </div> </div> - </div> - </div> - diff --git a/views/settings.html b/views/settings.html index 6ab4301..bfcd86a 100644 --- a/views/settings.html +++ b/views/settings.html @@ -142,6 +142,4 @@ <button type="button" class="btn btn-primary">Save changes</button> </form> - </div> - </div> - </div> + </div> \ No newline at end of file -- 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 ebfe3a42c3930a3cf413c3b1051abf669536f774 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Tue Mar 17 10:36:39 2015 +0100 groups: les hôtes peuvent être ajoutés à un groupe --- README | 9 ++- app/module_loader.py | 2 +- app/modules/detection_modules/nmap_detection.py | 4 +- app/modules/notification_modules/email_notif.py | 29 ++++++++ app/modules/storage_modules/shelve_db.py | 28 +++++--- bootstrap.sh => install.sh | 0 static/js/controllers/groupCtrl.js | 89 ++++++++++++++++++++++--- views/groups.html | 31 ++++++++- views/hostpage.html | 3 +- 9 files changed, 162 insertions(+), 33 deletions(-) diff --git a/README b/README index b9a1583..8a983ae 100644 --- a/README +++ b/README @@ -24,10 +24,11 @@ apt-get install python2.7-dev You need also Virtualenv: sudo pip install virtualenv -Install python dependancies (needs Pip): -./bootstrap.sh +Run the install script (it will install python dependences by Pip, create the conf file and create the basic folders +in ~/.mum): +./install.sh -edit mum.conf +Edit mum.conf file if necessary Launch the server : ./run.sh @@ -40,8 +41,6 @@ Updates git pull -delete bower_components folder - bower install edit mum.conf diff --git a/app/module_loader.py b/app/module_loader.py index 7a7f494..7442759 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -110,7 +110,7 @@ class ModuleLoader: def run_all_detection_modules(self, addr_host): """ Instanciates and runs the run_detection() method from each detection modules loaded on loaded_mod_detect - :param + :param addr_host: the IP address of the host we want to run the detection """ db = self.get_db() conn = self.create_connection(addr_host) diff --git a/app/modules/detection_modules/nmap_detection.py b/app/modules/detection_modules/nmap_detection.py index 1d6d84c..279dee0 100644 --- a/app/modules/detection_modules/nmap_detection.py +++ b/app/modules/detection_modules/nmap_detection.py @@ -123,6 +123,7 @@ class nmap_detection: def parse_res(self, ip): # opening the xml file with minidom parser root = minidom.parse(self.filename) + pexpect.run("rm -f " + self.filename) collection = root.documentElement # get every <host> of the collection @@ -166,5 +167,4 @@ class nmap_detection: dict_host['openports'] = list_dict_port # the host have its IP for ID on the db self.db.add_host(dict_host['addr'], json.dumps(dict_host), self.list_mod_conn, self.dict_mod_monitoring) - self.scanned_ip.append(dict_host['addr']) - pexpect.run("rm -f " + self.filename) \ No newline at end of file + self.scanned_ip.append(dict_host['addr']) \ No newline at end of file diff --git a/app/modules/notification_modules/email_notif.py b/app/modules/notification_modules/email_notif.py new file mode 100644 index 0000000..826ae6a --- /dev/null +++ b/app/modules/notification_modules/email_notif.py @@ -0,0 +1,29 @@ +__author__ = 'aguilbaud' + +import smtplib +from email.mime.text import MIMEText + + +def get_class_name(): + return "EMail" + + +class EMail: + def __init__(self, msg, params): + self.msg = msg + self.params = params + self.parameters = {"users": "dict", "smtp_server": "string"} # dict = {user: {'username': val, 'email'; val}} + + def get_parameters(self): + return self.parameters + + def notify(self): + for user in self.params["users"]: + msg_to_send = MIMEText(self.msg) + msg_to_send['Subject'] = self.params["users"][user]['subject'] + msg_to_send['From'] = "mum@mum.com" + msg_to_send['To'] = self.params["users"][user]['email'] + + s = smtplib.SMTP(self.params['smtp_server']) + s.sendmail(msg_to_send['From'], [msg_to_send['To']], msg_to_send.as_string()) + s.quit() \ 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 d03b7c3..fffe6c8 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -499,7 +499,7 @@ class shelve_db: try: for mod_name in args['activated']: # first case : the monitoring module have never been activated for this host - if not mod_name in self.db["hosts"][addr_host]["conf"]["monitoring"]: + if mod_name not in self.db["hosts"][addr_host]["conf"]["monitoring"]: self.db["hosts"][addr_host]["conf"]["monitoring"][mod_name] = {} self.generate_unique_conf(dict_mod_info, addr_host, mod_name, args['activated'][mod_name]) elif not self.db["hosts"][addr_host]["conf"]["monitoring"][mod_name]["activated"] == \ @@ -522,7 +522,7 @@ class shelve_db: finally: self.close_db() - def get_conf_mod(self, args):#, mod_name): + def get_conf_mod(self, args): """ Returns a structure containing informations about the settings of a monitoring module. :param args: a list containing the arguments : @@ -609,12 +609,12 @@ class shelve_db: 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: @@ -639,12 +639,12 @@ class shelve_db: :param val: the value observed """ self.open_db() - new_val = {"date": str(datetime.now()), "value" : val} + 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 isinstance(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 @@ -710,12 +710,17 @@ class shelve_db: stats['M2'] += stats['delta'] * (val - stats['mean']) return stats - def add_host_list_to_group(self, host_list, group): + def add_host_list_to_group(self, args): """ Add given hosts to a group. If the group doesn't exists on the database, it will be created. - :param host_list: a list of IP adresses - :param group: the name of the group + :param args: a dictionary containing : + { + 'host_list': val, # a list of IP adresses + 'group'; val # the group name + } """ + group = args['group'] + host_list = args['host_list'] self.open_db() try: # if the group is not registered, we create it @@ -724,8 +729,9 @@ class shelve_db: self.db['groups'][group]['hosts'] = [] self.db['groups'][group]['subscribers'] = [] for host in host_list: - self.db['groups'][group].append(host) - self.db['hosts'][host]['conf']['groups'].append(group) + if group not in self.db['hosts'][host]['conf']['groups']: + self.db['groups'][group]['hosts'].append(host) + self.db['hosts'][host]['conf']['groups'].append(group) finally: self.close_db() diff --git a/bootstrap.sh b/install.sh similarity index 100% rename from bootstrap.sh rename to install.sh diff --git a/static/js/controllers/groupCtrl.js b/static/js/controllers/groupCtrl.js index ea4a1d3..449cc10 100644 --- a/static/js/controllers/groupCtrl.js +++ b/static/js/controllers/groupCtrl.js @@ -1,20 +1,41 @@ -mumApp.controller('groupCtrl', function($scope, $filter, $routeParams, DataHosts){ +mumApp.controller('groupCtrl', function($scope, $filter, $routeParams, $modal, DataHosts){ $scope.sort = { sortingOrder : 'id', reverse : false }; - $scope.items = DataHosts.Items; - - $scope.$on("hostsUpdate", function (event) { - $scope.items = DataHosts.Items; - }); + $scope.items = DataHosts.Items; /* [ + { + "addr":"192.168.74.1", + "name":"www.example.com", + "status":val, //"success" or "warning" or "danger" or "" + "group":[ // at least 1 group "all" + { + "name":"all" + }, + { + "name":"mygroup1" + } + ], + "last_check":val //UNIX time + "subscribers":{ + "uid":val, + "priority":val + } + "warning": [mod_name, ...] + "danger": [mod_name, ...] + }, + ... + ] + */ $scope.group_filter = ''; - $scope.selection = { - host_addrs : {} - }; + $scope.selection = {}; // {addr_host: bool, ...} + + for(i = 0 ; i < $scope.items.length ; i++){ + $scope.selection[$scope.items[i]['addr']] = false; + } $scope.status = ''; @@ -53,4 +74,54 @@ mumApp.controller('groupCtrl', function($scope, $filter, $routeParams, DataHosts item.Selected = $scope.selectedAll; }); }; + + $scope.open_modal_group = function () { + var modalInstance = $modal.open({ + templateUrl: 'modal_group_label.html', + controller: 'ModalGroupInstanceCtrl', + resolve: { + group_args: function(){ + var selected = []; + for(host in $scope.selection){ + if($scope.selection[host]){ + selected[selected.length] = host + } + } + return {"selected": selected, + "groups": $scope.allGroups()}; + } + } + }); + }; +}); + +mumApp.controller('ModalGroupInstanceCtrl', function ($scope, $rootScope, $route, $modalInstance, group_args) { + $scope.group_args = group_args; /* { + 'selected' : tab_val, + 'groups': val + } */ + + $scope.new_grp_name = ""; + $scope.selected_grp = "all"; + + $scope.ok = function () { + var args = {}; + args['host_list'] = $scope.group_args['selected']; + if($scope.new_grp_name == ""){ + args['group'] = $scope.selected_grp; + } + else{ + args['group'] = $scope.new_grp_name; + } + + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'add_host_list_to_group','args': args}})); + + $modalInstance.close(); + + $route.reload(); + }; + + $scope.cancel = function () { + $modalInstance.close(); + }; }); \ No newline at end of file diff --git a/views/groups.html b/views/groups.html index 153b3ff..763d555 100644 --- a/views/groups.html +++ b/views/groups.html @@ -17,6 +17,7 @@ <label for="name_f">Name filter</label> <input class="form-control" type="text" id="name_f" ng-model="name_filter"> </div> + {{selection}} <table class="table table-striped table-hover"> <thead> <tr> @@ -32,17 +33,40 @@ <td>{{item.name}}</td> <td>{{getGroupsByAddr(item.addr)}}</td> <td> - <input type="checkbox" ng-model="item.Selected" id="{{item.addr}}"/> + <input type="checkbox" ng-model="selection[item.addr]"/> </td> </tr> </tbody> </table> - <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modal_add">Add selected to group...</button> + <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modal_add" ng-click="open_modal_group()">Add selected to group...</button> <button ng-show="grp != 'all' || ''" type="button" class="btn btn-danger">Remove selected from {{grp}}</button> + </div> </div> - </div> + <script type="text/ng-template" id="modal_group_label.html"> + <div class="modal-header"> + <h3 class="modal-title">Add to group</h3> + </div> + <div class="modal-body"> + {{group_args}} + <form> + <div class="form-group"> + <label for="list_grp">From an existing group</label> + <select class="form-control" id="list_grp" ng-model="selected_grp" ng-options= + "item for item in group_args.groups | unique:'group'"> + </select> + <label for="grp_name">Or create a new group</label> + <input type="text" class="form-control" id="grp_name" ng-model="new_grp_name"> + </div> + </form> + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="cancel()">Close</button> + <button type="button" class="btn btn-primary" ng-click="ok()">Save changes</button> + </div> + </script> +<!-- <div class="modal fade" id="modal_add" tabindex="-1" role="dialog" aria-labelledby="modal_add_label" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> @@ -70,3 +94,4 @@ </div> </div> </div> +--> \ No newline at end of file diff --git a/views/hostpage.html b/views/hostpage.html index e89aea9..15848fc 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -264,7 +264,7 @@ <button type="button" class="btn btn-primary" ng-click="ok()">Save changes</button> </div> </script> - + </div> <!-- <div class="modal fade bs-example-modal-lg" id="modal_conf_conn" tabindex="-1" role="dialog" aria-labelledby="modal_conf_conn_label" aria-hidden="true"> <div class="modal-dialog modal-lg"> @@ -397,4 +397,3 @@ </div> </div> --> - </div> \ No newline at end of file -- 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 131a4f4e743ca31961f89f673810b44a5b787880 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Tue Mar 17 13:44:43 2015 +0100 groups: les hôtes peuvent être retirés d'un groupe + changement du res de get_host() concernant les groupes => pb du filtre des groupes résolu --- app/modules/storage_modules/shelve_db.py | 22 +++++------ static/js/controllers/groupCtrl.js | 65 ++++++++++++++++++++------------ views/groups.html | 10 ++--- 3 files changed, 54 insertions(+), 43 deletions(-) diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index fffe6c8..4522c9a 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -284,14 +284,7 @@ class shelve_db: "addr":"192.168.74.1", "name":"www.example.com", "status":val, //"success" or "warning" or "danger" or "" - "group":[ // at least 1 group "all" - { - "name":"all" - }, - { - "name":"mygroup1" - } - ], + "group":[ "all", ...], "last_check":val //UNIX time "subscribers":{ "uid":val, @@ -322,7 +315,7 @@ class shelve_db: info_host["status"] = "" info_host["group"] = [] for group in self.db["hosts"][host]["conf"]["groups"]: - info_host["group"].append({"name": group}) + info_host["group"].append(group) if "date" in self.db["hosts"][host]["status"]: info_host["last_check"] = self.db["hosts"][host]["status"]["date"] else: @@ -735,12 +728,17 @@ class shelve_db: finally: self.close_db() - def remove_host_list_to_group(self, host_list, group): + def remove_host_list_to_group(self, args): """ Remove given hosts to a group. If the group is empty afterwards, il will be also deleted. - :param host_list: a list of IP adresses - :param group: the name of the group + :param args: a dictionary containing : + { + 'host_list': val, # a list of IP adresses + 'group'; val # the group name + } """ + group = args['group'] + host_list = args['host_list'] self.open_db() try: for host in host_list: diff --git a/static/js/controllers/groupCtrl.js b/static/js/controllers/groupCtrl.js index 449cc10..b9bb876 100644 --- a/static/js/controllers/groupCtrl.js +++ b/static/js/controllers/groupCtrl.js @@ -1,4 +1,4 @@ -mumApp.controller('groupCtrl', function($scope, $filter, $routeParams, $modal, DataHosts){ +mumApp.controller('groupCtrl', function($scope, $rootScope, $filter, $route, $routeParams, $modal, DataHosts){ $scope.sort = { sortingOrder : 'id', reverse : false @@ -9,14 +9,7 @@ mumApp.controller('groupCtrl', function($scope, $filter, $routeParams, $modal, D "addr":"192.168.74.1", "name":"www.example.com", "status":val, //"success" or "warning" or "danger" or "" - "group":[ // at least 1 group "all" - { - "name":"all" - }, - { - "name":"mygroup1" - } - ], + "group":[ "all", ...], "last_check":val //UNIX time "subscribers":{ "uid":val, @@ -31,6 +24,8 @@ mumApp.controller('groupCtrl', function($scope, $filter, $routeParams, $modal, D $scope.group_filter = ''; + $scope.selectedAll = false; + $scope.selection = {}; // {addr_host: bool, ...} for(i = 0 ; i < $scope.items.length ; i++){ @@ -42,12 +37,10 @@ mumApp.controller('groupCtrl', function($scope, $filter, $routeParams, $modal, D $scope.grp = "all"; $scope.getGroupsByAddr = function(addr) { - res = "" + res = ""; for(var i = 0; i<$scope.items.length; i++){ if($scope.items[i].addr === addr){ - for(var j = 0; j<$scope.items[i].group.length; j++){ - res += $scope.items[i].group[j].name + " "; - } + res = $scope.items[i]['group'] } } return res; @@ -57,24 +50,46 @@ mumApp.controller('groupCtrl', function($scope, $filter, $routeParams, $modal, D var res = [] for(var i = 0; i<$scope.items.length; i++){ for(var j = 0; j<$scope.items[i].group.length; j++){ - res.push($scope.items[i].group[j].name); + res.push($scope.items[i].group[j]); } } return res; }; - $scope.checkAll = function(){ - if($scope.selectedAll){ - $scope.selectedAll = true; - } - else{ - $scope.selectedAll = false; - } - angular.forEach($scope.items, function(item){ - item.Selected = $scope.selectedAll; - }); + $scope.change_group_displayed = function(){ + $scope.checkAll(false); + $scope.selection = {}; + for(i = 0 ; i < $scope.items.length ; i++){ + for(j = 0 ; j < $scope.items[i]['group'].length ; j++){ + if($scope.grp == $scope.items[i]['group'][j]){ + $scope.selection[$scope.items[i]['addr']] = false; + } + } + } + } + + $scope.checkAll = function(bool){ + $scope.selectedAll = bool; + for(host in $scope.selection){ + $scope.selection[host] = bool; + } }; + $scope.remove_host_list = function(){ + var args = {}; + args['host_list'] = []; + for(host in $scope.selection){ + if($scope.selection[host]){ + args['host_list'][args['host_list'].length] = host; + } + } + args['group'] = $scope.grp; + + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'remove_host_list_to_group','args': args}})); + + $route.reload(); + } + $scope.open_modal_group = function () { var modalInstance = $modal.open({ templateUrl: 'modal_group_label.html', @@ -84,7 +99,7 @@ mumApp.controller('groupCtrl', function($scope, $filter, $routeParams, $modal, D var selected = []; for(host in $scope.selection){ if($scope.selection[host]){ - selected[selected.length] = host + selected[selected.length] = host; } } return {"selected": selected, diff --git a/views/groups.html b/views/groups.html index 763d555..1be9016 100644 --- a/views/groups.html +++ b/views/groups.html @@ -5,7 +5,7 @@ <div class="col-xs-3"> <label for="grpoption">Your existing groups</label> <form class="form-inline" id="grpoption"> - <select class="form-control" ng-model="grp" ng-options="item for item in allGroups() | unique:'group'"> + <select class="form-control" ng-change="change_group_displayed()" ng-model="grp" ng-options="item for item in allGroups() | unique:'group'"> </select> </form> </div> @@ -17,18 +17,17 @@ <label for="name_f">Name filter</label> <input class="form-control" type="text" id="name_f" ng-model="name_filter"> </div> - {{selection}} <table class="table table-striped table-hover"> <thead> <tr> <th>Address</th> <th>Name</th> <th>Groups</th> - <th><input type="checkbox" ng-model="selectedAll" ng-click="checkAll()"></th> + <th><input type="checkbox" ng-model="selectedAll" ng-click="checkAll(!selectedAll)"></th> </tr> </thead> <tbody> - <tr ng-repeat="item in items | filter:{addr:addr_filter, name:name_filter}"> <!-- group:{name:grp} --> + <tr ng-repeat="item in items | filter:{addr:addr_filter, name:name_filter, group:grp}"> <!-- group:{name:grp} --> <td>{{item.addr}}</td> <td>{{item.name}}</td> <td>{{getGroupsByAddr(item.addr)}}</td> @@ -39,7 +38,7 @@ </tbody> </table> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modal_add" ng-click="open_modal_group()">Add selected to group...</button> - <button ng-show="grp != 'all' || ''" type="button" class="btn btn-danger">Remove selected from {{grp}}</button> + <button ng-show="grp != 'all' || ''" type="button" class="btn btn-danger" ng-click="remove_host_list()">Remove selected from {{grp}}</button> </div> </div> @@ -48,7 +47,6 @@ <h3 class="modal-title">Add to group</h3> </div> <div class="modal-body"> - {{group_args}} <form> <div class="form-group"> <label for="list_grp">From an existing group</label> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm