Issues (2963)

includes/polling/applications/ntp-server.inc.php (1 issue)

1
<?php
2
3
use LibreNMS\Exceptions\JsonAppException;
4
use LibreNMS\Exceptions\JsonAppParsingFailedException;
5
use LibreNMS\RRD\RrdDefinition;
6
7
$name = 'ntp-server';
8
$app_id = $app['app_id'];
9
10
echo $name;
11
12
try {
13
    $ntp = json_app_get($device, $name);
14
} catch (JsonAppParsingFailedException $e) {
15
    // Legacy script, build compatible array
16
    $legacy = $e->getOutput();
17
18
    $ntp = [
19
        data => [],
0 ignored issues
show
The constant data was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
20
    ];
21
22
    [$ntp['data']['stratum'], $ntp['data']['offset'], $ntp['data']['frequency'], $ntp['data']['jitter'],
23
          $ntp['data']['noise'], $ntp['data']['stability'], $ntp['data']['uptime'], $ntp['data']['buffer_recv'],
24
          $ntp['data']['buffer_free'], $ntp['data']['buffer_used'], $ntp['data']['packets_drop'],
25
          $ntp['data']['packets_ignore'], $ntp['data']['packets_recv'], $ntp['data']['packets_sent']] = explode("\n", $legacy);
26
} catch (JsonAppException $e) {
27
    echo PHP_EOL . $name . ':' . $e->getCode() . ':' . $e->getMessage() . PHP_EOL;
28
    update_application($app, $e->getCode() . ':' . $e->getMessage(), []); // Set empty metrics and error message
29
30
    return;
31
}
32
33
$rrd_name = ['app', $name, $app_id];
34
$rrd_def = RrdDefinition::make()
35
    ->addDataset('stratum', 'GAUGE', 0, 1000)
36
    ->addDataset('offset', 'GAUGE', -1000, 1000)
37
    ->addDataset('frequency', 'GAUGE', -1000, 1000)
38
    ->addDataset('jitter', 'GAUGE', -1000, 1000)
39
    ->addDataset('noise', 'GAUGE', -1000, 1000)
40
    ->addDataset('stability', 'GAUGE', -1000, 1000)
41
    ->addDataset('uptime', 'GAUGE', 0, 125000000000)
42
    ->addDataset('buffer_recv', 'GAUGE', 0, 100000)
43
    ->addDataset('buffer_free', 'GAUGE', 0, 100000)
44
    ->addDataset('buffer_used', 'GAUGE', 0, 100000)
45
    ->addDataset('packets_drop', 'DERIVE', 0, 125000000000)
46
    ->addDataset('packets_ignore', 'DERIVE', 0, 125000000000)
47
    ->addDataset('packets_recv', 'DERIVE', 0, 125000000000)
48
    ->addDataset('packets_sent', 'DERIVE', 0, 125000000000);
49
50
$fields = [
51
    'stratum'        => $ntp['data']['stratum'],
52
    'offset'         => $ntp['data']['offset'],
53
    'frequency'      => $ntp['data']['frequency'],
54
    'jitter'         => $ntp['data']['sys_jitter'],
55
    'noise'          => $ntp['data']['clk_jitter'],
56
    'stability'      => $ntp['data']['clk_wander'],
57
    'uptime'         => $ntp['data']['time_since_reset'],
58
    'buffer_recv'    => $ntp['data']['receive_buffers'],
59
    'buffer_free'    => $ntp['data']['free_receive_buffers'],
60
    'buffer_used'    => $ntp['data']['used_receive_buffers'],
61
    'packets_drop'   => $ntp['data']['dropped_packets'],
62
    'packets_ignore' => $ntp['data']['ignored_packets'],
63
    'packets_recv'   => $ntp['data']['received_packets'],
64
    'packets_sent'   => $ntp['data']['packets_sent'],
65
];
66
67
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
68
data_update($device, 'app', $tags, $fields);
69
update_application($app, 'OK', $fields);
70