two minor fixes for sagan (#16082)

* two minor fixes for sagan

* more tweaks

* change how instance handling is done
This commit is contained in:
Zane C. Bowers-Hadley
2024-06-04 04:08:20 -05:00
committed by GitHub
parent 05f29ae76c
commit fb7bc5dd5a
2 changed files with 5 additions and 3 deletions

View File

@@ -9,7 +9,7 @@ $link_array = [
print_optionbar_start();
echo generate_link('Totals', $link_array);
echo generate_link('Totals', $link_array) . ' | Instances: ';
$sagan_instances = $app->data['instances'] ?? [];
sort($sagan_instances);

View File

@@ -78,7 +78,8 @@ foreach ($sagan['data'] as $instance => $stats) {
$tags = ['name' => $name, 'app_id' => $app->app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name];
data_update($device, 'app', $tags, $fields);
}
$old_instances = $app->app['instances'];
$old_instances = $app->app['instances'] ?? [];
//check for added instances
$added_instances = array_values(array_diff($instances, $old_instances));
@@ -88,13 +89,14 @@ $removed_instances = array_values(array_diff($old_instances, $instances));
// if we have any instance changes, log it
if (sizeof($added_instances) > 0 or sizeof($removed_instances) > 0) {
$app->data = ['instances' => $instances];
$log_message = 'Sagan Instance Change:';
$log_message .= count($added_instances) > 0 ? ' Added ' . json_encode($added_instances) : '';
$log_message .= count($removed_instances) > 0 ? ' Removed ' . json_encode($added_instances) : '';
log_event($log_message, $device, 'application');
}
$app->data = ['instances' => $instances];
//
// all done so update the app metrics
//