示例#1
0
def run():
    logger = get_logger(logfile, "sanscript.fc")
    logger.info("START")

    dirpath = os.path.dirname(os.path.realpath(__file__))
    filepath = os.path.join(dirpath, "SwitchConnection.json")
    connections = load_data(filepath, [])

    for connection in connections:
        systemname = connection["name"]
        address = connection["address"]
        logger.info("Trying to connect to %s (SNMP)." % systemname)
        cmdGen = cmdgen.CommandGenerator()
        errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
            cmdgen.CommunityData("public", mpModel=0),
            cmdgen.UdpTransportTarget((address, 161)),
            cmdgen.MibVariable("SNMPv2-MIB", "sysName", 0),
            lookupNames=True,
            lookupValues=True,
        )
        if errorIndication:
            logger.warning(errorIndication)
        elif errorStatus:
            logger.warning(errorStatus)
        else:
            for name, val in varBinds:
                logger.info("%s = %s" % (name.prettyPrint(), val.prettyPrint()))
        if errorIndication or errorStatus:
            logger.warning("%s test failure." % systemname)
        else:
            logger.info("%s test successful." % systemname)
    logger.info("FINISH")
    return
示例#2
0
def run():
    logger = get_logger(logfile, 'sanscript.fc')

    connections = []
    dirpath = os.path.dirname(os.path.realpath(__file__))
    for filename in ['FabricConnection.json', 'SwitchConnection.json']:
        filepath = os.path.join(dirpath, filename)
        connections += load_data(filepath, [])

    for connection in connections:
        args = [connection[key] for key in ['name', 'address', 'username', 'password']]
        args.append([])
        system, outs, errs, exception = ssh_run(args)
        if exception:
            logger.warning('%s test failed - %s' %(system, exception))
        else:
            logger.info('%s test success' %system)