Issues (2963)

includes/discovery/sensors/current/apc.inc.php (2 issues)

1
<?php
2
3
// PDU - Phase
4
$oids = snmp_walk($device, 'rPDUStatusPhaseIndex', '-OsqnU', 'PowerNet-MIB');
5
if (empty($oids)) {
6
    $oids = snmp_walk($device, 'rPDULoadPhaseConfigIndex', '-OsqnU', 'PowerNet-MIB');
7
}
8
if ($oids) {
9
    d_echo($oids . "\n");
10
    $oids = trim($oids);
11
    if ($oids) {
12
        echo 'APC PowerNet-MIB Phase ';
13
    }
14
    $type = 'apc';
15
    $precision = '10';
16
    foreach (explode("\n", $oids) as $data) {
17
        $data = trim($data);
18
        if ($data) {
19
            [$oid,$kind] = explode(' ', $data);
20
            $split_oid = explode('.', $oid);
21
            $index = $split_oid[(count($split_oid) - 1)];
22
            $current_oid = '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.' . $index;
23
            // rPDULoadStatusLoad
24
            $phase_oid = '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.4.' . $index;
25
            // rPDULoadStatusPhaseNumber
26
            $limit_oid = '.1.3.6.1.4.1.318.1.1.12.2.2.1.1.4.' . $index;
27
            // rPDULoadPhaseConfigOverloadThreshold
28
            $lowlimit_oid = '.1.3.6.1.4.1.318.1.1.12.2.2.1.1.2.' . $index;
29
            // rPDULoadPhaseConfigLowLoadThreshold
30
            $warnlimit_oid = '.1.3.6.1.4.1.318.1.1.12.2.2.1.1.3.' . $index;
31
            // rPDULoadPhaseConfigNearOverloadThreshold
32
            $phase = snmp_get($device, $phase_oid, '-Oqv', '');
33
            $current = (snmp_get($device, $current_oid, '-Oqv', '') / $precision);
34
            $limit = snmp_get($device, $limit_oid, '-Oqv', '');
35
            // No / $precision here! Nice, APC!
36
            $lowlimit = snmp_get($device, $lowlimit_oid, '-Oqv', '');
37
            // No / $precision here! Nice, APC!
38
            $warnlimit = snmp_get($device, $warnlimit_oid, '-Oqv', '');
39
            // No / $precision here! Nice, APC!
40
            if (count(explode("\n", $oids)) != 1) {
41
                $descr = "Phase $phase";
42
            } else {
43
                $descr = 'Output';
44
            }
45
            discover_sensor($valid['sensor'], 'current', $device, $current_oid, $index, $type, $descr, '10', '1', $lowlimit, null, $warnlimit, $limit, $current);
46
        }
47
    }
48
}
49
unset($oids);
50
// v2 firmware- first bank is total, v3 firmware, 3rd bank is total
51
$bank_count = snmp_get($device, 'rPDULoadDevNumBanks.0', '-Oqv', 'PowerNet-MIB');
52
if ($bank_count > 0) {
53
    $oids = snmp_walk($device, 'rPDULoadStatusIndex', '-OsqnU', 'PowerNet-MIB');
54
}
55
// should work with firmware v2 and v3
56
if ($oids) {
57
    echo 'APC PowerNet-MIB Banks ';
58
    d_echo($oids . "\n");
59
    $oids = trim($oids);
60
    $type = 'apc';
61
    $precision = '10';
62
    // version 2 does some stuff differently- total power is first oid in index instead of the last.
63
    // will look something like "AOS v2.6.4 / App v2.6.5"
64
    $baseversion = '3';
65
    if (stristr($device['version'], 'AOS v2') == true) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stristr($device['version'], 'AOS v2') of type string to the boolean true. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
66
        $baseversion = '2';
67
    }
