1<?php 2/** 3 * aos-emu2.inc.php 4 * 5 * LibreNMS sensors state discovery module for APC EMU2 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 2018 Ben Gibbons 22 * @author Ben Gibbons <axemann@gmail.com> 23 */ 24 25 // Input Contact discovery 26 27$contacts['emu2_contacts'] = snmpwalk_group($device, 'emsInputContactStatusEntry', 'PowerNet-MIB'); 28 29foreach ($contacts['emu2_contacts'] as $id => $contact) { 30 $index = $contact['emsInputContactStatusInputContactIndex']; 31 $oid = '.1.3.6.1.4.1.318.1.1.10.3.14.1.1.3.' . $index; 32 $descr = $contact['emsInputContactStatusInputContactName']; 33 $currentstate = $contact['emsInputContactStatusInputContactState']; 34 $normalstate = $contact['emsInputContactStatusInputContactNormalState']; 35 if (is_array($contacts['emu2_contacts']) && $normalstate == '1') { 36 $state_name = 'emsInputContactNormalState_NC'; 37 $states = [ 38 ['value' => 1, 'generic' => 0, 'graph' => 0, 'descr' => 'Closed'], 39 ['value' => 2, 'generic' => 1, 'graph' => 0, 'descr' => 'Open'], 40 ]; 41 create_state_index($state_name, $states); 42 } elseif (is_array($contacts['emu2_contacts']) && $normalstate == '2') { 43 $state_name = 'emsInputContactNormalState_NO'; 44 $states = [ 45 ['value' => 1, 'generic' => 1, 'graph' => 0, 'descr' => 'Closed'], 46 ['value' => 2, 'generic' => 0, 'graph' => 0, 'descr' => 'Open'], 47 ]; 48 create_state_index($state_name, $states); 49 } 50 51 discover_sensor($valid['sensor'], 'state', $device, $oid, $index, $state_name, $descr, 1, 1, null, null, null, null, $currentstate, 'snmp', $index); 52 create_sensor_to_state_index($device, $state_name, $index); 53} 54 55// Output Relay discovery 56 57$relays['emu2_relays'] = snmpwalk_group($device, 'emsOutputRelayStatusEntry', 'PowerNet-MIB'); 58 59foreach ($relays['emu2_relays'] as $id => $relay) { 60 $index = $relay['emsOutputRelayStatusOutputRelayIndex']; 61 $oid = '.1.3.6.1.4.1.318.1.1.10.3.15.1.1.3.' . $index; 62 $descr = $relay['emsOutputRelayStatusOutputRelayName']; 63 $currentstate = $relay['emsOutputRelayStatusOutputRelayState']; 64 $normalstate = $relay['emsOutputRelayStatusOutputRelayNormalState']; 65 if (is_array($relays['emu2_relays']) && $normalstate == '1') { 66 $state_name = 'emsOutputRelayNormalState_NC'; 67 $states = [ 68 ['value' => 1, 'generic' => 0, 'graph' => 0, 'descr' => 'Closed'], 69 ['value' => 2, 'generic' => 1, 'graph' => 0, 'descr' => 'Open'], 70 ]; 71 create_state_index($state_name, $states); 72 } elseif (is_array($relays['emu2_relays']) && $normalstate == '2') { 73 $state_name = 'emsOutputRelayNormalState_NO'; 74 $states = [ 75 ['value' => 1, 'generic' => 1, 'graph' => 0, 'descr' => 'Closed'], 76 ['value' => 2, 'generic' => 0, 'graph' => 0, 'descr' => 'Open'], 77 ]; 78 create_state_index($state_name, $states); 79 } 80 81 discover_sensor($valid['sensor'], 'state', $device, $oid, $index, $state_name, $descr, 1, 1, null, null, null, null, $currentstate, 'snmp', $index); 82 create_sensor_to_state_index($device, $state_name, $index); 83} 84 85// Outlet discovery 86 87$outlets['emu2_outlets'] = snmpwalk_group($device, 'emsOutletStatusEntry', 'PowerNet-MIB'); 88 89foreach ($outlets['emu2_outlets'] as $id => $outlet) { 90 $index = $outlet['emsOutletStatusOutletIndex']; 91 $oid = '.1.3.6.1.4.1.318.1.1.10.3.16.1.1.3.' . $index; 92 $descr = $outlet['emsOutletStatusOutletName']; 93 $currentstate = $outlet['emsOutletStatusOutletState']; 94 $normalstate = $outlet['emsOutletStatusOutletNormalState']; 95 if (is_array($outlets['emu2_outlets']) && $normalstate == '1') { 96 $state_name = 'emsOutletNormalState_ON'; 97 $states = [ 98 ['value' => 1, 'generic' => 0, 'graph' => 0, 'descr' => 'On'], 99 ['value' => 2, 'generic' => 1, 'graph' => 0, 'descr' => 'Off'], 100 ]; 101 create_state_index($state_name, $states); 102 } elseif (is_array($outlets['emu2_outlets']) && $normalstate == '2') { 103 $state_name = 'emsOutletNormalState_OFF'; 104 $states = [ 105 ['value' => 1, 'generic' => 1, 'graph' => 0, 'descr' => 'On'], 106 ['value' => 2, 'generic' => 0, 'graph' => 0, 'descr' => 'Off'], 107 ]; 108 create_state_index($state_name, $states); 109 } 110 111 discover_sensor($valid['sensor'], 'state', $device, $oid, $index, $state_name, $descr, 1, 1, null, null, null, null, $currentstate, 'snmp', $index); 112 create_sensor_to_state_index($device, $state_name, $index); 113} 114