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 0a179b45441193164623b26cb50f60e760228717 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Apr 15 14:54:47 2015 +0200 hostapege: change the hostname (function called have been changed for every nmap attributes) + snmp connection module added --- app/modules/connection_modules/snmp.py | 61 ++++++++++++++++++++++++++++++++ app/modules/storage_modules/shelve_db.py | 9 ++--- requirements.txt | 1 + static/js/controllers/hostPageCtrl.js | 8 +++-- views/hostpage.html | 9 ++++- 5 files changed, 80 insertions(+), 8 deletions(-) diff --git a/app/modules/connection_modules/snmp.py b/app/modules/connection_modules/snmp.py new file mode 100644 index 0000000..2541f62 --- /dev/null +++ b/app/modules/connection_modules/snmp.py @@ -0,0 +1,61 @@ +__author__ = 'aguilbaud' + +from pysnmp.entity.rfc3413.oneliner import cmdgen + +def get_class_name(): + return "SNMP" + + +class SNMP: + def __init__(self, addr_host, params, key_loc, cnfe): + self.parameters = {"port": "int"} + self.name = get_class_name() + self.addr_host = addr_host + self.known_port = 161 + self.CommandNotFoundException = cnfe + self.cmdGen = cmdgen.CommandGenerator() + + def get_name(self): + return self.name + + def get_addr_host(self): + # Called by monitoring modules + return self.addr_host + + def get_parameters(self): + return self.parameters + + def get_known_port(self): + return self.known_port + + def exec_command(self, cmd): + res = "" + errorIndication, errorStatus, errorIndex, varBinds = self.cmdGen.getCmd( + cmdgen.CommunityData('public'), + cmdgen.UdpTransportTarget((self.addr_host, self.parameters['port'])), + cmd + ) + + # Check for errors and print out results + if errorIndication: + print(errorIndication) + else: + if errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1] or '?' + ) + ) + else: + for name, val in varBinds: + if val == "": + exception_inst = getattr(self.CommandNotFoundException, "CommandNotFoundException")( + cmd, self.addr_host + ) + raise exception_inst + else: + res = val + return res + + def disconnect(self): + self.cmdGen = None \ 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 4afe0f7..b1cfa7f 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -455,20 +455,21 @@ class shelve_db: finally: self.close_db() - def update_os_name(self, args): + def update_nmap_attribute(self, args): """ Called from the hostpage. - Updatdes the operating system detected with nmap for a given host. The os name is saved in lower case. + Updatdes an attribute detected by nmap for a given host. :param args: a dictionary containing : { + 'attribute': string, 'addr_host': string, - 'new_os_name': string + 'new_value': string } """ self.open_db() try: nmap_detection = json.loads(self.db['hosts'][args['addr_host']]['detected']['nmap']) - nmap_detection['os'] = args['new_os_name'].lower() + nmap_detection[args['attribute']] = args['new_value'].lower() self.db['hosts'][args['addr_host']]['detected']['nmap'] = json.dumps(nmap_detection) except Exception: print traceback.format_exc() diff --git a/requirements.txt b/requirements.txt index 3cef053..fb039e1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ bottle==0.12.7 +pysnmp pexpect paramiko bottle-websocket diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index 6dcf145..2717d01 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -44,11 +44,12 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar } } */ - $scope.update_os_name = function(){ + $scope.update_nmap_attribute = function(attribute, new_value){ var args = {}; + args['attribute'] = attribute; args['addr_host'] = $scope.addr_host; - args['new_os_name'] = $scope.model.new_os; - $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'update_os_name', 'args': args}})); + args['new_value'] = new_value; + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'update_nmap_attribute', 'args': args}})); }; $scope.get_unit = function(mod_name){ @@ -70,6 +71,7 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar $scope.model = {custom_infos : '', new_os : '', + new_hostname : '', compatible_os_list: []}; $scope.check = function(modname){ diff --git a/views/hostpage.html b/views/hostpage.html index 8bda3e6..269e193 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -49,9 +49,16 @@ ng-options="os for os in model.compatible_os_list"> </select> <button type="button" class="btn btn-info btn-xs" - ng-click="update_os_name()" + ng-click="update_nmap_attribute('os', model.new_os)" ng-disabled="model.new_os==''">Correct OS name</button> </td> + <td ng-show="(key == 'hostname')"> + <input type="text" + ng-model="model.new_hostname"/> + <button type="button" class="btn btn-info btn-xs" + ng-click="update_nmap_attribute('hostname', model.new_hostname)" + ng-disabled="model.new_hostname==''">Correct hostname</button> + </td> </tr> </table> </accordion-group> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.