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>.