Skip to content

Commit

Permalink
Logging improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-unwin committed Feb 18, 2019
1 parent 3cee85b commit 8770e79
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 60 deletions.
9 changes: 7 additions & 2 deletions code_igniter/application/helpers/audit_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,6 @@ function audit_format_system($parameters)
if (!filter_var($input->hostname, FILTER_VALIDATE_IP)) {
if (strpos($input->hostname, '.') !== false) {
# we have a fqdn in the hostname field
$mylog->message = "FQDN supplied in hostname, converting.";
discovery_log($mylog);
if (empty($input->fqdn)) {
$input->fqdn = $input->hostname;
}
Expand All @@ -350,6 +348,9 @@ function audit_format_system($parameters)
$input->domain = implode('.', $temp);
}
unset($temp);
$mylog->message = "FQDN supplied in hostname, converting.";
$mylog->command_output = 'Hostname: ' . $input->hostname . ' Domain: ' . $input->domain;
discovery_log($mylog);
}
}

Expand All @@ -358,6 +359,7 @@ function audit_format_system($parameters)
if (empty($input->ip)) {
$input->ip = $input->hostname;
$mylog->message = "IP supplied in hostname, setting device IP.";
$mylog->command_output = 'IP: ' . $input->ip;
discovery_log($mylog);
}
$input->hostname = '';
Expand All @@ -370,9 +372,12 @@ function audit_format_system($parameters)
(strripos($input->manufacturer, "virtual") !== false))) {
$input->form_factor = 'Virtual';
$mylog->message = "Manufacturer match, setting form factor to Virtual.";
$mylog->command_output = 'Manufacturer: ' . $input->manufacturer;
discovery_log($mylog);
}

$mylog->command_output = '';

# Mac Model
if (!empty($input->os_family) and $input->os_family == 'Apple OSX') {
$CI->load->helper('mac_model');
Expand Down
99 changes: 52 additions & 47 deletions code_igniter/application/helpers/snmp_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ function snmp_audit($ip, $credentials, $log)
discovery_log($log);
return false;
} else {
$log->message = 'SNMP PHP function loaded and attempting to run snmp_helper::snmp_audit function';
discovery_log($log);
#$log->message = 'SNMP PHP function loaded and attempting to run snmp_helper::snmp_audit function';
#discovery_log($log);
}

# we need an ip address
Expand All @@ -380,8 +380,8 @@ function snmp_audit($ip, $credentials, $log)
discovery_log($log);
return false;
} else {
$log->message = 'Received ip ' . $ip;
discovery_log($log);
#$log->message = 'Received ip ' . $ip;
#discovery_log($log);
}

if (empty($credentials) or !is_object($credentials)) {
Expand All @@ -390,8 +390,8 @@ function snmp_audit($ip, $credentials, $log)
discovery_log($log);
return false;
} else {
$log->message = 'Received credentials for ip ' . $ip;
discovery_log($log);
#$log->message = 'Received credentials for ip ' . $ip;
#discovery_log($log);
}

# new in 1.5 - remove the type from the returned SNMP query.
Expand Down Expand Up @@ -488,14 +488,14 @@ function snmp_audit($ip, $credentials, $log)
} else {
$details->uptime = intval($details->sysUpTime / 100);
}
if (!empty($details->uptime)) {
$log->message = 'derive uptime from sysUpTime for '.$ip;
$log->command = '';
$log->command_output = (string)$details->uptime;
$log->command_time_to_execute = (microtime(true) - $item_start);
discovery_log($log);
unset($log->id, $log->command, $log->command_time_to_execute, $log->command_output);
}
// if (!empty($details->uptime)) {
// $log->message = 'derive uptime from sysUpTime for '.$ip;
// $log->command = '';
// $log->command_output = (string)$details->uptime;
// $log->command_time_to_execute = (microtime(true) - $item_start);
// discovery_log($log);
// unset($log->id, $log->command, $log->command_time_to_execute, $log->command_output);
// }

$log->message = 'sysObjectID retrieval for '.$ip;
$log->command = 'snmpget 1.3.6.1.2.1.1.2.0';
Expand Down Expand Up @@ -804,11 +804,14 @@ function snmp_audit($ip, $credentials, $log)
unset($log->id, $log->command, $log->command_time_to_execute, $log->command_output);
}

$log->message = 'SNMP audit thinks '.$ip.' is of type:'.$details->type;
$log->message = 'SNMP audit thinks '.$ip.' is of type: '.$details->type;
$log->command_output = $details->type;
discovery_log($log);
$log->message = 'SNMP audit thinks '.$ip.' is a model:' . $details->model;
$log->message = 'SNMP audit thinks '.$ip.' is a model: ' . $details->model;
$log->command_output = $details->model;
discovery_log($log);
$log->message = 'SNMP audit thinks '.$ip.' has a serial:' . $details->serial;
$log->message = 'SNMP audit thinks '.$ip.' has a serial: ' . $details->serial;
$log->command_output = $details->serial;
discovery_log($log);

// subnet
Expand Down Expand Up @@ -840,20 +843,22 @@ function snmp_audit($ip, $credentials, $log)
discovery_log($log);
unset($log->id, $log->command, $log->command_time_to_execute);

