1<?php 2/** 3 * enlogic-pdu.inc.php 4 * 5 * LibreNMS sensors state discovery module for enLOGIC PDU 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 2017 Neil Lathwood 22 * @author Neil Lathwood <gh+n@laf.io> 23 */ 24foreach ($pre_cache['enlogic_pdu_status'] as $index => $data) { 25 if (is_array($data)) { 26 $oid = '.1.3.6.1.4.1.38446.1.2.4.1.3.' . $index; 27 $state_name = 'pduUnitStatusLoadState'; 28 $current = $data['pduUnitStatusLoadState']; 29 30 //Create State Translation 31 $states = [ 32 ['value' => 1, 'generic' => 2, 'graph' => 1, 'descr' => 'upperCritical'], 33 ['value' => 2, 'generic' => 1, 'graph' => 1, 'descr' => 'upperWarning'], 34 ['value' => 3, 'generic' => 1, 'graph' => 1, 'descr' => 'lowerWarning'], 35 ['value' => 4, 'generic' => 2, 'graph' => 1, 'descr' => 'lowerCritical'], 36 ['value' => 5, 'generic' => 0, 'graph' => 1, 'descr' => 'normal'], 37 ]; 38 create_state_index($state_name, $states); 39 40 $descr = "Load state #$index"; 41 //Discover Sensors 42 discover_sensor($valid['sensor'], 'state', $device, $oid, $index, $state_name, $descr, 1, 1, null, null, null, null, $current); 43 //Create Sensor To State Index 44 create_sensor_to_state_index($device, $state_name, $index); 45 } 46} 47 48foreach ($pre_cache['enlogic_pdu_input'] as $index => $data) { 49 if (is_array($data)) { 50 $oid = '.1.3.6.1.4.1.38446.1.3.4.1.3.' . $index; 51 $tmp_index = $state_name . '.' . $index; 52 $state_name = 'pduInputPhaseStatusCurrentState'; 53 $current = $data['pduInputPhaseStatusCurrentState']; 54 $descr = "Current state #$index"; 55 if (! is_numeric($current)) { 56 $states = [ 57 ['value' => 1, 'generic' => 2, 'graph' => 1, 'descr' => 'upperCritical'], 58 ['value' => 2, 'generic' => 1, 'graph' => 1, 'descr' => 'upperWarning'], 59 ['value' => 3, 'generic' => 1, 'graph' => 1, 'descr' => 'lowerWarning'], 60 ['value' => 4, 'generic' => 2, 'graph' => 1, 'descr' => 'lowerCritical'], 61 ['value' => 5, 'generic' => 0, 'graph' => 1, 'descr' => 'normal'], 62 ]; 63 create_state_index($state_name, $states); 64 65 //Discover Sensors 66 discover_sensor($valid['sensor'], 'state', $device, $oid, $tmp_index, $state_name, $descr, 1, 1, null, null, null, null, $current); 67 //Create Sensor To State Index 68 create_sensor_to_state_index($device, $state_name, $tmp_index); 69 } 70 71 $oid = '.1.3.6.1.4.1.38446.1.3.4.1.4.' . $index; 72 $tmp_index = $state_name . '.' . $index; 73 $state_name = 'pduInputPhaseStatusVoltageState'; 74 $current = $data['pduInputPhaseStatusVoltageState']; 75 $descr = "Voltage state #$index"; 76 if (! is_numeric($current)) { 77 $states = [ 78 ['value' => 1, 'generic' => 2, 'graph' => 1, 'descr' => 'upperCritical'], 79 ['value' => 2, 'generic' => 1, 'graph' => 1, 'descr' => 'upperWarning'], 80 ['value' => 3, 'generic' => 1, 'graph' => 1, 'descr' => 'lowerWarning'], 81 ['value' => 4, 'generic' => 2, 'graph' => 1, 'descr' => 'lowerCritical'], 82 ['value' => 5, 'generic' => 0, 'graph' => 1, 'descr' => 'normal'], 83 ]; 84 create_state_index($state_name, $states); 85 86 //Discover Sensors 87 discover_sensor($valid['sensor'], 'state', $device, $oid, $tmp_index, $state_name, $descr, 1, 1, null, null, null, null, $current); 88 //Create Sensor To State Index 89 create_sensor_to_state_index($device, $state_name, $tmp_index); 90 } 91 } 92} 93 94foreach ($pre_cache['enlogic_pdu_circuit'] as $index => $data) { 95 if (is_array($data)) { 96 $oid = '.1.3.6.1.4.1.38446.1.4.4.1.4.' . $index; 97 $state_name = 'pduCircuitBreakerStatusLoadState'; 98 $current = $data['pduCircuitBreakerStatusLoadState']; 99 100 if (! is_numeric($current)) { 101 //Create State Translation 102 $states = [ 103 ['value' => 1, 'generic' => 2, 'graph' => 1, 'descr' => 'upperCritical'], 104 ['value' => 2, 'generic' => 1, 'graph' => 1, 'descr' => 'upperWarning'], 105 ['value' => 3, 'generic' => 1, 'graph' => 1, 'descr' => 'lowerWarning'], 106 ['value' => 4, 'generic' => 2, 'graph' => 1, 'descr' => 'lowerCritical'], 107 ['value' => 5, 'generic' => 0, 'graph' => 1, 'descr' => 'normal'], 108 ]; 109 create_state_index($state_name, $states); 110 111 $descr = "Circuit breaker state {$data['pduCircuitBreakerLabel']}"; 112 //Discover Sensors 113 discover_sensor($valid['sensor'], 'state', $device, $oid, $index, $state_name, $descr, 1, 1, null, null, null, null, $current); 114 //Create Sensor To State Index 115 create_sensor_to_state_index($device, $state_name, $index); 116 } 117 } 118} 119 120unset( 121 $index, 122 $data 123); 124