def testapi3(): openapi = Ops.setup_api_opener_full(method="GET") data = openapi.open("https://210.245.0.176:5665/v1/objects/hosts/QBHP01201ES52").read() data = json.loads(data) data = data["results"][0] print data for each in data: if each != "attrs": print each +"="+ str(data[each]) else: for content in data[each]: print content + "="+ str(data[each][content])
def test_edit_host(data,location="Ha Noi",hosttype="Zyxel IES-5112M",zone="checker"): for each in data: province = each["KhuVuc"] ip = each["IP"] names = each["TenThietBi"] devicetype = each["DeviceType"] if province==location and devicetype==hosttype: result = Ops.icinga_edit_object_hosts(url="https://210.245.0.176:5665/v1/objects/hosts/", province=province, ip=ip, names=names, devicetype=devicetype,zone=zone) try: if result != str(-1): status = json.loads(result) status = status["results"][0]["status"] print names + "=" + status except: print names + " exists , cannot import"
#key = Ops.testapi2(url=options.host) def testapi3(): openapi = Ops.setup_api_opener_full(method="GET") data = openapi.open("https://210.245.0.176:5665/v1/objects/hosts/QBHP01201ES52").read() data = json.loads(data) data = data["results"][0] print data for each in data: if each != "attrs": print each +"="+ str(data[each]) else: for content in data[each]: print content + "="+ str(data[each][content]) # expose data from port.net # testapi3() data = Ops.read_portnet_api() # import HNI DSLAM to Icinga ( please check data from # test import #test2 = Ops.icinga_create_object_hosts(url="https://210.245.0.176:5665/v1/objects/hosts/", province="Ha Noi", ip="20.11.8.11", names="HNIB00101ES524", devicetype="Zyxel IES-5112M") #if test2 != -1: # print json.loads(test2)["results"][0]["status"] #else: # print "object exists" def test_create_host(data,location="Ha Noi",hosttype="Zyxel IES-5112M",zone="checker"): for each in data: province = each["KhuVuc"] ip = each["IP"] names = each["TenThietBi"] devicetype = each["DeviceType"] if province==location and devicetype==hosttype: