예제 #1
0
def scan_address(address, plugins):
    """Queue manual discovery on the specified address."""

    try:
        network = Network.from_ip(address)
    except IndexError:
        raise NoQueueError(
            "Address {0} doesn't belong to any configured "
            "network.".format(address), )
    if not network.queue:
        raise NoQueueError(
            "The network {0} has no discovery queue.".format(network), )
    ipaddress, created = IPAddress.objects.get_or_create(address=address)
    queue_name = network.queue.name
    queue = django_rq.get_queue(queue_name)
    job = queue.enqueue_call(
        func=_scan_address,
        args=(
            address,
            plugins,
        ),
        kwargs={
            'snmp_community': ipaddress.snmp_community,
            'snmp_version': ipaddress.snmp_version,
            'http_family': ipaddress.http_family,
            'snmp_name': ipaddress.snmp_name,
        },
        timeout=60,
        result_ttl=3600,
    )
    return job
예제 #2
0
def scan_environment(environment, plugins, automerge=AUTOMERGE_MODE):
    """Queue scan of all scannable networks in the environment."""

    if not environment.queue:
        raise NoQueueError(
            "Evironment {0} does not have configured queue.".format(
                environment,
            ),
        )
    ip_numbers = set()
    for min_ip_num, max_ip_num in environment.network_set.values_list(
        'min_ip', 'max_ip',
    ).order_by('-min_ip', 'max_ip'):
        ip_numbers |= set(range(min_ip_num, max_ip_num + 1))
    range_start = 0
    for ip_number in sorted(ip_numbers):
        if range_start == 0:
            range_start = ip_number
        if ip_number + 1 in ip_numbers:
            continue
        scan_ip_addresses_range(
            range_start,
            ip_number,
            plugins,
            queue_name=environment.queue.name,
            automerge=automerge,
        )
        range_start = 0
예제 #3
0
파일: autoscan.py 프로젝트: fossabot/ralph
def autoscan_environment(environment):
    """Queues a pre-scan of all scannable networks in the environment."""

    if not environment.queue:
        raise NoQueueError(
            "No discovery queue defined for environment {0}.".format(
                environment,
            ),
        )
    ip_numbers = set()
    for network in environment.network_set.all().order_by(
        '-min_ip', 'max_ip',
    ):
        ip_numbers |= set(range(network.min_ip, network.max_ip + 1))
        network.last_scan = datetime.datetime.now()
        network.save()
    range_start = 0
    for ip_number in sorted(ip_numbers):
        if range_start == 0:
            range_start = ip_number
        if ip_number + 1 in ip_numbers:
            continue
        autoscan_ip_addresses_range(
            range_start,
            ip_number,
            queue_name=environment.queue.name
        )
        range_start = 0
예제 #4
0
def scan_address(
    ip_address, plugins, queue_name=None, automerge=AUTOMERGE_MODE,
    called_from_ui=False,
):
    """Queue scan on the specified address."""

    if not queue_name:
        try:
            network = Network.from_ip(ip_address)
        except IndexError:
            raise NoQueueError(
                "Address {0} doesn't belong to any configured "
                "network.".format(ip_address),
            )
        else:
            if network.environment and network.environment.queue:
                queue_name = network.environment.queue.name
            else:
                raise NoQueueError(
                    "The IP address {0} has no discovery queue. "
                    "Set the queue in the environments admin panel.".format(
                        ip_address,
                    ),
                )
    if all((
        called_from_ui,
        '%s_%s' % (UI_CALLS_QUEUE_PREFIX, queue_name) in RQ_QUEUES_LIST
    )):
        queue_name = '%s_%s' % (UI_CALLS_QUEUE_PREFIX, queue_name)
    queue = django_rq.get_queue(queue_name)
    job = queue.enqueue_call(
        func=scan_address_job,
        args=(
            ip_address,
            plugins,
        ),
        kwargs={
            'automerge': automerge,
        },
        timeout=300,
        result_ttl=86400,
    )
    return job
예제 #5
0
파일: autoscan.py 프로젝트: smagowr/ralph
def autoscan_address(address):
    """Queues a scan of a single address on the right worker."""

    try:
        network = Network.from_ip(address)
    except IndexError:
        raise NoQueueError(
            "Address {0} doesn't belong to any configured "
            "network.".format(address), )
    if not network.queue:
        raise NoQueueError(
            "The network {0} has no discovery queue.".format(network), )
    queue_name = network.queue.name
    queue = django_rq.get_queue(queue_name)
    queue.enqueue_call(
        func=_autoscan_group,
        args=([address], ),
        timeout=60,
        result_ttl=0,
    )
예제 #6
0
파일: autoscan.py 프로젝트: smagowr/ralph
def autoscan_network(network):
    """Queues a scan of a whole network on the right worker."""

    if not network.queue:
        raise NoQueueError(
            "No discovery queue defined for network {0}.".format(network), )
    queue_name = network.queue.name
    queue = django_rq.get_queue(queue_name)
    for group in _split_into_groups(
            network.network.iterhosts(),
            ADDRESS_GROUP_SIZE,
    ):
        queue.enqueue_call(
            func=_autoscan_group,
            args=(group, ),
            timeout=60,
            result_ttl=0,
        )
    network.last_scan = datetime.datetime.now()
    network.save()