68
    foreach (explode("\n", $oids) as $data) {
69
        $data = trim($data);
70
        if ($data) {
71
            [$oid,$kind] = explode(' ', $data);
72
            $split_oid = explode('.', $oid);
73
            $index = $split_oid[(count($split_oid) - 1)];
74
            $banknum = ($index - 1);
75
            $descr = 'Bank ' . $banknum;
76
            if ($baseversion == '3') {
77
                if ($index == '1') {
78
                    $descr = 'Bank Total';
79
                }
80
            }
81
            if ($baseversion == '2') {
82
                if ($index == '1') {
83
                    $descr = 'Bank Total';
84
                }
85
            }
86
            $current_oid = '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.' . $index;
87
            // rPDULoadStatusLoad
88
            $bank_oid = '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.5.' . $index;
89
            // rPDULoadStatusBankNumber
90
            $limit_oid = '.1.3.6.1.4.1.318.1.1.12.2.4.1.1.4.' . $index;
91
            // rPDULoadBankConfigOverloadThreshold
92
            $lowlimit_oid = '.1.3.6.1.4.1.318.1.1.12.2.4.1.1.2.' . $index;
93
            // rPDULoadBankConfigLowLoadThreshold
94
            $warnlimit_oid = '.1.3.6.1.4.1.318.1.1.12.2.4.1.1.3.' . $index;
95
            // rPDULoadBankConfigNearOverloadThreshold
96
            $bank = snmp_get($device, $bank_oid, '-Oqv', '');
97
            $current = (snmp_get($device, $current_oid, '-Oqv', '') / $precision);
98
            $limit = snmp_get($device, $limit_oid, '-Oqv', '');
99
            $lowlimit = snmp_get($device, $lowlimit_oid, '-Oqv', '');
100
            $warnlimit = snmp_get($device, $warnlimit_oid, '-Oqv', '');
101
            if ($limit != -1 && $lowlimit != -1 && $warnlimit != -1) {
102
                discover_sensor($valid['sensor'], 'current', $device, $current_oid, $index, $type, $descr, '10', '1', $lowlimit, null, $warnlimit, $limit, $current);
103
            }
104
        }
105
    }
106
    unset($baseversion);
107
}
108
unset($oids);
109
// Per Outlet Power Bar
110
$oids = snmp_walk($device, '.1.3.6.1.4.1.318.1.1.26.9.4.3.1.1', '-t 30 -OsqnU', 'PowerNet-MIB');
111
if ($oids) {
112
    echo 'APC PowerNet-MIB Outlets ';
113
    d_echo($oids . "\n");
114
    $oids = trim($oids);
115
    $type = 'apc';
116
    $precision = '10';
117
    foreach (explode("\n", $oids) as $data) {
118
        $data = trim($data);
119
        if ($data) {
120
            [$oid,$kind] = explode(' ', $data);
121
            $split_oid = explode('.', $oid);
122
            $index = $split_oid[(count($split_oid) - 1)];
123
            $voltage_oid = '.1.3.6.1.4.1.318.1.1.26.6.3.1.6';
124
            // rPDU2PhaseStatusVoltage
125
            $current_oid = '.1.3.6.1.4.1.318.1.1.26.9.4.3.1.6.' . $index;
126
            // rPDU2OutletMeteredStatusCurrent
127
            $limit_oid = '.1.3.6.1.4.1.318.1.1.26.9.4.1.1.7.' . $index;
128
            // rPDU2OutletMeteredConfigOverloadCurrentThreshold
129
            $lowlimit_oid = '.1.3.6.1.4.1.318.1.1.26.9.4.1.1.7.' . $index;
130
            // rPDU2OutletMeteredConfigLowLoadCurrentThreshold
131
            $warnlimit_oid = '.1.3.6.1.4.1.318.1.1.26.9.4.1.1.6.' . $index;
132
            // rPDU2OutletMeteredConfigNearOverloadCurrentThreshold
133
            $name_oid = '.1.3.6.1.4.1.318.1.1.26.9.4.3.1.3.' . $index;
134
            // rPDU2OutletMeteredStatusName
135
            $voltage = snmp_get($device, $voltage_oid, '-Oqv', '');
136
            $current = (snmp_get($device, $current_oid, '-Oqv', '') / $precision);
137
            $limit = (snmp_get($device, $limit_oid, '-Oqv', '') / $voltage);
138
            $lowlimit = (snmp_get($device, $lowlimit_oid, '-Oqv', '') / $voltage);
139
            $warnlimit = (snmp_get($device, $warnlimit_oid, '-Oqv', '') / $voltage);
140
            $descr = 'Outlet ' . $index . ' - ' . snmp_get($device, $name_oid, '-Oqv', '');
0 ignored issues
show
Are you sure snmp_get($device, $name_oid, '-Oqv', '') of type false|string can be used in concatenation? ( Ignorable by Annotation )

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

140
            $descr = 'Outlet ' . $index . ' - ' . /** @scrutinizer ignore-type */ snmp_get($device, $name_oid, '-Oqv', '');
Loading history...
141
            discover_sensor($valid['sensor'], 'current', $device, $current_oid, $index, $type, $descr, '10', '1', $lowlimit, null, $warnlimit, $limit, $current);
142
        }
143
    }
144
}
145
unset($oids);
146
// ATS
147
$oids = snmp_walk($device, 'atsConfigPhaseTableIndex', '-OsqnU', 'PowerNet-MIB');
148
if ($oids) {
149
    $type = 'apc';
150
    d_echo($oids . "\n");
151
    $oids = trim($oids);
152
    if ($oids) {
153
        echo 'APC PowerNet-MIB ATS ';
154
    }
155
    $current_oid = '.1.3.6.1.4.1.318.1.1.8.5.4.3.1.4.1.1.1';
156
    // atsOutputCurrent
157
    $limit_oid = '.1.3.6.1.4.1.318.1.1.8.4.16.1.5.1';
158
    // atsConfigPhaseOverLoadThreshold
159
    $lowlimit_oid = '.1.3.6.1.4.1.318.1.1.8.4.16.1.3.1';
160
    // atsConfigPhaseLowLoadThreshold
161
    $warnlimit_oid = '.1.3.6.1.4.1.318.1.1.8.4.16.1.4.1';
162
    // atsConfigPhaseNearOverLoadThreshold
163
    $index = 1;
164
    $current = (snmp_get($device, $current_oid, '-Oqv', '') / $precision);
165
    $limit = snmp_get($device, $limit_oid, '-Oqv', '');
166
    // No / $precision here! Nice, APC!
167
    $lowlimit = snmp_get($device, $lowlimit_oid, '-Oqv', '');
168
    // No / $precision here! Nice, APC!
169
    $warnlimit = snmp_get($device, $warnlimit_oid, '-Oqv', '');
170
    // No / $precision here! Nice, APC!
171
    $descr = 'Output Feed';
172
    discover_sensor($valid['sensor'], 'current', $device, $current_oid, $index, $type, $descr, '10', '1', $lowlimit, null, $warnlimit, $limit, $current);
173
}
174
unset($oids);
175
176
// UPS
177
178
    $phasecount = $phasecount = $pre_cache['apcups_phase_count'];
