Skip to content

Commit

Permalink
Improved log messages in integrations.
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-unwin committed Apr 21, 2024
1 parent ae140ea commit 44ca9a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/Helpers/integrations_nmis_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ function integrations_update($integration, $devices)
unlink($ckfile);
return array();
} else {
$message = '[integrations_update] Device ' . $device->configuration->host . ' updated in NMIS.';
$message = '[integrations_update] Device ' . $device->name . ' at ' . $device->configuration->host . ' updated in NMIS.';
$count = count($external_devices);
$sql = "INSERT INTO integrations_log VALUES (null, ?, null, ?, 'info', ?)";
$db->query($sql, [$integration->id, microtime(true), $message]);
Expand Down
15 changes: 5 additions & 10 deletions app/Models/IntegrationsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,15 +451,16 @@ public function execute(int $id = 0)
$sql = "SELECT omk_uuid FROM devices WHERE id = ?";
$result = $this->db->query($sql, [intval($device->devices->id)])->getResult();
foreach ($integration->attributes->fields as $field) {
$message = 'Not updating device ID: ' . $device->devices->id . ' for ' . $device->devices->name . ' in Open-AudIT because no changed fields.';
if (($field->priority === 'external' or (empty($result[0]->uuid) and $integration->attributes->type === 'nmis')) and strpos($field->internal_field_name, 'devices.') !== false) {
// a regular field in Open-AudIT that we should update
$system_field = str_replace('devices.', '', $field->internal_field_name);
if (!empty($device->devices->{$system_field})) { # TODO - something better than not empty
$temp_device->{$system_field} = $device->devices->{$system_field};
$message = 'Updating device ID: ' . $device->devices->id . ' for ' . $device->devices->name . ' in Open-AudIT because ' . $system_field . ' is ' . $device->devices->{$system_field} . ' and priority is external.';
}
}
}
$message = 'Updating device ID: ' . $device->devices->id . ' for ' . $device->devices->name . ' in Open-AudIT.';
$sql = "INSERT INTO integrations_log VALUES (null, ?, null, ?, 'info', ?)";
$this->db->query($sql, [$integration->id, microtime(true), $message]);
$devicesModel->update($temp_device->id, $temp_device);
Expand Down Expand Up @@ -746,7 +747,7 @@ public function execute(int $id = 0)
$hit = true;
if ($integration->debug) {
// TODO - ip not seeing in logs
$message = "Updating {$local_device->name} at {$local_device->configuration->host} because {$ifield->external_field_name} == $test";
$message = "Updating {$local_device->name} at {$local_device->configuration->host} in NMIS because {$ifield->external_field_name} == $test and priority is internal.";
$sql = "INSERT INTO integrations_log VALUES (null, ?, null, ?, 'debug', ?)";
$this->db->query($sql, [$integration->id, microtime(true), $message]);
}
Expand All @@ -770,12 +771,6 @@ public function execute(int $id = 0)
$sql = "UPDATE integrations SET update_external_count = ? WHERE id = ?";
$this->db->query($sql, [count($update_external_devices), $integration->id]);

// if ($integration->debug and count($update_external_devices) > 0) {
// $message = json_encode($update_external_devices);
// $sql = "INSERT INTO integrations_log VALUES (null, ?, null, ?, 'debug', ?)";
// $this->db->query($sql, [$integration->id, microtime(true), $message]);
// }

integrations_update($integration, $update_external_devices);
}

Expand All @@ -795,7 +790,7 @@ public function execute(int $id = 0)
$test2 = $this->getValue($external_device, $field->external_field_name);
if ($test1 == $test2) {
if ($integration->debug) {
$message = 'Removing ' . $external_device->name . ' delete from list.';
$message = 'Removing ' . $external_device->name . ' from delete list (not deleting this device in NMIS).';
$sql = "INSERT INTO integrations_log VALUES (null, ?, null, ?, 'info', ?)";
$this->db->query($sql, [$integration->id, microtime(true), $message]);
}
Expand All @@ -813,7 +808,7 @@ public function execute(int $id = 0)
integrations_delete($integration, $delete_external_devices);
} else {
$message = '0 devices require deleting in ' . $integration->attributes->type . ' for ' . $integration->attributes->name . '.';
$sql = "/* m_integrations::execute */ " . "INSERT INTO integrations_log VALUES (null, ?, null, ?, 'info', ?)";
$sql = "INSERT INTO integrations_log VALUES (null, ?, null, ?, 'info', ?)";
$this->db->query($sql, [$integration->id, microtime(true), $message]);
}
}
Expand Down

0 comments on commit 44ca9a0

Please sign in to comment.