Issues (2963)

includes/polling/core.inc.php (1 issue)

1
<?php
2
/*
3
 * LibreNMS Network Management and Monitoring System
4
 * Copyright (C) 2006-2011, Observium Developers - http://www.observium.org
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * See COPYING for more details.
12
 */
13
14
use LibreNMS\Config;
15
use LibreNMS\RRD\RrdDefinition;
16
use LibreNMS\Util\Time;
17
18
$snmpdata = snmp_get_multi_oid($device, ['sysUpTime.0', 'sysName.0', 'sysObjectID.0', 'sysDescr.0'], '-OQnUt', 'SNMPv2-MIB');
19
20
$poll_device['sysUptime'] = $snmpdata['.1.3.6.1.2.1.1.3.0'];
21
$poll_device['sysName'] = str_replace("\n", '', strtolower($snmpdata['.1.3.6.1.2.1.1.5.0']));
22
$poll_device['sysObjectID'] = $snmpdata['.1.3.6.1.2.1.1.2.0'];
23
$poll_device['sysDescr'] = str_replace(chr(218), "\n", $snmpdata['.1.3.6.1.2.1.1.1.0']);
24
25
if (! empty($agent_data['uptime'])) {
26
    [$uptime] = explode(' ', $agent_data['uptime']);
27
    $uptime = round($uptime);
0 ignored issues
show
$uptime of type string is incompatible with the type double|integer expected by parameter $num of round(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
    $uptime = round(/** @scrutinizer ignore-type */ $uptime);
Loading history...
28
    echo "Using UNIX Agent Uptime ($uptime)\n";
29
} else {
30
    $uptime_data = snmp_get_multi($device, ['snmpEngineTime.0', 'hrSystemUptime.0'], '-OQnUst', 'HOST-RESOURCES-MIB:SNMP-FRAMEWORK-MIB');
31
32
    $uptime = max(
33
        round($poll_device['sysUptime'] / 100),
34
        Config::get("os.{$device['os']}.bad_snmpEngineTime") ? 0 : $uptime_data[0]['snmpEngineTime'],
35
        Config::get("os.{$device['os']}.bad_hrSystemUptime") ? 0 : round($uptime_data[0]['hrSystemUptime'] / 100)
36
    );
37
    d_echo("Uptime seconds: $uptime\n");
38
}
39
40
if ($uptime != 0 && Config::get("os.{$device['os']}.bad_uptime") !== true) {
41
    if ($uptime < $device['uptime']) {
42
        log_event('Device rebooted after ' . Time::formatInterval($device['uptime']) . " -> {$uptime}s", $device, 'reboot', 4, $device['uptime']);
43
    }
44
45
    $tags = [
46
        'rrd_def' => RrdDefinition::make()->addDataset('uptime', 'GAUGE', 0),
47
    ];
48
    data_update($device, 'uptime', $tags, $uptime);
49
50
    $os->enableGraph('uptime');
51
52
    echo 'Uptime: ' . Time::formatInterval($uptime) . PHP_EOL;
53
54
    $update_array['uptime'] = $uptime;
55
    $device['uptime'] = $uptime;
56
}//end if
57
58
// Save results of various polled values to the database
59
foreach (['sysObjectID', 'sysName', 'sysDescr'] as $elem) {
60
    if ($poll_device[$elem] != $device[$elem]) {
61
        $update_array[$elem] = $poll_device[$elem];
62
        $device[$elem] = $poll_device[$elem];
63
        log_event("$elem -> " . $poll_device[$elem], $device, 'system', 3);
64
    }
65
}
66
67
unset($snmpdata, $uptime_data, $uptime, $tags, $poll_device);
68