def interrogate(args): db = get_db(args) hostname = args.hostname[0] authinfo = db.authinfo.find_one({"name": hostname}) if authinfo is None: authinfo = {"name": hostname} default = db.authinfo.find_one({"name": "default"}) if default is None: authinfo = {} descriptions = {} if args.snmp: for community in authinfo.get("community", []) + default.get("community", []): log.info("querying with SNMP community: %s" % community) try: from snmp import interrogate_snmp descriptions["snmp"] = interrogate_snmp(hostname, community=community) authinfo["community"] = [community] break except: pass if args.login: for u,p in authinfo.get("login", []) + default.get("login", []): log.info("logging in as user: %s" % u) try: from rlogin import interrogate_rlogin descriptions["login"] = interrogate_rlogin(host=hostname, username=u, password=p) authinfo["login"] = [(u,p)] break except: pass db.authinfo.save(authinfo) try: ident = pkey_check(descriptions) except PKeyError, e: log.warning("%s\n%s" % (e, format_exc(e))) return
from snmp import interrogate_snmp from rlogin import interrogate_rlogin from traceback import format_exc log = __import__("logging").getLogger(__name__) __all__ = ['interrogate'] def interrogate(host, **kw): result = {} try: result["snmp"] = interrogate_snmp(host, **kw) except Exception, e: log.warning(str(e) + "\n" + format_exc()) try: result["rlogin"] = interrogate_rlogin(host, **kw) except Exception, e: log.warning(str(e) + "\n" + format_exc()) return result