Beispiel #1
0
def get_snmp(ipaddress):
    community = ipaddress.snmp_community
    version = ipaddress.snmp_version or '2c'
    oid = (1, 3, 6, 1, 2, 1, 1, 1, 0)  # sysDesc
    http_family = ipaddress.http_family
    message = None
    # Windows hosts always say that the port is closed, even when it's open
    if http_family not in ('Microsoft-IIS', 'Unspecified', 'RomPager'):
        if not check_snmp_port(ipaddress.address):
            return None, None, None
    if http_family == 'HP':
        version = '1'
        oid = (1, 3, 6, 1, 4, 1, 2, 3, 51, 2, 2, 21, 1, 1, 5, 0)
        # bladeCenterManufacturingId
    if http_family == 'RomPager':
        version = '1'
    if version != '3':
        # Don't try SNMP v2 if v3 worked on this host.
        communities = list(SNMP_COMMUNITIES)
        if community:
            if community in communities:
                communities.remove(community)
            communities.insert(0, community)
        for community in communities:
            message = _snmp(
                ipaddress.address,
                community,
                oid,
                attempts=2,
                timeout=0.2,
                snmp_version=version,
            )
            if message == '' and version != '1':
                # prevent empty response for some communities.
                version = '1'
                message = _snmp(
                    ipaddress.address,
                    community,
                    oid,
                    attempts=2,
                    timeout=0.2,
                    snmp_version=version,
                )
            if message:
                return message, community, version
    if SNMP_V3_AUTH:
        version = '3'
        message = _snmp(
            ipaddress.address,
            SNMP_V3_AUTH,
            oid,
            attempts=2,
            timeout=2,  # SNMP v3 usually needs more time
            snmp_version=version,
        )
    if not message:
        return None, None, None
    return message, community, version
Beispiel #2
0
def get_snmp(ipaddress):
    community = ipaddress.snmp_community
    version = ipaddress.snmp_version or '2c'
    oid = (1, 3, 6, 1, 2, 1, 1, 1, 0)  # sysDesc
    http_family = ipaddress.http_family
    message = None
    # Windows hosts always say that the port is closed, even when it's open
    if http_family not in ('Microsoft-IIS', 'Unspecified', 'RomPager'):
        if not check_snmp_port(ipaddress.address):
            return None, None, None
    if http_family == 'HP':
        version = '1'
        oid = (1, 3, 6, 1, 4, 1, 2, 3, 51, 2, 2, 21, 1, 1, 5, 0)
        # bladeCenterManufacturingId
    if http_family == 'RomPager':
        version = '1'
    if version != '3':
        # Don't try SNMP v2 if v3 worked on this host.
        communities = list(SNMP_COMMUNITIES)
        if community:
            if community in communities:
                communities.remove(community)
            communities.insert(0, community)
        for community in communities:
            message = _snmp(
                ipaddress.address,
                community,
                oid,
                attempts=2,
                timeout=0.2,
                snmp_version=version,
            )
            if message == '' and version != '1':
                # prevent empty response for some communities.
                version = '1'
                message = _snmp(
                    ipaddress.address,
                    community,
                    oid,
                    attempts=2,
                    timeout=0.2,
                    snmp_version=version,
                )
            if message:
                return message, community, version
    if SNMP_V3_AUTH and version not in ('1', '2', '2c'):
        version = '3'
        message = _snmp(
            ipaddress.address,
            SNMP_V3_AUTH,
            oid,
            attempts=2,
            timeout=0.5,  # SNMP v3 usually needs more time
            snmp_version=version,
        )
    if not message:
        return None, None, None
    return message, community, version
Beispiel #3
0
def snmp(**kwargs):
    http_family = kwargs.get('http_family')
    if  http_family in ('Thomas-Krenn',):
        return False, 'no match.', kwargs
    ip = str(kwargs['ip'])
    if http_family not in ('Microsoft-IIS', 'Unspecified', 'RomPager'):
        # Windows hosts always say that the port is closed, even when it's open
        if not check_snmp_port(ip):
            return False, 'port closed.', kwargs
    community = kwargs.get('community')
    oids = [
        ('2c', (1,3,6,1,2,1,1,1,0)), # sysDescr
        # Blade centers answer only to their own OIDs and to SNMP version 1
        #  ('1', (1,3,6,1,4,1,2,3,51,2,2,21,1,1,5,0)),
        # bladeCenterManufacturingId
    ]
    if http_family in ('RomPager',):
        oids.append(('1', (1,3,6,1,2,1,1,1,0))) # sysDescr, snmp version 1
    communities = SNMP_PLUGIN_COMMUNITIES[:]
    if community:
        if community in communities:
            communities.remove(community)
        communities.insert(0, community)
    for community in communities:
        for ver, oid in oids:
            version = ver
            is_up, message = _snmp(ip, community, oid, attempts=2, timeout=0.2,
                                   snmp_version=ver)
            if message == '':
                is_up, message = _snmp(ip, community, oid, attempts=2, timeout=0.2,
                                   snmp_version='1')
                version = '1'
            if is_up:
                kwargs['community'] = community
                kwargs['snmp_version'] = version
                kwargs['snmp_name'] = message
                return is_up, message, kwargs
    return False, 'no answer.', kwargs
