Skip to content

Commit

Permalink
Improve - Move the update of discoveries.ip_all_count and discoveries…
Browse files Browse the repository at this point in the history
….ip_responding_count into the log helper so it's applied when running Server / Collector. We already did this for ip_discovered_count and ip_audited_count so it makes this a little more consistent having them all here as well.
  • Loading branch information
mark-unwin committed Jul 20, 2020
1 parent 211b288 commit 54315d2
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 66 deletions.
3 changes: 0 additions & 3 deletions code_igniter/application/controllers/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,6 @@ public function queue()
$queue_item->discovery_id = $details->discovery_id;
$queue_item->details = $result;
$this->m_queue->create('ip_audit', $queue_item);
$sql = '/* util::queue */ ' . 'UPDATE `discoveries` SET `ip_scanned_count` = `ip_scanned_count` + 1 WHERE id = ?';
$data = array($details->discovery_id);
$this->db->query($sql, $data);
}
}

Expand Down
20 changes: 15 additions & 5 deletions code_igniter/application/helpers/discoveries_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,19 +327,29 @@ function discover_subnet($queue_item = null)
if ( ! empty($responding_ip_list) && is_array($responding_ip_list)) {
$ip_responding_count = count($responding_ip_list);
}
$sql = '/* discoveries_helper::discover_subnet */ ' . 'UPDATE `discoveries` SET ip_all_count = ?, ip_responding_count = ? WHERE `id` = ?';
$data = array($ip_all_count, $ip_responding_count, $discovery_id);
$CI->db->query($sql, $data);

$time_to_execute = microtime(true) - $start;

// This will increment discoveries.ip_all_count using tyhe log helper (think Collector / Server)
$log->message = 'Total IPs count: ' . $ip_all_count;
$log->command_time_to_execute = $time_to_execute;
discovery_log($log);

// This will increment discoveries.ip_responding_count using tyhe log helper (think Collector / Server)
$log->message = 'Responding IPs count: ' . $ip_responding_count;
$log->command_time_to_execute = $time_to_execute;
discovery_log($log);

if (empty($responding_ip_list)) {
$log->message = 'No IPs are responding. You may wish to check your discovery configuration.';
$log->command_time_to_execute = microtime(true) - $start;
$log->command_time_to_execute = $time_to_execute;
discovery_log($log);
// NOTE - the log_helper will mark this in the database as complete for us, think Collector / Server
$log->message = 'Discovery has finished.';
$log->command = '';
$log->command_output = '';
$log->command_status = 'finished';
$log->command_time_to_execute = microtime(true) - $start;
$log->command_time_to_execute = $time_to_execute;
$log->ip = '127.0.0.1';
discovery_log($log);
}
Expand Down
Loading

0 comments on commit 54315d2

Please sign in to comment.