$log->message = 'MAC Address for interface ' . $interface_number . ' using IP ' . $ip . ' retrieval for '.$ip;
$log->command = 'snmpget 1.3.6.1.2.1.2.2.1.6.'.$interface_number;
$log->command_status = 'fail';
$log->id = discovery_log($log);
$item_start = microtime(true);
snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
$details->mac_address = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.2.2.1.6.".$interface_number);
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
$log->command_time_to_execute = (microtime(true) - $item_start);
$details->mac_address = format_mac($details->mac_address);
$log->command_output = (string)$details->mac_address;
$log->command_status = 'notice';
discovery_log($log);
unset($log->id, $log->command, $log->command_time_to_execute);
if (!empty($interface_number)) {
$log->message = 'MAC Address for interface ' . $interface_number . ' using IP ' . $ip . ' retrieval for '.$ip;
$log->command = 'snmpget 1.3.6.1.2.1.2.2.1.6.'.$interface_number;
$log->command_status = 'fail';
$log->id = discovery_log($log);
$item_start = microtime(true);
snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
$details->mac_address = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.2.2.1.6.".$interface_number);
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
$log->command_time_to_execute = (microtime(true) - $item_start);
$details->mac_address = format_mac($details->mac_address);
$log->command_output = (string)$details->mac_address;
$log->command_status = 'notice';
discovery_log($log);
unset($log->id, $log->command, $log->command_time_to_execute);
}
}
// last attempt at a MAC - just use whatever's in the first interface MAC
if (empty($details->mac_address)) {
Expand Down Expand Up @@ -1241,10 +1246,10 @@ function snmp_audit($ip, $credentials, $log)
discovery_log($log);
unset($log->id, $log->command, $log->command_time_to_execute, $log->command_output);

$log->message = 'Processing modules for '.$ip;
$log->command_status = 'fail';
$log->id = discovery_log($log);
$item_start = microtime(true);
// $log->message = 'Processing modules for '.$ip;
// $log->command_status = 'fail';
// $log->id = discovery_log($log);
// $item_start = microtime(true);
foreach ($modules_list as $key => $value) {

$module = new stdClass();
Expand Down Expand Up @@ -1306,10 +1311,10 @@ function snmp_audit($ip, $credentials, $log)

$modules[] = $module;
}
$log->command_time_to_execute = (microtime(true) - $item_start);
$log->command_status = 'notice';
discovery_log($log);
unset($log->id, $log->command, $log->command_time_to_execute);
// $log->command_time_to_execute = (microtime(true) - $item_start);
// $log->command_status = 'notice';
// discovery_log($log);
// unset($log->id, $log->command, $log->command_time_to_execute);
}
unset($log->id, $log->command, $log->command_time_to_execute, $log->command_output);

Expand Down Expand Up @@ -1505,10 +1510,10 @@ function snmp_audit($ip, $credentials, $log)
discovery_log($log);
unset($log->id, $log->command, $log->command_time_to_execute, $log->command_output);

$log->message = 'Processing interfaces for '.$ip;
$log->command_status = 'fail';
$log->id = discovery_log($log);
$item_start = microtime(true);
// $log->message = 'Processing interfaces for '.$ip;
// $log->command_status = 'fail';
// $log->id = discovery_log($log);
// $item_start = microtime(true);

foreach ($interfaces as $key => $value) {
// $log->message = 'Processing interface '. $value .' for '.$ip;
Expand Down Expand Up @@ -1597,10 +1602,10 @@ function snmp_audit($ip, $credentials, $log)
// unset($log->id, $log->command, $log->command_time_to_execute);
}

$log->command_time_to_execute = (microtime(true) - $item_start);
$log->command_status = 'notice';
discovery_log($log);
unset($log->id, $log->command, $log->command_time_to_execute);
// $log->command_time_to_execute = (microtime(true) - $item_start);
// $log->command_status = 'notice';
// discovery_log($log);
// unset($log->id, $log->command, $log->command_time_to_execute);
} // end of network interfaces

// Special for ExaBlaze
Expand Down
22 changes: 11 additions & 11 deletions code_igniter/application/helpers/ssh_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,11 @@ function ssh_command($parameters)
if (stripos($command, 'audit_') !== false and stripos($command, 'submit_online') !== false) {
$log->command_output = 'Audit console output removed.';
} else {
$log->command_output = json_encode($result);
if (!empty($result)) {
$log->command_output = json_encode($result);
} else {
$log->command_output = '';
}
}
$log->command_status = 'success';
discovery_log($log);
Expand Down Expand Up @@ -763,17 +767,13 @@ function ssh_audit($parameters)
}
$log->severity = 7;

if (strpos($device->shell, 'bash') === false) {
if (strpos($device->shell, 'bash') === false and $device->bash === '') {
$log->command = '';
$log->command_output = $device->shell;
$log->command_time_to_execute = '';
$log->severity = 6;
$log->message = 'Will use ' . $device->bash . ' to run commands. Running commands in a shell other than bash may fail.';
$log->message = 'Will use ' . $device->shell . ' to run commands. Running commands in a shell other than bash may fail.';
$log->command_status = 'notice';
if ($device->bash === '') {
$log->message = 'Unable to detect shell. Running commands in a shell other than bash may fail.';
$log->command_status = 'notice';
}
discovery_log($log);
}
$log->severity = 7;
Expand Down Expand Up @@ -850,18 +850,18 @@ function ssh_audit($parameters)
} else {
$device->$item = $temp1;
}
$log->command = $command . '; # ' . $item;
$log->command = $command;
$log->command_time_to_execute = (microtime(true) - $item_start);
$log->command_output = $temp1;
$log->command_status = 'success';
$log->message = 'SSH command';
$log->message = 'SSH command - ' . $item;
discovery_log($log);
} else {
$log->command = $command . '; # ' . $item;
$log->command = $command;
$log->command_time_to_execute = (microtime(true) - $item_start);
$log->command_output = $temp1;
$log->command_status = 'notice';
$log->message = 'SSH command';
$log->message = 'SSH command - ' . $item;
discovery_log($log);
}
}
Expand Down

0 comments on commit 8770e79

Please sign in to comment.