Beispiel #4
0
def snmp(**kwargs):
    http_family = kwargs.get('http_family')
    if  http_family in ('Thomas-Krenn',):
        return False, 'no match.', kwargs
    ip = str(kwargs['ip'])
    if http_family not in ('Microsoft-IIS', 'Unspecified', 'RomPager'):
        # Windows hosts always say that the port is closed, even when it's open
        if not check_snmp_port(ip):
            return False, 'port closed.', kwargs
    community = kwargs.get('community')
    oids = [
        ('2c', (1,3,6,1,2,1,1,1,0)), # sysDescr
        # Blade centers answer only to their own OIDs and to SNMP version 1
        #  ('1', (1,3,6,1,4,1,2,3,51,2,2,21,1,1,5,0)),
        # bladeCenterManufacturingId
    ]
    if http_family in ('RomPager',):
        oids.append(('1', (1,3,6,1,2,1,1,1,0))) # sysDescr, snmp version 1
    communities = SNMP_PLUGIN_COMMUNITIES[:]
    if community:
        if community in communities:
            communities.remove(community)
        communities.insert(0, community)
    for community in communities:
        for ver, oid in oids:
            version = ver
            is_up, message = _snmp(ip, community, oid, attempts=2, timeout=0.2,
                                   snmp_version=ver)
            if message == '':
                is_up, message = _snmp(ip, community, oid, attempts=2, timeout=0.2,
                                   snmp_version='1')
                version = '1'
            if is_up:
                kwargs['community'] = community
                kwargs['snmp_version'] = version
                kwargs['snmp_name'] = message
                return is_up, message, kwargs
    return False, 'no answer.', kwargs
Beispiel #5
0
def snmp(**kwargs):
    http_family = kwargs.get("http_family")
    if http_family in ("Thomas-Krenn",):
        return False, "no match.", kwargs
    ip = str(kwargs["ip"])
    if http_family not in ("Microsoft-IIS", "Unspecified", "RomPager"):
        # Windows hosts always say that the port is closed, even when it's open
        if not check_snmp_port(ip):
            return False, "port closed.", kwargs
    community = kwargs.get("community")
    oids = [
        ("2c", (1, 3, 6, 1, 2, 1, 1, 1, 0)),  # sysDescr
        # Blade centers answer only to their own OIDs and to SNMP version 1
        #  ('1', (1,3,6,1,4,1,2,3,51,2,2,21,1,1,5,0)),
        # bladeCenterManufacturingId
    ]
    if http_family in ("RomPager",):
        oids.append(("1", (1, 3, 6, 1, 2, 1, 1, 1, 0)))  # sysDescr, snmp version 1
    communities = SNMP_PLUGIN_COMMUNITIES[:]
    if community:
        if community in communities:
            communities.remove(community)
        communities.insert(0, community)
    for community in communities:
        for ver, oid in oids:
            version = ver
            is_up, message = _snmp(ip, community, oid, attempts=2, timeout=0.2, snmp_version=ver)
            if message == "":
                is_up, message = _snmp(ip, community, oid, attempts=2, timeout=0.2, snmp_version="1")
                version = "1"
            if is_up:
                kwargs["community"] = community
                kwargs["snmp_version"] = version
                kwargs["snmp_name"] = message
                return is_up, message, kwargs
    return False, "no answer.", kwargs