179
if ($phasecount > 1) {
180
    $oids = snmpwalk_cache_oid($device, 'upsPhaseOutputCurrent', $oids, 'PowerNet-MIB');
181
    $in_oids = snmpwalk_cache_oid($device, 'upsPhaseInputCurrent', $in_oids, 'PowerNet-MIB');
182
} else {
183
    $oids = snmpwalk_cache_oid($device, 'upsHighPrecOutputCurrent', $oids, 'PowerNet-MIB');
184
}
185
if (isset($in_oids)) {
186
    foreach ($in_oids as $index => $data) {
187
        $type = 'apcUPS';
188
        $current_oid = '.1.3.6.1.4.1.318.1.1.1.9.2.3.1.6.' . $index;
189
        $divisor = 10;
190
        $current = $data['upsPhaseInputCurrent'] / $divisor;
191
        $in_index = '3.1.4.' . $index;
192
        if (substr($index, 0, 1) == 2 && $data['upsPhaseInputCurrent'] != -1) {
193
            $descr = 'Phase ' . substr($index, -1) . ' Bypass Input';
194
            discover_sensor($valid['sensor'], 'current', $device, $current_oid, $in_index, $type, $descr, $divisor, 0, null, null, null, null, $current);
195
        } elseif (substr($index, 0, 1) == 1) {
196
            $descr = 'Phase ' . substr($index, -1) . ' Input';
197
            discover_sensor($valid['sensor'], 'current', $device, $current_oid, $in_index, $type, $descr, $divisor, 0, null, null, null, null, $current);
198
        }
199
    }
200
}
201
    unset($index);
202
    unset($data);
203
foreach ($oids as $index => $data) {
204
    $type = 'apcUPS';
205
    $descr = 'Phase ' . substr($index, -1) . ' Output';
206
    if (isset($data['upsHighPrecOutputCurrent'])) {
207
        $current_oid = '.1.3.6.1.4.1.318.1.1.1.4.3.4.' . $index;
208
        $divisor = 10;
209
        $current = $data['upsHighPrecOutputCurrent'] / $divisor;
210
    } else {
211
        $current_oid = '.1.3.6.1.4.1.318.1.1.1.9.3.3.1.4.' . $index;
212
        $divisor = 10;
213
        $current = $data['upsPhaseOutputCurrent'] / $divisor;
214
    }
215
    if ($current >= -1) {
216
        discover_sensor($valid['sensor'], 'current', $device, $current_oid, $index, $type, $descr, $divisor, 1, null, null, null, null, $current);
217
    }
218
}
219
    unset($index);
220
    unset($data);
221