Skip to content

Commit

Permalink
Merge pull request #907 from xor-xor/ralph_1726
Browse files Browse the repository at this point in the history
Added autoscan (prescan) at the beginning of the manual scan.
  • Loading branch information
vi4m committed May 30, 2014
2 parents 4f43b41 + 50fdb9c commit 12a0505
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
33 changes: 17 additions & 16 deletions src/ralph/scan/autoscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,24 @@ def autoscan_ip_addresses_range(min_ip_number, max_ip_number, queue_name):
)


def autoscan_address(address):
"""Queues a scan of a single address on the right worker."""
def autoscan_address(address, queue_name=None):
"""Queues an autoscan 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.environment or not network.environment.queue:
raise NoQueueError(
"The network environment {0} has no discovery queue.".format(
network,
),
)
queue_name = network.environment.queue.name
if not queue_name:
try:
network = Network.from_ip(address)
except IndexError:
raise NoQueueError(
"Address {0} doesn't belong to any configured "
"network.".format(address),
)
if not network.environment or not network.environment.queue:
raise NoQueueError(
"The network environment {0} has no discovery queue.".format(
network,
),
)
queue_name = network.environment.queue.name
queue = django_rq.get_queue(queue_name)
queue.enqueue_call(
func=_autoscan_group,
Expand Down
19 changes: 11 additions & 8 deletions src/ralph/scan/manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from ralph.discovery.models import IPAddress, Network
from ralph.scan.automerger import save_job_results
from ralph.scan.autoscan import autoscan_address
from ralph.scan.errors import NoQueueError
from ralph.scan.models import ScanSummary

Expand All @@ -42,7 +43,7 @@ def scan_address(
ip_address, plugins, queue_name=None, automerge=AUTOMERGE_MODE,
called_from_ui=False,
):
"""Queue scan on the specified address."""
"""Queues a scan of the specified address."""

if not queue_name:
try:
Expand All @@ -62,6 +63,13 @@ def scan_address(
ip_address,
),
)
try:
ip_address_from_db = IPAddress.objects.get(address=unicode(ip_address))
except IPAddress.DoesNotExist:
ip_address_from_db = None
if not ip_address_from_db or not (ip_address_from_db.snmp_name and
ip_address_from_db.snmp_community):
autoscan_address(ip_address, queue_name=queue_name)
if all((
called_from_ui,
'%s_%s' % (UI_CALLS_QUEUE_PREFIX, queue_name) in RQ_QUEUES_LIST
Expand All @@ -70,13 +78,8 @@ def scan_address(
queue = django_rq.get_queue(queue_name)
job = queue.enqueue_call(
func=scan_address_job,
args=(
ip_address,
plugins,
),
kwargs={
'automerge': automerge,
},
args=(ip_address, plugins),
kwargs={'automerge': automerge},
timeout=300,
result_ttl=86400,
)
Expand Down

0 comments on commit 12a0505

Please sign in to comment.