1<?php 2/** 3 * netagent2.inc.php 4 * 5 * -Description- 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <https://www.gnu.org/licenses/>. 19 * 20 * @link https://www.librenms.org 21 * @copyright 2016 Tony Murray 22 * @author Tony Murray <murraytony@gmail.com> 23 * 3 Phase support extension 24 * @copyright 2018 Mikael Sipilainen 25 * @author Mikael Sipilainen <mikael.sipilainen@gmail.com> 26 */ 27$ups_state_oid = '.1.3.6.1.4.1.935.1.1.1.4.1.1.0'; 28$ups_state = snmp_get($device, $ups_state_oid, '-Oqv'); 29 30if (! empty($ups_state) || $ups_state == 0) { 31 // UPS state OID (Value : 0-1 Unknown, 2 On Line, 3 On Battery, 4 On Boost, 5 Sleeping, 6 On Bypass, 7 Rebooting, 8 Standby, 9 On Buck ) 32 $state_name = 'netagent2upsstate'; 33 $states = [ 34 ['value' => 0, 'generic' => 3, 'graph' => 0, 'descr' => 'unknown'], 35 ['value' => 1, 'generic' => 3, 'graph' => 0, 'descr' => 'unknown'], 36 ['value' => 2, 'generic' => 0, 'graph' => 0, 'descr' => 'OnLine'], 37 ['value' => 3, 'generic' => 1, 'graph' => 0, 'descr' => 'OnBattery'], 38 ['value' => 4, 'generic' => 0, 'graph' => 0, 'descr' => 'OnBoost'], 39 ['value' => 5, 'generic' => 1, 'graph' => 0, 'descr' => 'Sleeping'], 40 ['value' => 6, 'generic' => 0, 'graph' => 0, 'descr' => 'OnBypass'], 41 ['value' => 7, 'generic' => 1, 'graph' => 0, 'descr' => 'Rebooting'], 42 ['value' => 8, 'generic' => 0, 'graph' => 0, 'descr' => 'Standby'], 43 ['value' => 9, 'generic' => 0, 'graph' => 0, 'descr' => 'OnBuck'], 44 ]; 45 create_state_index($state_name, $states); 46 47 $index = 0; 48 $limit = 10; 49 $warnlimit = null; 50 $lowlimit = null; 51 $lowwarnlimit = null; 52 $divisor = 1; 53 $state = $ups_state / $divisor; 54 $descr = 'UPS state'; 55 56 discover_sensor($valid['sensor'], 'state', $device, $ups_state_oid, $index, $state_name, $descr, $divisor, 1, $lowlimit, $lowwarnlimit, $warnlimit, $limit, $state); 57 create_sensor_to_state_index($device, $state_name, $index); 58} 59 60// Detect type of UPS (Signle-Phase/3 Phase) 61// Number of input lines 62$upsInputNumLines_oid = '.1.3.6.1.2.1.33.1.3.2.0'; 63$in_phaseNum = snmp_get($device, $upsInputNumLines_oid, '-Oqv'); 64 65// 3 Phase system states 66if ($in_phaseNum == '3') { 67 // In And Out 68 $ups_state_oid = '.1.3.6.1.4.1.935.1.1.1.8.5.4.0'; 69 $ups_state = snmp_get($device, $ups_state_oid, '-Oqv'); 70 71 if (! empty($ups_state) || $ups_state == 0) { 72 $state_name = 'upsThreePhaseDCandRectifierStatusInAndOut'; 73 $states = [ 74 ['value' => 2, 'generic' => 3, 'graph' => 0, 'descr' => 'threeInOneOut'], 75 ['value' => 3, 'generic' => 3, 'graph' => 0, 'descr' => 'threeInThreeOut'], 76 ]; 77 create_state_index($state_name, $states); 78 79 $index = 0; 80 $limit = 10; 81 $warnlimit = null; 82 $lowlimit = null; 83 $lowwarnlimit = null; 84 $divisor = 1; 85 $state = $ups_state / $divisor; 86 $descr = 'In And Out'; 87 88 discover_sensor($valid['sensor'], 'state', $device, $ups_state_oid, $index, $state_name, $descr, $divisor, 1, $lowlimit, $lowwarnlimit, $warnlimit, $limit, $state); 89 create_sensor_to_state_index($device, $state_name, $index); 90 } 91 92 // Back Status 93 $ups_state_oid = '.1.3.6.1.4.1.935.1.1.1.8.5.5.0'; 94 $ups_state = snmp_get($device, $ups_state_oid, '-Oqv'); 95 96 if (! empty($ups_state) || $ups_state == 0) { 97 $state_name = 'upsThreePhaseDCandRectifierStatusBatteryStatus'; 98 $states = [ 99 ['value' => 4, 'generic' => 1, 'graph' => 0, 'descr' => 'backup'], 100 ['value' => 5, 'generic' => 0, 'graph' => 0, 'descr' => 'acnormal'], 101 ]; 102 create_state_index($state_name, $states); 103 104 $index = 0; 105 $limit = 10; 106 $warnlimit = null; 107 $lowlimit = null; 108 $lowwarnlimit = null; 109 $divisor = 1; 110 $state = $ups_state / $divisor; 111 $descr = 'Back Status'; 112 113 discover_sensor($valid['sensor'], 'state', $device, $ups_state_oid, $index, $state_name, $descr, $divisor, 1, $lowlimit, $lowwarnlimit, $warnlimit, $limit, $state); 114 create_sensor_to_state_index($device, $state_name, $index); 115 } 116 117 // Charge Status 118 $ups_state_oid = '.1.3.6.1.4.1.935.1.1.1.8.5.6.0'; 119 $ups_state = snmp_get($device, $ups_state_oid, '-Oqv'); 120 121 if (! empty($ups_state) || $ups_state == 0) { 122 $state_name = 'upsThreePhaseDCandRectifierStatusChargeStatus'; 123 $states = [ 124 ['value' => 6, 'generic' => 0, 'graph' => 0, 'descr' => 'boost'], 125 ['value' => 7, 'generic' => 0, 'graph' => 0, 'descr' => 'float'], 126 ['value' => 16, 'generic' => 2, 'graph' => 0, 'descr' => 'no'], 127 ]; 128 create_state_index($state_name, $states); 129 130 $index = 0; 131 $limit = 10; 132 $warnlimit = null; 133 $lowlimit = null; 134 $lowwarnlimit = null; 135 $divisor = 1; 136 $state = $ups_state / $divisor; 137 $descr = 'Charge Status'; 138 139 discover_sensor($valid['sensor'], 'state', $device, $ups_state_oid, $index, $state_name, $descr, $divisor, 1, $lowlimit, $lowwarnlimit, $warnlimit, $limit, $state); 140 create_sensor_to_state_index($device, $state_name, $index); 141 } 142 143 // Bypass braker status 144 $ups_state_oid = '.1.3.6.1.4.1.935.1.1.1.8.6.2.0'; 145 $ups_state = snmp_get($device, $ups_state_oid, '-Oqv'); 146 147 if (! empty($ups_state) || $ups_state == 0) { 148 $state_name = 'upsThreePhaseUPSStatusManualBypassBreaker'; 149 $states = [ 150 ['value' => 8, 'generic' => 1, 'graph' => 0, 'descr' => 'close'], 151 ['value' => 9, 'generic' => 0, 'graph' => 0, 'descr' => 'open'], 152 ]; 153 create_state_index($state_name, $states); 154 155 $index = 0; 156 $limit = 10; 157 $warnlimit = null; 158 $lowlimit = null; 159 $lowwarnlimit = null; 160 $divisor = 1; 161 $state = $ups_state / $divisor; 162 $descr = 'Breaker Status'; 163 164 discover_sensor($valid['sensor'], 'state', $device, $ups_state_oid, $index, $state_name, $descr, $divisor, 1, $lowlimit, $lowwarnlimit, $warnlimit, $limit, $state); 165 create_sensor_to_state_index($device, $state_name, $index); 166 } 167 168 // AC Status 169 $ups_state_oid = '.1.3.6.1.4.1.935.1.1.1.8.6.3.0'; 170 $ups_state = snmp_get($device, $ups_state_oid, '-Oqv'); 171 172 if (! empty($ups_state) || $ups_state == 0) { 173 $state_name = 'upsThreePhaseUPSStatusACStatus'; 174 $states = [ 175 ['value' => 10, 'generic' => 0, 'graph' => 0, 'descr' => 'normal'], 176 ['value' => 11, 'generic' => 2, 'graph' => 0, 'descr' => 'abnormal'], 177 ]; 178 create_state_index($state_name, $states); 179 180 $index = 0; 181 $limit = 10; 182 $warnlimit = null; 183 $lowlimit = null; 184 $lowwarnlimit = null; 185 $divisor = 1; 186 $state = $ups_state / $divisor; 187 $descr = 'AC status'; 188 189 discover_sensor($valid['sensor'], 'state', $device, $ups_state_oid, $index, $state_name, $descr, $divisor, 1, $lowlimit, $lowwarnlimit, $warnlimit, $limit, $state); 190 create_sensor_to_state_index($device, $state_name, $index); 191 } 192 193 // Common State - Inverter active, Rectifier Operating 194 $states = [ 195 ['value' => 14, 'generic' => 0, 'graph' => 0, 'descr' => 'yes'], 196 ['value' => 16, 'generic' => 2, 'graph' => 0, 'descr' => 'no'], 197 ]; 198 199 // Inverter active 200 $ups_state_oid = '.1.3.6.1.4.1.935.1.1.1.8.6.5.0'; 201 $ups_state = snmp_get($device, $ups_state_oid, '-Oqv'); 202 203 if (! empty($ups_state) || $ups_state == 0) { 204 $state_name = 'upsThreePhaseUPSStatusInverterOperating'; 205 create_state_index($state_name, $states); 206 207 $index = 0; 208 $limit = 10; 209 $warnlimit = null; 210 $lowlimit = null; 211 $lowwarnlimit = null; 212 $divisor = 1; 213 $state = $ups_state / $divisor; 214 $descr = 'Inverter Operating'; 215 216 discover_sensor($valid['sensor'], 'state', $device, $ups_state_oid, $index, $state_name, $descr, $divisor, 1, $lowlimit, $lowwarnlimit, $warnlimit, $limit, $state); 217 create_sensor_to_state_index($device, $state_name, $index); 218 } 219 220 // Rectifier Operating 221 $ups_state_oid = '.1.3.6.1.4.1.935.1.1.1.8.5.7.0'; 222 $ups_state = snmp_get($device, $ups_state_oid, '-Oqv'); 223 224 if (! empty($ups_state) || $ups_state == 0) { 225 $state_name = 'upsThreePhaseDCandRectifierStatusRecOperating'; 226 create_state_index($state_name, $states); 227 228 $index = 0; 229 $limit = 10; 230 $warnlimit = null; 231 $lowlimit = null; 232 $lowwarnlimit = null; 233 $divisor = 1; 234 $state = $ups_state / $divisor; 235 $descr = 'Rectifier Operating'; 236 237 discover_sensor($valid['sensor'], 'state', $device, $ups_state_oid, $index, $state_name, $descr, $divisor, 1, $lowlimit, $lowwarnlimit, $warnlimit, $limit, $state); 238 create_sensor_to_state_index($device, $state_name, $index); 239 } 240 241 // Switch Mode 242 $ups_state_oid = '.1.3.6.1.4.1.935.1.1.1.8.6.4.0'; 243 $ups_state = snmp_get($device, $ups_state_oid, '-Oqv'); 244 245 if (! empty($ups_state) || $ups_state == 0) { 246 $state_name = 'upsThreePhaseUPSStaticSwitchMode'; 247 $states = [ 248 ['value' => 12, 'generic' => 0, 'graph' => 0, 'descr' => 'invermode'], 249 ['value' => 13, 'generic' => 1, 'graph' => 0, 'descr' => 'bypassmode'], 250 ]; 251 create_state_index($state_name, $states); 252 253 $index = 0; 254 $limit = 10; 255 $warnlimit = null; 256 $lowlimit = null; 257 $lowwarnlimit = null; 258 $divisor = 1; 259 $state = $ups_state / $divisor; 260 $descr = 'Switch Mode'; 261 262 discover_sensor($valid['sensor'], 'state', $device, $ups_state_oid, $index, $state_name, $descr, $divisor, 1, $lowlimit, $lowwarnlimit, $warnlimit, $limit, $state); 263 create_sensor_to_state_index($device, $state_name, $index); 264 } 265 266 // Common State - Rectifier Rotation Error, Bypass Status and Short Circuit 267 $states = [ 268 ['value' => 14, 'generic' => 2, 'graph' => 0, 'descr' => 'yes'], 269 ['value' => 16, 'generic' => 0, 'graph' => 0, 'descr' => 'no'], 270 ]; 271 272 // Rectifier Rotation Error 273 $ups_state_oid = '.1.3.6.1.4.1.935.1.1.1.8.5.1.0'; 274 $ups_state = snmp_get($device, $ups_state_oid, '-Oqv'); 275 276 if (! empty($ups_state) || $ups_state == 0) { 277 $state_name = 'upsThreePhaseDCandRectifierStatusRecRotError'; 278 create_state_index($state_name, $states); 279 280 $index = 0; 281 $limit = 10; 282 $warnlimit = null; 283 $lowlimit = null; 284 $lowwarnlimit = null; 285 $divisor = 1; 286 $state = $ups_state / $divisor; 287 $descr = 'Rectifier Rotation Error'; 288 289 discover_sensor($valid['sensor'], 'state', $device, $ups_state_oid, $index, $state_name, $descr, $divisor, 1, $lowlimit, $lowwarnlimit, $warnlimit, $limit, $state); 290 create_sensor_to_state_index($device, $state_name, $index); 291 } 292 293 // Bypass Status 294 $ups_state_oid = '.1.3.6.1.4.1.935.1.1.1.8.6.1.0'; 295 $ups_state = snmp_get($device, $ups_state_oid, '-Oqv'); 296 297 if (! empty($ups_state) || $ups_state == 0) { 298 $state_name = 'upsThreePhaseUPSStatusBypassFreqFail'; 299 create_state_index($state_name, $states); 300 301 $index = 0; 302 $limit = 10; 303 $warnlimit = null; 304 $lowlimit = null; 305 $lowwarnlimit = null; 306 $divisor = 1; 307 $state = $ups_state / $divisor; 308 $descr = 'Bypass freq. fail'; 309 310 discover_sensor($valid['sensor'], 'state', $device, $ups_state_oid, $index, $state_name, $descr, $divisor, 1, $lowlimit, $lowwarnlimit, $warnlimit, $limit, $state); 311 create_sensor_to_state_index($device, $state_name, $index); 312 } 313 314 // Short Circuit 315 $ups_state_oid = '.1.3.6.1.4.1.935.1.1.1.8.7.7.0'; 316 $ups_state = snmp_get($device, $ups_state_oid, '-Oqv'); 317 318 if (! empty($ups_state) || $ups_state == 0) { 319 $state_name = 'upsThreePhaseFaultStatusShortCircuit'; 320 create_state_index($state_name, $states); 321 322 $index = 0; 323 $limit = 10; 324 $warnlimit = null; 325 $lowlimit = null; 326 $lowwarnlimit = null; 327 $divisor = 1; 328 $state = $ups_state / $divisor; 329 $descr = 'Short Circuit'; 330 331 discover_sensor($valid['sensor'], 'state', $device, $ups_state_oid, $index, $state_name, $descr, $divisor, 1, $lowlimit, $lowwarnlimit, $warnlimit, $limit, $state); 332 create_sensor_to_state_index($device, $state_name, $index); 333 } 334} 335