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 419b9f75b2c2a84c5a91dae8e02490170e376241 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Mar 2 17:16:25 2015 +0100 hostpage : bilan des check => OK --- app/app.py | 3 +- app/modules/storage_modules/shelve_db.py | 38 +++++++++++-------- static/js/controllers/headCtrl.js | 25 ++----------- static/js/controllers/hostPageCtrl.js | 14 +++++++ static/js/controllers/scanCtrl.js | 7 +++- static/js/mumApp.js | 2 +- views/hostpage.html | 63 ++++++-------------------------- views/index.html | 1 + 8 files changed, 60 insertions(+), 93 deletions(-) diff --git a/app/app.py b/app/app.py index 7805908..8745224 100755 --- a/app/app.py +++ b/app/app.py @@ -141,12 +141,11 @@ def receive(ws): start_first_detection(msg[NMAP_SCAN_DEMAND], ws) elif code == GET_HOSTS_DEMAND: db = module_loader.load_db() - hosts= db.get_hosts() ws.send(json.dumps({GET_HOSTS_RESPONSE: db.get_hosts()})) del db elif code == HOST_INFO_DEMAND: db = module_loader.load_db() - ws.send(json.dumps({INFO_HOST: db.get_host_inoformations(msg[HOST_INFO_DEMAND])})) + ws.send(json.dumps({INFO_HOST: db.get_host_informations(msg[HOST_INFO_DEMAND])})) del db else: break diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 7644003..19120e3 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -265,44 +265,50 @@ class shelve_db: self.close_db() return json.dumps(res) - def get_host_inoformations(self, addr_host): + def get_host_informations(self, addr_host): """ 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 : { - addr_host:{ - 'monitoring':{ - mod_name:{ - 'state':val, - 'value':val, - 'unit':val, - 'last_check':date - } + 'host_name': val, + 'monitoring':{ + mod_name:{ + 'state':val, + 'value':val, + 'unit':val, + 'last_check':date } - 'detection':{ - mod_name:res - } - 'custom_info';val - 'interventions':list } + 'detection':{ + mod_name:res + } + 'custom_info';val + 'interventions':list } """ self.open_db() res = {} try: + res_nmap = json.loads(self.db['hosts'][addr_host]['detected']['nmap']) + if 'hostname' in res_nmap: + res['hostname'] = json.loads(self.db['hosts'][addr_host]['detected']['nmap'])['hostname'] + else: + res['hostname'] = '' res['monitoring'] = {} for mod in self.db['hosts'][addr_host]['monitoring']: - print mod res['monitoring'][mod] = self.db['hosts'][addr_host]['monitoring'][mod] + res['monitoring'][mod]['name'] = mod res['detected'] = {} for mod in self.db['hosts'][addr_host]['detected']: res['detected'][mod] = json.loads(self.db['hosts'][addr_host]['detected'][mod]) res['custom_info'] = self.db['hosts'][addr_host]['conf']['custom_info'] res['interventions'] = self.db['hosts'][addr_host]['conf']['interventions'] + except Exception as e: + print e.__str__() finally: self.close_db() - return json.dumps({addr_host: res}) + return json.dumps(res) def remove_host(self, addr_host): diff --git a/static/js/controllers/headCtrl.js b/static/js/controllers/headCtrl.js index d5da7ee..8366485 100644 --- a/static/js/controllers/headCtrl.js +++ b/static/js/controllers/headCtrl.js @@ -9,13 +9,6 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r $scope.items = DataHosts.Items; }); - // Concerning the hostpage - $scope.host_informations = null; - $scope.get_host_informations = function(addr_host){ - var request = '{"13" : "'+ addr_host + '"}'; - ws.send(request); - } - // Concerning WebSocket var ws = new WebSocket("ws://" + $location.host() + ":1337/websocket"); @@ -34,17 +27,11 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r JSON.parse(evt.data, function (key, value) { switch(parseInt(key)){ case 20: // Success of a module execution - $scope.$apply(function(){ - $scope.state = "Success!"; - $scope.ip_scanned = value; - }); + $rootScope.$broadcast("success", value); toastr.success(value, "Success on module execution"); - /*case 21: // Informations concerning one host - $scope.$apply(function(){ - DataHosts.Items = JSON.parse(value); - alert(value); - }); - break;*/ + case 21: // Informations concerning one host + $rootScope.$broadcast("hostInfos", JSON.parse(value)); + break; case 22: // List of hosts under monitoring DataHosts.Items = JSON.parse(value); $rootScope.$broadcast("hostsUpdate"); @@ -97,10 +84,6 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r toastr.error(msg, title); }; - - - - /* * Return a vector with the number of hosts with a status of : success, warning, danger */ diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js new file mode 100644 index 0000000..8d9bd9c --- /dev/null +++ b/static/js/controllers/hostPageCtrl.js @@ -0,0 +1,14 @@ +mumApp.controller('hostPageCtrl', function($scope, $rootScope, $routeParams, DataHosts) { + $scope.host_informations = null; + + $scope.addr_host = $routeParams.param + $rootScope.$broadcast("sendViaWs", JSON.stringify({"13": $routeParams.param})); + + $scope.items = []; + + $scope.$on("hostInfos", function (event, args) { + $scope.$apply(function(){ + $scope.items = args; + }); + }); +}); \ No newline at end of file diff --git a/static/js/controllers/scanCtrl.js b/static/js/controllers/scanCtrl.js index 3f40afd..63ecab5 100644 --- a/static/js/controllers/scanCtrl.js +++ b/static/js/controllers/scanCtrl.js @@ -2,6 +2,12 @@ mumApp.controller('scanCtrl', function($scope, $rootScope) { // Concerning the scan form $scope.ip_range = "" // la plage d'ip entree dans le champ $scope.state = ""; // l'etat general du scan en cours + $scope.ip_scanned = {}; + + $scope.$on("success", function (event, args) { + $scope.state = "Success!"; + $scope.ip_scanned = args; + }); $scope.$on("stateUpdate", function (event, args) { $scope.state = args; @@ -9,7 +15,6 @@ mumApp.controller('scanCtrl', function($scope, $rootScope) { $scope.validated = false; // pour afficher ou non certaines parties de la page $scope.scan_is_over = false; // pour afficher ou non certaines parties de la page - $scope.ip_scanned = {}; $scope.post_val = function(){ //lace la detection apres remplissage du champ et validation du formulaire $rootScope.$broadcast("sendViaWs", JSON.stringify({"10": $scope.ip_range})); diff --git a/static/js/mumApp.js b/static/js/mumApp.js index 8edd37c..e4dfd70 100644 --- a/static/js/mumApp.js +++ b/static/js/mumApp.js @@ -24,7 +24,7 @@ mumApp.config(function($routeProvider){ }) .when('/hostpage/:param',{ templateUrl : 'hostpage.html', - //controller : 'mainController' + controller : 'hostPageCtrl' }) .when('/notifications',{ templateUrl : 'notifications.html', diff --git a/views/hostpage.html b/views/hostpage.html index f25aec8..709acea 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -1,6 +1,6 @@ <div class="col-md-offset-2 main"> - <h1 class="page-header">Current state of {{param}} <small>www.example.com</small></h1> + <h1 class="page-header">Current state of {{addr_host}} <small>{{items.hostname}}</small></h1> <button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_block">Activate/Deactivate</button> <button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_conn">Connection settings</button> <button type="button" class="btn btn-info btn-xs">Launch a new detection</button> @@ -10,60 +10,19 @@ <thead> <tr> - <th class="id" custom-sort order="'addr'" sort="sort">Part </th> - <th class="name" custom-sort order="'name'" sort="sort">Value </th> - <th class="description" custom-sort order="'status'" sort="sort">State </th> - <th class="field3" custom-sort order="'group'" sort="sort">Last check </th> + <th>Part </th> + <th>Value </th> + <th>State </th> + <th>Last check </th> </tr> </thead> + <tbody> - <tr class=success> - <td>HTTP</td> - <td>up</td> - <td>success</td> - <td>12:00</td> - <td><button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_conf"> - Configure - </button> - </td> - <td><button type="button" class="btn btn-info btn-xs"> - Check now - </button> - </td> - </tr> - <tr class=success> - <td>SMTP</td> - <td>up</td> - <td>success</td> - <td>12:04</td> - <td><button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_conf"> - Configure - </button> - </td> - <td><button type="button" class="btn btn-info btn-xs"> - Check now - </button> - </td> - </tr> - <tr class=success> - <td>CPU</td> - <td>28%</td> - <td>success</td> - <td>14:51</td> - <td><button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_conf"> - Configure - </button> - </td> - <td><button type="button" class="btn btn-info btn-xs"> - Check now - </button> - </td> - </tr> - <tr class=success> - <td>Drive</td> - <td>37% used</td> - <td>success</td> - <td>14:51</td> + <tr ng-repeat="item in items.monitoring" class={{item.state}}> + <td>{{item.name}}</td> + <td>{{item.value}}</td> + <td>{{item.state}}</td> + <td>{{item.date}}</td> <td><button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_conf"> Configure </button> diff --git a/views/index.html b/views/index.html index 36429c1..56cec09 100644 --- a/views/index.html +++ b/views/index.html @@ -25,6 +25,7 @@ <script src="static/js/controllers/dashboardCtrl.js"></script> <script src="static/js/controllers/headCtrl.js"></script> <script src="static/js/controllers/scanCtrl.js"></script> + <script src="static/js/controllers/hostPageCtrl.js"></script> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]><!-- -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.