Can you pull network status information from the Softlayer API? -


we interested in using api information found on network > status > local page.

does api allow this?

thank you

yes possible, there no single api call returns result. need routers in account.

here code (it using python client)

""" network status local  script displays same information https://control.softlayer.com/network/status/local page.  important manual pages https://sldn.softlayer.com/reference/services/softlayer_account/ https://sldn.softlayer.com/reference/services/softlayer_account/getobject https://sldn.softlayer.com/reference/datatypes/softlayer_hardware """ import softlayer import json   def getracks(networkhardware, routerstatus):     """retrieves racks information.        :param softlayer_hardware networkhardware: network hardware downstream.        :param softlayer_hardware routerstatus: routers in account contains network incidents.     """     racks = []     if 'downstreamnetworkhardware' in networkhardware:         network in networkhardware['downstreamnetworkhardware']:             rack = {}             if 'cs' in network['hostname']:                 rack['name'] = network['hostname'] + '.' + network['domain']                 rack['type'] = network['hardwarechassis']['hardwarefunction']['code']                 rack['status'] = getaggregationrackstatus(network, routerstatus)                 racks.append(rack)     return racks   def getaggregationrackstatus(networkhardware, routerstatus):     """retrieves status racks , aggregation hardware.        :param softlayer_hardware networkhardware: network hardware downstream.        :param softlayer_hardware routerstatus: routers in account contains network incidents.     """     if 'downstreamnetworkhardwarewithincidents' in routerstatus:         incident in routerstatus['downstreamnetworkhardwarewithincidents']:             if incident['hostname'] == networkhardware['hostname']:                 return incident['networkstatus']     else:         return routerstatus['networkstatus']   def getaggregation(router, routerstatus):     """retrieves racks information.        :param softlayer_hardware router: router hardware.        :param softlayer_hardware routerstatus: routers in account contains network incidents.     """     aggregations = []     if 'downstreamnetworkhardware' in router:         networkhardware in router['downstreamnetworkhardware']:             aggregation= {}             if 'as' in networkhardware['hostname']:                 aggregation['name'] = networkhardware['hostname'] + '.' + networkhardware['domain']                 aggregation['type'] = networkhardware['hardwarechassis']['hardwarefunction']['code']                 aggregation['status'] = getaggregationrackstatus(networkhardware, routerstatus)                 aggregation['rack'] = getracks(networkhardware, routerstatus)                 aggregations.append(aggregation)     return aggregations   username = 'set me' api_key = 'set me'  # declares api client client = softlayer.client() accountservice = client['softlayer_account']  objectmask = "mask[id,routers[id,hardwarechassis[manufacturer,name,hardwarefunction[code,description]],hostname,domain,networkstatus,networkmonitorattacheddownvirtualguestcount,networkmonitorattacheddownhardwarecount,downstreamnetworkhardware[downstreamnetworkhardware,hostname,domain,hardwarechassis[manufacturer,name,hardwarefunction[code,description]]]]]" objectmaskstatus = "mask[networkmonitordownvirtualguestcount,networkmonitordownhardwarecount,routers[downstreamnetworkhardwarewithincidents[hardwarechassis[hardwarefunction], networkstatus]]]"  try:     response = accountservice.getobject(mask=objectmask)     responsestatus = accountservice.getobject(mask=objectmask) except softlayer.softlayerapierror e:     print("unable account. faultcode=%s, faultstring=%s" % (e.faultcode, e.faultstring))   routers = [] in range(0, len(response['routers'])):     router = response['routers'][i]     routerstatus = responsestatus['routers'][i]     device = {}     device['name'] = router['hostname'] + "." + router['domain']     device['type'] = router['hardwarechassis']['hardwarefunction']['code']     device['status'] = router['networkstatus']     device['aggregation'] = getaggregation(router, routerstatus)     device['routerstatus'] = routerstatus['id']     device['id'] = router['id']     routers.append(device)  print(json.dumps(routers, sort_keys=true, indent=2, separators=(',', ': '))) 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -