Example #1
0
def get_mactable(ver):
    """ Get the MAC Table from NetDB
    """

    error = version_chk(ver, ['v1.0', 'v2'])
    if error:
        return error

    switch = None
    port = '%'
    hours = 1

    if 'switch' in request.args:
        switch = request.args['switch']
        switch = switch.replace('*', '%')
    else:
        return jsonify(errors.json_error('InputError', 'switch= is required'))
    if 'port' in request.args:
        port = request.args['port']
        port = port.replace('*', '%')
        print("port", port)

    if 'hours' in request.args:
        hours = int(request.args['hours'])

    try:
        return jsonify(
            upgrade_api(
                nglib.netdb.switch.mac(switch=switch, port=port, hours=hours),
                ver))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #2
0
def get_arptable(ver):
    """ Get ARP Tables from NetDB
    """

    error = version_chk(ver, ['v1.0', 'v2'])
    if error:
        return error

    router = None
    hours = 1

    if 'router' in request.args:
        router = request.args['router']
        router = router.replace('*', '%')
    else:
        return jsonify(errors.json_error('InputError', 'router= is required'))

    if 'hours' in request.args:
        hours = int(request.args['hours'])

    try:
        return jsonify(
            upgrade_api(nglib.netdb.ip.arp(router=router, hours=hours), ver))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #3
0
def get_arptable(ver):
    """ Get ARP Tables from NetDB
    """

    error = version_chk(ver, ['v1.0', 'v2'])
    if error:
        return error

    router = None
    hours = 1

    if 'router' in request.args:
        router = request.args['router']
        router = router.replace('*', '%')
    else:
        return jsonify(errors.json_error('InputError', 'router= is required'))

    if 'hours' in request.args:
        hours = int(request.args['hours'])


    try:
        return jsonify(upgrade_api(nglib.netdb.ip.arp(router=router, hours=hours), ver))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #4
0
def get_mactable(ver):
    """ Get the MAC Table from NetDB
    """

    error = version_chk(ver, ['v1.0', 'v2'])
    if error:
        return error

    switch = None
    port = '%'
    hours = 1

    if 'switch' in request.args:
        switch = request.args['switch']
        switch = switch.replace('*', '%')
    else:
        return jsonify(errors.json_error('InputError', 'switch= is required'))
    if 'port' in request.args:
        port = request.args['port']
        port = port.replace('*', '%')
        print("port", port)

    if 'hours' in request.args:
        hours = int(request.args['hours'])

    try:
        return jsonify(upgrade_api(nglib.netdb.switch.mac(switch=switch, port=port, hours=hours), ver))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #5
0
def get_device_ints(device):
    """ Get specific device interfaces """

    if not nglib.netdb:
        return jsonify(errors.json_error('NetDB Error', \
            'NetDB Must be enabled to run this query'))

    try:
        return jsonify(nglib.netdb.switch.get_switch(device))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #6
0
def get_device_ints(ver, device):
    """ Get specific device interfaces """

    error = version_chk(ver)
    if error:
        return error

    if not nglib.netdb:
        return jsonify(errors.json_error('NetDB Error', \
            'NetDB Must be enabled to run this query'))

    try:
        return jsonify(upgrade_api(nglib.netdb.switch.get_switch(device), ver))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #7
0
def get_device(device):
    """ Get specific device reports """

    try:
        return jsonify(nglib.query.dev.get_device(device, rtype="NGTREE"))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #8
0
def get_device_nets(device):
    """ Get specific device networks """

    try:
        return jsonify(nglib.query.dev.get_networks(device))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #9
0
def get_devs(ver):
    """ Get Device Reports

        Notes: Truncates by default for speed
    """

    error = version_chk(ver)
    if error:
        return error

    search = '.*'
    group = '.*'
    trunc = True

    if 'search' in request.args:
        search = request.args['search']
    if 'group' in request.args:
        group = request.args['group']
    if 'full' in request.args:
        trunc = False

    try:
        return jsonify(upgrade_api(nglib.report.get_dev_report(dev=search, group=group, trunc=trunc), ver))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #10
0
def get_vid():
    allSwitches = True
    if 'allSwitches' in request.args and request.args['allSwitches'] == 'False':
        allSwitches = False
    try:
        return jsonify(nglib.query.vlan.search_vlan_id(request.args['id'], \
                    rtype="NGTREE", allSwitches=allSwitches))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #11
0
def get_vlan(vlan, ver):
    allSwitches = True

    if 'allSwitches' in request.args and request.args['allSwitches'] == 'False':
        allSwitches = False
    try:
        return jsonify(nglib.query.vlan.get_vlan(vlan, allSwitches=allSwitches, \
                    rtype="NGTREE"))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #12
0
def get_device_neighbors(ver, device):
    """ Get specific device neighbors """

    error = version_chk(ver)
    if error:
        return error

    try:
        return jsonify(upgrade_api(nglib.query.dev.get_neighbors(device), ver))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #13
0
def get_nets(ver):
    """
    /nets API method

    Options:
        none   - return a list of all networks
        ip     - find the cidr for an IP
        cidr   - filter networks by CIDR
        filter - filter networks by NetGrph filter (vrf:[role])
    """

    error = version_chk(ver)
    if error:
        return error

    cidr = None
    nFilter = 'all'

    if 'ip' in request.args:
        try:
            return jsonify(upgrade_api(nglib.query.net.get_net(request.args['ip'], rtype="NGTREE"), ver))
        except ResultError as e:
            return jsonify(errors.json_error(e.expression, e.message))
    elif 'cidr' in request.args:
        cidr = request.args['cidr']
        cidr = cidr.replace('-', '/')
        try:
            return jsonify(upgrade_api(nglib.query.net.get_networks_on_cidr(cidr, rtype="NGTREE"), ver))
        except ResultError as e:
            return jsonify(errors.json_error(e.expression, e.message))
        except ValueError as e:
            print(dir(e))
            return jsonify(errors.json_error('ValueError', str(e), code=400))
    else:
        if 'filter' in request.args:
            nFilter = request.args['filter']
        try:
            return jsonify(upgrade_api(nglib.query.net.get_networks_on_filter(nFilter=nFilter, rtype="NGTREE"), ver))
        except ResultError as e:
            return jsonify(errors.json_error(e.expression, e.message))
