Files

46 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2020-06-16 01:04:30 +02:00
<?php
// Polls backupninja statistics from script via SNMP
use LibreNMS\RRD\RrdDefinition;
$name = 'backupninja';
$app_id = $app['app_id'];
$output = 'OK';
try {
$backupninja_data = json_app_get($device, $name, 1)['data'];
} catch (JsonAppMissingKeysException $e) {
$backupninja_data = $e->getParsedJson();
} catch (JsonAppException $e) {
2020-09-21 15:43:38 +02:00
echo PHP_EOL . $name . ':' . $e->getCode() . ':' . $e->getMessage() . PHP_EOL;
update_application($app, $e->getCode() . ':' . $e->getMessage(), []); // Set empty metrics and error message
2020-06-16 01:04:30 +02:00
return;
}
2020-09-21 15:43:38 +02:00
$metrics = [];
2020-06-16 01:04:30 +02:00
$category = 'overview';
2020-09-21 15:43:38 +02:00
$rrd_name = ['app', $name, $app_id, $category];
2020-06-16 01:04:30 +02:00
$rrd_def = RrdDefinition::make()
->addDataset('last_actions', 'GAUGE', 0)
->addDataset('last_fatal', 'GAUGE', 0)
->addDataset('last_error', 'GAUGE', 0)
->addDataset('last_warning', 'GAUGE', 0);
2020-09-21 15:43:38 +02:00
$fields = [
2020-06-16 01:04:30 +02:00
'last_actions' => $backupninja_data['last_actions'],
'last_fatal' => $backupninja_data['last_fatal'],
'last_error' => $backupninja_data['last_error'],
'last_warning' => $backupninja_data['last_warning'],
2020-09-21 15:43:38 +02:00
];
2020-06-16 01:04:30 +02:00
$metrics[$category] = $fields;
// Debug
d_echo("backupninja : $fields");
2020-09-21 15:43:38 +02:00
$tags = ['name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name];
2020-06-16 01:04:30 +02:00
data_update($device, 'app', $tags, $fields);
update_application($app, $output, $metrics);