Exemplo n.º 1
0
parent = args.parent
search = args.search
match = args.match
country = args.country
tenantgroup = args.tenantgroup
tenant = args.tenant
output = args.output
host = args.host
port = args.port

netbox = NetboxAPI()
netbox.conn(host, port)

if match:
    netbox.search(match_type='match',
                  match=match,
                  parent=parent,
                  search=search)
else:
    netbox.search(match_type='all', match=match, parent=parent, search=search)
netbox.output(output)
#netbox.save_dashboard(output, es_server, es_port)

#netbox.parse_prefixes()

#test = NetboxAPI()
#test.parse_prefixes()
# print(test.get_nb_api('prefix'))

#netbox.parse_prefixes()
#print(json.dumps(netbox.get_nb_api('prefix', args.tenantgroup), indent=4, sort_keys=True))
#prefix = netbox.get_nb_api('prefix', 'all')
    netbox_options['match'] = match

if role:
    netbox_options['role'] = role

sync = False
try:
    sync = os.getenv('SYNC')
    if sync == 0:
        print('sync off!')
        sync = True
except:
    pass

#######
netbox.search(**netbox_options)
n = netbox.output()

####################
# db output
if output == 'db':
    from netboxapi import ElsSaveMap
    es = ElsSaveMap(index, index_type)

    if search_type == 'dashboard':
        getattr(es, save_es)(n)
    else:
        pipeline(n)
    ### if !sites and db here ... sys.exit(0)
    #if netbox_options['search'] != 'site':
    #print('''\nWarning ...