Example #14
0
def get_device(device, ver):
    """ Get specific device reports """

    error = version_chk(ver)
    if error:
        return error

    try:
        res = nglib.query.dev.get_device(device, rtype="NGTREE")

        return jsonify(upgrade_api(nglib.query.dev.get_device(device, rtype="NGTREE"), ver))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #15
0
def get_switched_path(ver):
    """ Switched Path """
    onepath = False
    depth = '20'
    if 'onepath' in request.args:
        if request.args['onepath'] == "True":
            onepath = True
    if 'depth' in request.args:
        depth = request.args['depth']
    try:
        return jsonify(nglib.query.path.get_switched_path(request.args['src'], \
            request.args['dst'], {"onepath": onepath, "depth": depth}))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #16
0
def get_vlan(vlan, ver):
    'Get individual vlan'
    allSwitches = True

    error = version_chk(ver)
    if error:
        return error

    if 'allSwitches' in request.args and request.args['allSwitches'] == 'False':
        allSwitches = False
    try:
        return jsonify(upgrade_api(nglib.query.vlan.get_vlan(vlan, allSwitches=allSwitches, \
                    rtype="NGTREE"), ver))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #17
0
def get_vlans(ver):
    allSwitches = True
    vrange = '1-4096'
    group = '.*'
    if 'allSwitches' in request.args and request.args['allSwitches'] == 'False':
        allSwitches = False
    if 'vrange' in request.args:
        vrange = request.args['vrange']
    if 'group' in request.args:
        group = request.args['group']

    try:
        return jsonify(nglib.report.get_vlan_report(vrange=vrange, group=group, \
                    rtype="NGTREE"))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #18
0
def get_mac_count(ver, switch):
    """ Get the MAC Table count from NetDB
    """

    error = version_chk(ver, ['v1.0', 'v2'])
    if error:
        return error

    hours = 1
    switch = switch.replace('*', '%')

    if 'hours' in request.args:
        hours = int(request.args['hours'])

    try:
        return jsonify(upgrade_api(nglib.netdb.switch.count(switch=switch, hours=hours), ver))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #19
0
def get_routed_path(ver):
    """ Routed Paths, accepts vrf """
    onepath = False
    depth = '20'
    vrf = 'default'

    if 'onepath' in request.args:
        if request.args['onepath'] == "True":
            onepath = True
    if 'depth' in request.args:
        depth = request.args['depth']
    if 'vrf' in request.args:
        vrf = request.args['vrf']
    try:
        return jsonify(nglib.query.path.get_routed_path(request.args['src'], \
            request.args['dst'], {"onepath": onepath, "depth": depth, \
            "VRF": vrf}))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #20
0
def get_switched_path(ver):
    """ Switched Path """

    error = version_chk(ver, ['v1.0', 'v1.1', 'v2'])
    if error:
        return error

    onepath = False
    depth = '20'
    if 'onepath' in request.args:
        if request.args['onepath'] == "True":
            onepath = True
    if 'depth' in request.args:
        depth = request.args['depth']
    try:
        return jsonify(upgrade_api(nglib.query.path.get_switched_path(request.args['src'], \
            request.args['dst'], {"onepath": onepath, "depth": depth}), ver))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #21
0
def get_mac_count(ver, switch):
    """ Get the MAC Table count from NetDB
    """

    error = version_chk(ver, ['v1.0', 'v2'])
    if error:
        return error

    hours = 1
    switch = switch.replace('*', '%')

    if 'hours' in request.args:
        hours = int(request.args['hours'])

    try:
        return jsonify(
            upgrade_api(nglib.netdb.switch.count(switch=switch, hours=hours),
                        ver))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #22
0
def get_vlans(ver):
    'L2 VLANs'

    error = version_chk(ver, ['v1.0', 'v1.1', 'v2'])
    if error:
        return error

    allSwitches = True
    vrange = '1-4096'
    group = '.*'
    if 'allSwitches' in request.args and request.args['allSwitches'] == 'False':
        allSwitches = False
    if 'vrange' in request.args:
        vrange = request.args['vrange']
    if 'group' in request.args:
        group = request.args['group']

    try:
        return jsonify(upgrade_api(nglib.report.get_vlan_report(vrange=vrange, group=group, \
                    rtype="NGTREE"), ver))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #23
0
def get_ip():

    try:
        return jsonify(nglib.query.net.get_net(request.args['ip'], rtype="NGTREE"))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #24
0
def get_dev():
    try:
        return jsonify(nglib.query.dev.get_device(request.args['dev'], rtype="NGTREE"))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #25
0
def get_vtree():
    try:
        return jsonify(nglib.query.vlan.get_vtree(request.args['name'], rtype="NGTREE"))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #26
0
def get_nfilter():
    """ Networks on a filter """
    try:
        return jsonify(nglib.query.net.get_networks_on_filter(nFilter=request.args['filter'], rtype="NGTREE"))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))
Example #27
0
def get_nlist():

    try:
        return jsonify(nglib.query.net.get_networks_on_filter(request.args['group'], rtype="NGTREE"))
    except ResultError as e:
        return jsonify(errors.json_error(e.expression, e.message))