1<?php
2/**
3 * fs-nmu.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  2020 Jozef Rebjak
22 * @author     Jozef Rebjak <jozefrebjak@icloud.com>
23 */
24$power1 = snmp_get($device, 'power1State.0', '-Ovqe', 'OAP-NMU');
25$power2 = snmp_get($device, 'power2State.0', '-Ovqe', 'OAP-NMU');
26$fan = snmp_get($device, 'fanState.0', '-Ovqe', 'OAP-NMU');
27$oid_power1 = '.1.3.6.1.4.1.40989.10.16.20.11.0';
28$oid_power2 = '.1.3.6.1.4.1.40989.10.16.20.12.0';
29$oid_fan = '.1.3.6.1.4.1.40989.10.16.20.10.0';
30$index = '0';
31
32// Power 1 State
33if (is_numeric($power1)) {
34    $state_name = 'power1State';
35    $states = [
36        ['value' => 0, 'generic' => 2, 'graph' => 0, 'descr' => 'off'],
37        ['value' => 1, 'generic' => 0, 'graph' => 0, 'descr' => 'on'],
38    ];
39    create_state_index($state_name, $states);
40
41    $descr = 'Power 1 State';
42    discover_sensor($valid['sensor'], 'state', $device, $oid_power1, $index, $state_name, $descr, 1, 1, null, null, null, null, $power1, 'snmp', $index);
43
44    create_sensor_to_state_index($device, $state_name, $index);
45}
46
47// Power 2 State
48if (is_numeric($power2)) {
49    $state_name = 'power2State';
50    $states = [
51        ['value' => 0, 'generic' => 2, 'graph' => 0, 'descr' => 'off'],
52        ['value' => 1, 'generic' => 0, 'graph' => 0, 'descr' => 'on'],
53    ];
54    create_state_index($state_name, $states);
55
56    $descr = 'Power 2 State';
57    discover_sensor($valid['sensor'], 'state', $device, $oid_power2, $index, $state_name, $descr, 1, 1, null, null, null, null, $power2, 'snmp', $index);
58
59    create_sensor_to_state_index($device, $state_name, $index);
60}
61
62// Fan State
63if (is_numeric($fan)) {
64    $state_name = 'fanState';
65    $states = [
66        ['value' => 0, 'generic' => 2, 'graph' => 0, 'descr' => 'off'],
67        ['value' => 1, 'generic' => 0, 'graph' => 0, 'descr' => 'on'],
68    ];
69    create_state_index($state_name, $states);
70
71    $descr = 'Fan State';
72    discover_sensor($valid['sensor'], 'state', $device, $oid_fan, $index, $state_name, $descr, 1, 1, null, null, null, null, $fan, 'snmp', $index);
73
74    create_sensor_to_state_index($device, $state_name, $index);
75}
76