Beispiel #6
0
def snmp(**kwargs):
    http_family = kwargs.get('http_family')
    if  http_family in ('Thomas-Krenn',):
        return False, 'no match.', kwargs
    ip = str(kwargs['ip'])
    if http_family not in ('Microsoft-IIS', 'Unspecified', 'RomPager'):
        # Windows hosts always say that the port is closed, even when it's open
        if not check_snmp_port(ip):
            return False, 'port closed.', kwargs
    community = kwargs.get('community')
    version = kwargs.get('snmp_version')
    oids = [
        ('2c', (1,3,6,1,2,1,1,1,0)), # sysDescr
        # Blade centers answer only to their own OIDs and to SNMP version 1
        #  ('1', (1,3,6,1,4,1,2,3,51,2,2,21,1,1,5,0)),
        # bladeCenterManufacturingId
    ]
    if http_family in ('RomPager',):
        oids.append(('1', (1,3,6,1,2,1,1,1,0))) # sysDescr, snmp version 1
    if version != '3':
        # Don't try SNMP v2 if v3 worked on this host.
        communities = SNMP_PLUGIN_COMMUNITIES[:]
        if community:
            if community in communities:
                communities.remove(community)
            communities.insert(0, community)
        for community in communities:
            for ver, oid in oids:
                version = ver
                is_up, message = _snmp(
                    ip,
                    community,
                    oid,
                    attempts=2,
                    timeout=0.2,
                    snmp_version=version,
                )
                if message == '' and ver != '1':
                    version = '1'
                    is_up, message = _snmp(
                        ip,
                        community,
                        oid,
                        attempts=2,
                        timeout=0.2,
                        snmp_version=version,
                    )
                # prevent empty response for some communities.
                if message and is_up:
                    kwargs['community'] = community
                    kwargs['snmp_version'] = version
                    kwargs['snmp_name'] = message
                    return is_up, message, kwargs
    if SNMP_V3_AUTH and version not in ('1', '2', '2c'):
        is_up, message = _snmp(
            ip, SNMP_V3_AUTH,
            (1,3,6,1,2,1,1,1,0),
            attempts=2,
            timeout=0.5, # SNMP v3 usually needs more time
            snmp_version='3',
        )
        if is_up:
            kwargs['community'] = ''
            kwargs['snmp_version'] = '3'
            kwargs['snmp_name'] = message
            return is_up, message, kwargs
    kwargs['community'] = ''
    kwargs['snmp_version'] = ''
    return False, 'no answer.', kwargs
Beispiel #7
0
def snmp(**kwargs):
    http_family = kwargs.get('http_family')
    if http_family in ('Thomas-Krenn', ):
        return False, 'no match.', kwargs
    ip = str(kwargs['ip'])
    if http_family not in ('Microsoft-IIS', 'Unspecified', 'RomPager'):
        # Windows hosts always say that the port is closed, even when it's open
        if not check_snmp_port(ip):
            return False, 'port closed.', kwargs
    community = kwargs.get('community')
    version = kwargs.get('snmp_version')
    oids = [
        ('2c', (1, 3, 6, 1, 2, 1, 1, 1, 0)),  # sysDescr
        # Blade centers answer only to their own OIDs and to SNMP version 1
        #  ('1', (1,3,6,1,4,1,2,3,51,2,2,21,1,1,5,0)),
        # bladeCenterManufacturingId
    ]
    if http_family in ('RomPager', ):
        # sysDescr, snmp version 1
        oids.append(('1', (1, 3, 6, 1, 2, 1, 1, 1, 0)))
    if version != '3':
        # Don't try SNMP v2 if v3 worked on this host.
        communities = SNMP_PLUGIN_COMMUNITIES[:]
        if community:
            if community in communities:
                communities.remove(community)
            communities.insert(0, community)
        for community in communities:
            for ver, oid in oids:
                version = ver
                is_up, message = _snmp(
                    ip,
                    community,
                    oid,
                    attempts=2,
                    timeout=0.2,
                    snmp_version=version,
                )
                if message == '' and ver != '1':
                    version = '1'
                    is_up, message = _snmp(
                        ip,
                        community,
                        oid,
                        attempts=2,
                        timeout=0.2,
                        snmp_version=version,
                    )
                # prevent empty response for some communities.
                if message and is_up:
                    kwargs['community'] = community
                    kwargs['snmp_version'] = version
                    kwargs['snmp_name'] = message
                    return is_up, message, kwargs
    if SNMP_V3_AUTH and version not in ('1', '2', '2c'):
        is_up, message = _snmp(
            ip,
            SNMP_V3_AUTH,
            (1, 3, 6, 1, 2, 1, 1, 1, 0),
            attempts=2,
            timeout=0.5,  # SNMP v3 usually needs more time
            snmp_version='3',
        )
        if is_up:
            kwargs['community'] = ''
            kwargs['snmp_version'] = '3'
            kwargs['snmp_name'] = message
            return is_up, message, kwargs
    kwargs['community'] = ''
    kwargs['snmp_version'] = ''
    return False, 'no answer.', kwargs