Passed
Push — master ( 0baeb0...d4017c )
by Tony
19:18 queued 08:55
created

includes/discovery/sensors/openbsd.inc.php (3 issues)

1
<?php
2
3
echo ' OPENBSD-SENSORS-MIB: ';
4
5
echo 'Caching OIDs:';
6
7
$oids = [];
8
echo ' sensorDevice';
9
$oids = snmpwalk_cache_multi_oid($device, 'sensorDevice', $oids, 'OPENBSD-SENSORS-MIB');
10
echo ' sensorDescr';
11
$oids = snmpwalk_cache_multi_oid($device, 'sensorDescr', $oids, 'OPENBSD-SENSORS-MIB');
12
echo ' sensorValue';
13
$oids = snmpwalk_cache_multi_oid($device, 'sensorValue', $oids, 'OPENBSD-SENSORS-MIB');
14
echo ' sensorType';
15
$oids = snmpwalk_cache_multi_oid($device, 'sensorType', $oids, 'OPENBSD-SENSORS-MIB');
16
17
# temperature(0), fan(1), voltsdc(2), voltsac(3), resistance(4), power(5),
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
18
# current(6), watthour(7), amphour(8), indicator(9), raw(10), percent(11),
19
# illuminance(12), drive(13), timedelta(14), humidity(15), freq(16),
20
# angle(17), distance(18), pressure(19), accel(20)
21
22
$entitysensor['voltsdc']   = 'voltage';
23
$entitysensor['voltsac']   = 'voltage';
24
$entitysensor['fan']       = 'fanspeed';
25
26
$entitysensor['current']   = 'current';
27
$entitysensor['power']     = 'power';
28
$entitysensor['freq']      = 'freq';
29
$entitysensor['humidity']  = 'humidity';
30
$entitysensor['temperature'] = 'temperature';
31
32
if (is_array($oids)) {
33
    foreach ($oids as $index => $entry) {
34
        // echo("[" . $entry['sensorType'] . "|" . $entry['sensorValue']. "|" . $index . "] ");
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
35
        if ($entitysensor[$entry['sensorType']] && is_numeric($entry['sensorValue']) && is_numeric($index)) {
36
            $entPhysicalIndex = $index;
37
            $oid              = '.1.3.6.1.4.1.30155.2.1.2.1.5.'.$index;
38
            $current          = $entry['sensorValue'];
39
            $descr = $entry['sensorDevice'].' '.$entry['sensorDescr'];
40
            $bogus = false;
41
42
            $type = $entitysensor[$entry['sensorType']];
43
44
            if ($type == 'voltage') {
45
                $descr = preg_replace('/ voltage/i', '', $descr);
46
            }
47
48
            if ($type == 'temperature') {
49
                if ($current < -40 || $current > 200) {
50
                    $bogus = true;
51
                }
52
                $descr = preg_replace('/ temperature/i', '', $descr);
53
            }
54
55
            // echo($descr . "|" . $index . "|" .$current . "|" . $bogus . "\n");
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
56
            if (! $bogus) {
57
                discover_sensor($valid['sensor'], $type, $device, $oid, $index, 'openbsd-sensor', $descr, '1', '1', null, null, null, null, $current);
58
            }
59
        }//end if
60
    }//end foreach
61
}//end if
62
63
echo "\n";
64