Exemplo n.º 1
0
def snmpcli(argv):
    """snmpcli [-h] [-p <port>] [-s <scriptname>] [-m <module>] host community

Provides an interactive session to an SNMP agent.
    """
    port = 161
    sourcefile = None
    logfile = None
    modname = None
    try:
        optlist, longopts, args = getopt.getopt(argv[1:], "hl:p:s:m:")
    except getopt.GetoptError:
        print(snmpcli.__doc__)
        return
    for opt, val in optlist:
        if opt == "-s":
            sourcefile = val
        elif opt == "-l":
            logfile = val
        elif opt == "-h":
            print(snmpcli.__doc__)
            return
        elif opt == "-p":
            try:
                port = int(val)
            except ValueError:
                print(snmpcli.__doc__)
                return
        elif opt == "-m":
            modname = val

    if not args:
        print(snmpcli.__doc__)
        return

    host = args[0]
    if len(args) > 1:
        community = args[1]
    else:
        community = "public"

    if modname:
        module = __import__(modname, globals(), locals(), ["*"])
        manager = module.get_manager(host, community)
    else:
        manager = Manager.get_manager(host, community, mibs=[SNMPv2_MIB, IF_MIB])

    parser = CLI.get_generic_cli(
        manager, SNMPManagerCommands, logfile=logfile, historyfile=os.path.expandvars("$HOME/.hist_snmpcli")
    )

    if sourcefile:
        try:
            parser.parse(sourcefile)
        except CLI.CommandQuit:
            pass
    else:
        parser.interact()
Exemplo n.º 2
0
def get_manager(device, community):
    return Manager.get_manager(device, community, LinuxManager, MIBNAMES)
Exemplo n.º 3
0
def snmpcli(argv):
    """snmpcli [-h] [-p <port>] [-s <scriptname>] [-m <module>] host community

Provides an interactive session to an SNMP agent.
    """
    port = 161
    sourcefile = None
    logfile = None
    modname = None
    try:
        optlist, longopts, args = getopt.getopt(argv[1:], "hl:p:s:m:")
    except getopt.GetoptError:
        print(snmpcli.__doc__)
        return
    for opt, val in optlist:
        if opt == "-s":
            sourcefile = val
        elif opt == "-l":
            logfile = val
        elif opt == "-h":
            print(snmpcli.__doc__)
            return
        elif opt == "-p":
            try:
                port = int(val)
            except ValueError:
                print(snmpcli.__doc__)
                return
        elif opt == "-m":
            modname = val

    if not args:
        print(snmpcli.__doc__)
        return

    host = args[0]
    if len(args) > 1:
        community = args[1]
    else:
        community = "public"

    if modname:
        module = __import__(modname, globals(), locals(), ["*"])
        manager = module.get_manager(host, community)
    else:
        manager = Manager.get_manager(host,
                                      community,
                                      mibs=[SNMPv2_MIB, IF_MIB])

    parser = CLI.get_generic_cli(
        manager,
        SNMPManagerCommands,
        logfile=logfile,
        historyfile=os.path.expandvars("$HOME/.hist_snmpcli"))

    if sourcefile:
        try:
            parser.parse(sourcefile)
        except CLI.CommandQuit:
            pass
    else:
        parser.interact()
Exemplo n.º 4
0
def get_manager(device, community):
    return Manager.get_manager(device, community, APCManager, MIBS)
Exemplo n.º 5
0
def _test(argv):
    device = argv[1]
    community = "Private" if len(argv) < 2 else argv[2]
    mgr = Manager.get_manager(device, community)
    print(mgr.get_outlets())
Exemplo n.º 6
0
def get_manager(device, community):
    mgr = Manager.get_manager(device, community, Sentry3Manager)
    mgr.add_mib(SNMPv2_MIB)
    mgr.add_mib(Sentry3_MIB, subclassmodule=sys.modules[__name__])
    return mgr
Exemplo n.º 7
0
def get_manager(device, community):
    return Manager.get_manager(device, community, ExtremeManager, MIBS)
Exemplo n.º 8
0
def get_manager(device, community):
    return Manager.get_manager(device, community, BridgeManager, MIBS)
Exemplo n.º 9
0
def get_manager(device, community):
    return Manager.get_manager(device, community, APCManager, MIBS)
Exemplo n.º 10
0
def get_manager(device, community):
    return Manager.get_manager(device, community, LinuxManager, MIBNAMES)
Exemplo n.º 11
0
def get_manager(device, community):
    return Manager.get_manager(device, community, ExtremeManager, MIBS)
Exemplo n.º 12
0
def get_manager(device, community):
    return Manager.get_manager(device, community, BridgeManager, MIBS)
Exemplo n.º 13
0
def get_manager(device, community):
    return Manager.get_manager(device, community, C3560Manager, MIBNAMES)
Exemplo n.º 14
0
def _test(argv):
    device = argv[1]
    community = "Private" if len(argv) < 2 else argv[2]
    mgr = Manager.get_manager(device, community)
    print(mgr.get_outlets())
Exemplo n.º 15
0
def get_manager(device, community):
    mgr = Manager.get_manager(device, community, Sentry3Manager)
    mgr.add_mib(SNMPv2_MIB)
    mgr.add_mib(Sentry3_MIB, subclassmodule=sys.modules[__name__])
    return mgr
Exemplo n.º 16
0
def get_manager(device, community):
    return Manager.get_manager(device, community, C3560Manager, MIBNAMES)