Adding support for multiple instances
This commit is contained in:
parent
976e45d082
commit
ae7e0ba61e
2 changed files with 50 additions and 28 deletions
31
client.py
31
client.py
|
@ -7,9 +7,13 @@ import argparse
|
||||||
with open("config.yml", "r") as ymlfile:
|
with open("config.yml", "r") as ymlfile:
|
||||||
cfg = yaml.load(ymlfile)
|
cfg = yaml.load(ymlfile)
|
||||||
|
|
||||||
def call_api(path):
|
def call_api(params, path):
|
||||||
url = '/'.join((cfg['base_url'],cfg['api_path'],path))
|
url = '/'.join((params['base_url'],params['api_path'],path))
|
||||||
response = requests.get(url, auth=(cfg['username'], cfg['password']))
|
try:
|
||||||
|
response = requests.get(url, auth=(params['username'], params['password']))
|
||||||
|
except:
|
||||||
|
return
|
||||||
|
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
def print_data(key, value, suffix = None):
|
def print_data(key, value, suffix = None):
|
||||||
|
@ -18,21 +22,32 @@ def print_data(key, value, suffix = None):
|
||||||
else:
|
else:
|
||||||
print "%-20s %s" % (key, value)
|
print "%-20s %s" % (key, value)
|
||||||
|
|
||||||
|
# Test instances
|
||||||
|
for instance in cfg['instances'].keys():
|
||||||
|
test = call_api(cfg['instances'][instance], 'devices')
|
||||||
|
if test is None:
|
||||||
|
print "Instance %s is not working, disabling" % instance
|
||||||
|
cfg['instances'].pop(instance)
|
||||||
|
else:
|
||||||
|
print "Instance %s is working" % instance
|
||||||
|
|
||||||
def search_ports(args):
|
def search_ports(args):
|
||||||
data = call_api('ports/?ifAlias=%s' % args.string)
|
for instance, params in cfg['instances'].iteritems():
|
||||||
|
data = call_api(params, 'ports/?ifAlias=%s' % args.string)
|
||||||
|
|
||||||
if data['count'] < 1:
|
if data['count'] < 1:
|
||||||
print "No port found matching description %s" % args.string
|
print "No port found for description %s on instance %s" \
|
||||||
|
% (args.string, instance)
|
||||||
return
|
return
|
||||||
|
|
||||||
for port in data['ports'].itervalues():
|
for port in data['ports'].itervalues():
|
||||||
print "=" * 80
|
print "=" * 80
|
||||||
device = call_api('devices/%s' % port['device_id'])
|
device = call_api(params, 'devices/%s' % port['device_id'])
|
||||||
print_data("Device", device['device']['hostname'])
|
print_data("Device", device['device']['hostname'])
|
||||||
print_data("", "%s/device/device=%s" % (cfg['base_url'], port['device_id']))
|
print_data("", "%s/device/device=%s" % (params['base_url'], port['device_id']))
|
||||||
print_data("Port", port['port_label_short'])
|
print_data("Port", port['port_label_short'])
|
||||||
print_data("", "%s/device/device=%s/tab=port/port=%s/" %
|
print_data("", "%s/device/device=%s/tab=port/port=%s/" %
|
||||||
(cfg['base_url'], port['device_id'], port['port_id']))
|
(params['base_url'], port['device_id'], port['port_id']))
|
||||||
print_data("Description", port['ifAlias'])
|
print_data("Description", port['ifAlias'])
|
||||||
print_data("Port status", "%s (Admin) / %s (Oper)" % (port['ifAdminStatus'], port['ifOperStatus']))
|
print_data("Port status", "%s (Admin) / %s (Oper)" % (port['ifAdminStatus'], port['ifOperStatus']))
|
||||||
print_data("Last flap", port['ifLastChange'])
|
print_data("Last flap", port['ifLastChange'])
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
|
instances:
|
||||||
|
luxnetwork:
|
||||||
base_url: 'https://noc1.luxnetwork.eu'
|
base_url: 'https://noc1.luxnetwork.eu'
|
||||||
api_path: 'api/v0'
|
api_path: 'api/v0'
|
||||||
username: ''
|
username: ''
|
||||||
password: ''
|
password: ''
|
||||||
|
tlpo:
|
||||||
|
base_url: 'http://observium2.tl-noc.com'
|
||||||
|
api_path: 'api/v0'
|
||||||
|
username: ''
|
||||||
|
password: ''
|
||||||
|
|
Loading…
Reference in a new issue