예제 #1
0
파일: autoscan.py 프로젝트: smagowr/ralph
def _autoscan_address(address):
    """Autoscans a single address on the worker."""

    try:
        ipaddress = IPAddress.objects.get(address=address)
    except IPAddress.DoesNotExist:
        ipaddress = None
    if ipaddress and ipaddress.is_buried:
        return
    pinged = ping(address)
    if pinged:
        if not ipaddress:
            ipaddress, created = IPAddress.objects.get_or_create(
                address=address, )
        ipaddress.http_family = get_http_family(ipaddress.address)
        (
            ipaddress.snmp_name,
            ipaddress.snmp_community,
            ipaddress.snmp_version,
        ) = get_snmp(ipaddress)
        ipaddress.dead_ping_count = 0
        ipaddress.save(update_last_seen=True)
    else:
        if ipaddress:
            ipaddress.http_family = None
            ipaddress.snmp_name = None
            ipaddress.snmp_community = None
            ipaddress.snmp_version = None
            ipaddress.dead_ping_count += 1
            ipaddress.save(update_last_seen=False)
예제 #2
0
파일: autoscan.py 프로젝트: fossabot/ralph
def _autoscan_address(address):
    """Autoscans a single address on the worker."""

    try:
        ipaddress = IPAddress.objects.get(address=unicode(address))
    except IPAddress.DoesNotExist:
        ipaddress = None
    if ipaddress and ipaddress.is_buried:
        return
    pinged = ping(address)
    if pinged:
        if not ipaddress:
            ipaddress, created = IPAddress.objects.get_or_create(
                address=unicode(address),
            )
        ipaddress.http_family = get_http_family(ipaddress.address)
        (
            ipaddress.snmp_name,
            ipaddress.snmp_community,
            ipaddress.snmp_version,
        ) = get_snmp(ipaddress)
        ipaddress.dead_ping_count = 0
        ipaddress.save(update_last_seen=True)
    else:
        if ipaddress:
            ipaddress.dead_ping_count += 1
            if ipaddress.dead_ping_count >= settings.DEAD_PING_COUNT:
                # remove previous values only if this IP address already died
                ipaddress.http_family = None
                ipaddress.snmp_name = None
                ipaddress.snmp_community = None
                ipaddress.snmp_version = None
            ipaddress.save(update_last_seen=False)
예제 #3
0
파일: autoscan.py 프로젝트: quamilek/ralph
def _autoscan_address(address):
    """Autoscans a single address on the worker."""

    try:
        ipaddress = IPAddress.objects.get(address=address)
    except IPAddress.DoesNotExist:
        ipaddress = None
    if ipaddress and ipaddress.is_buried:
        return
    pinged = ping(address)
    if pinged:
        if not ipaddress:
            ipaddress, created = IPAddress.objects.get_or_create(address=address)
        ipaddress.http_family = get_http_family(ipaddress.address)
        (ipaddress.snmp_name, ipaddress.snmp_community, ipaddress.snmp_version) = get_snmp(ipaddress)
        ipaddress.dead_ping_count = 0
        ipaddress.save(update_last_seen=True)
    else:
        if ipaddress:
            ipaddress.http_family = None
            ipaddress.snmp_name = None
            ipaddress.snmp_community = None
            ipaddress.snmp_version = None
            ipaddress.dead_ping_count += 1
            ipaddress.save(update_last_seen=False)
예제 #4
0
파일: tests.py 프로젝트: damjanek/ralph
 def test_ping(self):
     from ralph.util.network import ping
     # existing domain; big timeout for running tests through GPRS
     msg = textwrap.dedent("""
         {} is not pingable from Python. Things you might want to check:
         * are you connected to the Internet
         * is this domain pingable from your terminal
         * is your python binary capped with setcap CAP_NET_RAW
           or
         * are you running tests from root
           or
         * are you using setuid bin/python""".format(
         EXISTING_DOMAIN)).strip()
     self.assertIsNotNone(ping(EXISTING_DOMAIN, 2), msg)
     self.assertTrue(ping(EXISTING_DOMAIN, 2) > 0)
     # non-existent domain
     self.assertIsNone(ping(NON_EXISTENT_DOMAIN))
     # non-pingable host
     self.assertIsNone(ping(NON_EXISTENT_HOST_IP))
예제 #5
0
파일: tests.py 프로젝트: pombreda/ralph
 def test_ping(self):
     from ralph.util.network import ping
     # existing domain; big timeout for running tests through GPRS
     msg = textwrap.dedent("""
         {} is not pingable from Python. Things you might want to check:
         * are you connected to the Internet
         * is this domain pingable from your terminal
         * is your python binary capped with setcap CAP_NET_RAW
           or
         * are you running tests from root
           or
         * are you using setuid bin/python""".format(
         EXISTING_DOMAIN)).strip()
     self.assertIsNotNone(ping(EXISTING_DOMAIN, 2), msg)
     self.assertTrue(ping(EXISTING_DOMAIN, 2) > 0)
     # non-existent domain
     self.assertIsNone(ping(NON_EXISTENT_DOMAIN))
     # non-pingable host
     self.assertIsNone(ping(NON_EXISTENT_HOST_IP))
예제 #6
0
def ping(**kwargs):
    ip = kwargs['ip']
    is_up = False
    if network.ping(str(ip)) is None:
        message = 'down.'
    else:
        is_up = True
        message = 'up!'
        ip_address, created = IPAddress.concurrent_get_or_create(address=str(ip))
        hostname = network.hostname(ip)
        if hostname:
            ip_address.hostname = hostname
            ip_address.dns_info = '\n'.join(network.descriptions(hostname))
        kwargs['community'] = ip_address.snmp_community
        ip_address.save(update_last_seen=True)
    return is_up, message, kwargs
예제 #7
0
def ping(**kwargs):
    ip = kwargs['ip']
    is_up = False
    if network.ping(str(ip)) is None:
        message = 'down.'
    else:
        is_up = True
        message = 'up!'
        ip_address, created = IPAddress.concurrent_get_or_create(
            address=str(ip))
        hostname = network.hostname(ip)
        if hostname:
            ip_address.hostname = hostname
            ip_address.dns_info = '\n'.join(network.descriptions(hostname))
        kwargs['community'] = ip_address.snmp_community
        ip_address.save(update_last_seen=True)
    return is_up, message, kwargs
예제 #8
0
파일: tasks.py 프로젝트: szaydel/ralph
def sanity_check(perform_network_checks=True):
    """Checks configuration integrity by pinging www.allegro.pl."""
    if not perform_network_checks:
        return

    if ping(SANITY_CHECK_PING_ADDRESS) is None:
        raise ImproperlyConfigured(textwrap.dedent("""
            fatal: {} is not pingable.

            Things you might want to check:
             * is this host connected to network
             * is this domain pingable from your terminal
             * is your python binary capped with setcap CAP_NET_RAW
               or
             * are you running tests from root
               or
             * are you using setuid bin/python""").strip().format(
                 SANITY_CHECK_PING_ADDRESS))
예제 #9
0
def sanity_check(perform_network_checks=True):
    """Checks configuration integrity by pinging www.allegro.pl."""
    if not perform_network_checks:
        return

    if ping(SANITY_CHECK_PING_ADDRESS) is None:
        raise ImproperlyConfigured(textwrap.dedent("""
            fatal: {} is not pingable.

            Things you might want to check:
             * is this host connected to network
             * is this domain pingable from your terminal
             * is your python binary capped with setcap CAP_NET_RAW
               or
             * are you running tests from root
               or
             * are you using setuid bin/python""").strip().format(
                 SANITY_CHECK_PING_ADDRESS))