def test_snmp_g01(self): """ snmp_g01 """ if "json" == ml_system.CFG_TYPE: shutil.copyfile(os.path.join("unittest", "snmp-g01.json"), os.path.join("running", "snmp.txt")) if "jcfg" == ml_system.CFG_TYPE: shutil.copyfile(os.path.join("unittest", "snmp-g01.jcfg"), os.path.join("running", "snmp.txt")) if "pickle" == ml_system.CFG_TYPE: return self.maxDiff = None e = ml_w_snmp.get(None, threading.RLock()) self.assertEqual(e, (True, { "enable": True, "community": "public", "system_name": "SLB", "system_contact": "info <*****@*****.**>", "system_location": "4F, 102 Guangfu S. Road, Daan District, Taipei 10612, Taiwan" }))
def snmp(self, **kwargs): ''' snmp setting data format from middleware (True, {'system_name': 'SLB', 'system_contact': '', 'enable': False, 'system_loca tion': '', 'community': 'public'}) ''' import libs.login if False == libs.login.cklogin(): raise _.HTTPRedirect('/') import ml_w_snmp as snmp import json import libs.tools _.response.headers["Content-Type"] = "application/json" if 'system_name' in kwargs: # for updating setting libs.tools.v(kwargs) res = {'system_name': libs.tools.convert(kwargs['system_name']), 'system_contact': libs.tools.convert(kwargs['system_contact']), 'enable': 'enable' in kwargs, 'system_location': libs.tools.convert(kwargs['system_location']), 'community': libs.tools.convert(kwargs['community'])} libs.tools.v(res) res = snmp.set(user = self.getUser(), cfg = res) if False == res[0]: return json.dumps([res[0], libs.tools.translateMessage(res[1])]) else: return json.dumps(res) else: # for information getter return json.dumps(snmp.get())