Skip to content

Commit 10b57d2

Browse files
authored
[ipoman] drop precache, app(sensor-discovery) (librenms#17707)
* [ipoman] drop precache, app(sensor-discovery) * styleci
1 parent c55a9bb commit 10b57d2

File tree

7 files changed

+258
-111
lines changed

7 files changed

+258
-111
lines changed
Lines changed: 71 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,81 @@
11
<?php
22

3-
echo ' IPOMANII-MIB ';
3+
/*
4+
* @author Peca Nesovanovic <[email protected]>
5+
*/
46

5-
$oids_in = [];
6-
$oids_out = [];
7+
// pre-cache
8+
$oidsOut = SnmpQuery::cache()->hideMib()->walk([
9+
'IPOMANII-MIB::outletConfigDesc',
10+
'IPOMANII-MIB::outletConfigLocation',
11+
])->table(1);
12+
$oidsIn = SnmpQuery::cache()->hideMib()->walk([
13+
'IPOMANII-MIB::inletConfigDesc',
14+
])->table(1);
715

8-
d_echo('inletConfigCurrentHigh ');
9-
$oids_in = snmpwalk_cache_multi_oid($device, 'inletConfigCurrentHigh', $oids_in, 'IPOMANII-MIB');
10-
d_echo('inletStatusCurrent ');
11-
$oids_in = snmpwalk_cache_multi_oid($device, 'inletStatusCurrent', $oids_in, 'IPOMANII-MIB');
12-
d_echo('outletConfigCurrentHigh ');
13-
$oids_out = snmpwalk_cache_multi_oid($device, 'outletConfigCurrentHigh', $oids_out, 'IPOMANII-MIB');
14-
d_echo('outletStatusCurrent ');
15-
$oids_out = snmpwalk_cache_multi_oid($device, 'outletStatusCurrent', $oids_out, 'IPOMANII-MIB');
16+
//data
17+
$oidsCurrIn = SnmpQuery::hideMib()->walk([
18+
'IPOMANII-MIB::inletConfigCurrentHigh',
19+
'IPOMANII-MIB::inletStatusCurrent',
20+
])->table(1);
21+
$oidsCurrOut = SnmpQuery::hideMib()->walk([
22+
'IPOMANII-MIB::outletConfigCurrentHigh',
23+
'IPOMANII-MIB::outletStatusCurrent',
24+
])->table(1);
1625

17-
if (is_array($oids_in)) {
18-
foreach ($oids_in as $index => $entry) {
19-
$cur_oid = '.1.3.6.1.4.1.2468.1.4.2.1.3.1.3.1.3.' . $index;
20-
$divisor = 1000;
21-
$descr = (trim($pre_cache['ipoman']['in'][$index]['inletConfigDesc'], '"') != '' ? trim($pre_cache['ipoman']['in'][$index]['inletConfigDesc'], '"') : "Inlet $index");
22-
$current = ($entry['inletStatusCurrent'] / $divisor);
23-
$high_limit = ($entry['inletConfigCurrentHigh'] / 10);
26+
foreach ($oidsCurrIn as $index => $entry) {
27+
$oid = '.1.3.6.1.4.1.2468.1.4.2.1.3.1.3.1.3.' . $index;
28+
$divisor = 1000;
29+
$descr = (trim($oidsIn[$index]['inletConfigDesc'], '"') != '' ? trim($oidsIn[$index]['inletConfigDesc'], '"') : "Inlet $index");
30+
$value = ($entry['inletStatusCurrent'] / $divisor);
31+
$high_limit = ($entry['inletConfigCurrentHigh'] / 10);
2432

25-
discover_sensor(null, 'current', $device, $cur_oid, '1.3.1.3.' . $index, 'ipoman', $descr, $divisor, '1', null, null, null, $high_limit, $current);
26-
// FIXME: iPoMan 1201 also says it has 2 inlets, at least until firmware 1.06 - wtf?
27-
}
33+
// FIXME: iPoMan 1201 also says it has 2 inlets, at least until firmware 1.06 - wtf?
34+
app('sensor-discovery')->discover(new \App\Models\Sensor([
35+
'poller_type' => 'snmp',
36+
'sensor_class' => 'current',
37+
'sensor_oid' => $oid,
38+
'sensor_index' => '1.3.1.3.' . $index,
39+
'sensor_type' => 'ipoman',
40+
'sensor_descr' => $descr,
41+
'sensor_divisor' => $divisor,
42+
'sensor_multiplier' => 1,
43+
'sensor_limit_low' => null,
44+
'sensor_limit_low_warn' => null,
45+
'sensor_limit_warn' => null,
46+
'sensor_limit' => $high_limit,
47+
'sensor_current' => $value,
48+
'entPhysicalIndex' => null,
49+
'entPhysicalIndex_measured' => null,
50+
'user_func' => null,
51+
'group' => null,
52+
]));
2853
}
2954

30-
if (is_array($oids_out)) {
31-
foreach ($oids_out as $index => $entry) {
32-
$cur_oid = '.1.3.6.1.4.1.2468.1.4.2.1.3.2.3.1.3.' . $index;
33-
$divisor = 1000;
34-
$descr = (trim($pre_cache['ipoman']['out'][$index]['outletConfigDesc'], '"') != '' ? trim($pre_cache['ipoman']['out'][$index]['outletConfigDesc'], '"') : "Output $index");
35-
$current = ($entry['outletStatusCurrent'] / $divisor);
36-
$high_limit = ($entry['outletConfigCurrentHigh'] / 10);
55+
foreach ($oidsCurrOut as $index => $entry) {
56+
$oid = '.1.3.6.1.4.1.2468.1.4.2.1.3.2.3.1.3.' . $index;
57+
$divisor = 1000;
58+
$descr = (trim($oidsOut[$index]['outletConfigDesc'], '"') != '' ? trim($oidsOut[$index]['outletConfigDesc'], '"') : "Output $index");
59+
$value = ($entry['outletStatusCurrent'] / $divisor);
60+
$high_limit = ($entry['outletConfigCurrentHigh'] / 10);
3761

38-
discover_sensor(null, 'current', $device, $cur_oid, '2.3.1.3.' . $index, 'ipoman', $descr, $divisor, '1', null, null, null, $high_limit, $current);
39-
}
62+
app('sensor-discovery')->discover(new \App\Models\Sensor([
63+
'poller_type' => 'snmp',
64+
'sensor_class' => 'current',
65+
'sensor_oid' => $oid,
66+
'sensor_index' => '2.3.1.3.' . $index,
67+
'sensor_type' => 'ipoman',
68+
'sensor_descr' => $descr,
69+
'sensor_divisor' => $divisor,
70+
'sensor_multiplier' => 1,
71+
'sensor_limit_low' => null,
72+
'sensor_limit_low_warn' => null,
73+
'sensor_limit_warn' => null,
74+
'sensor_limit' => $high_limit,
75+
'sensor_current' => $value,
76+
'entPhysicalIndex' => null,
77+
'entPhysicalIndex_measured' => null,
78+
'user_func' => null,
79+
'group' => null,
80+
]));
4081
}
Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,47 @@
11
<?php
22

3-
echo 'IPOMANII-MIB: ';
3+
/*
4+
* @author Peca Nesovanovic <[email protected]>
5+
*/
46

5-
$oids = [];
7+
// pre-cache
8+
$oidsIn = SnmpQuery::cache()->hideMib()->walk([
9+
'IPOMANII-MIB::inletConfigDesc',
10+
])->table(1);
611

7-
d_echo('inletConfigFrequencyHigh ');
8-
$oids = snmpwalk_cache_multi_oid($device, 'inletConfigFrequencyHigh', $oids, 'IPOMANII-MIB');
9-
d_echo('inletConfigFrequencyLow ');
10-
$oids = snmpwalk_cache_multi_oid($device, 'inletConfigFrequencyLow', $oids, 'IPOMANII-MIB');
11-
d_echo('inletStatusFrequency ');
12-
$oids = snmpwalk_cache_multi_oid($device, 'inletStatusFrequency', $oids, 'IPOMANII-MIB');
12+
//data
13+
$oidsFreqIn = SnmpQuery::hideMib()->walk([
14+
'IPOMANII-MIB::inletConfigFrequencyHigh',
15+
'IPOMANII-MIB::inletConfigFrequencyLow',
16+
'IPOMANII-MIB::inletStatusFrequency',
17+
])->table(1);
1318

14-
if (is_array($oids)) {
15-
foreach ($oids as $index => $entry) {
16-
$freq_oid = '.1.3.6.1.4.1.2468.1.4.2.1.3.1.3.1.4.' . $index;
17-
$divisor = 10;
18-
$descr = (trim($pre_cache['ipoman']['in'][$index]['inletConfigDesc'], '"') != '' ? trim($pre_cache['ipoman']['in'][$index]['inletConfigDesc'], '"') : "Inlet $index");
19-
$current = ($entry['inletStatusFrequency'] / 10);
20-
$low_limit = $entry['inletConfigFrequencyLow'];
21-
$high_limit = $entry['inletConfigFrequencyHigh'];
22-
discover_sensor(null, 'frequency', $device, $freq_oid, $index, 'ipoman', $descr, $divisor, '1', $low_limit, null, null, $high_limit, $current);
23-
// FIXME: iPoMan 1201 also says it has 2 inlets, at least until firmware 1.06 - wtf?
24-
}
19+
foreach ($oidsFreqIn as $index => $entry) {
20+
$oid = '.1.3.6.1.4.1.2468.1.4.2.1.3.1.3.1.4.' . $index;
21+
$divisor = 10;
22+
$descr = (trim($oidsIn[$index]['inletConfigDesc'], '"') != '' ? trim($oidsIn[$index]['inletConfigDesc'], '"') : "Inlet $index");
23+
$value = ($entry['inletStatusFrequency'] / 10);
24+
$low_limit = $entry['inletConfigFrequencyLow'];
25+
$high_limit = $entry['inletConfigFrequencyHigh'];
26+
27+
// FIXME: iPoMan 1201 also says it has 2 inlets, at least until firmware 1.06 - wtf?
28+
app('sensor-discovery')->discover(new \App\Models\Sensor([
29+
'poller_type' => 'snmp',
30+
'sensor_class' => 'frequency',
31+
'sensor_oid' => $oid,
32+
'sensor_index' => $index,
33+
'sensor_type' => 'ipoman',
34+
'sensor_descr' => $descr,
35+
'sensor_divisor' => $divisor,
36+
'sensor_multiplier' => 1,
37+
'sensor_limit_low' => $low_limit,
38+
'sensor_limit_low_warn' => null,
39+
'sensor_limit_warn' => null,
40+
'sensor_limit' => $high_limit,
41+
'sensor_current' => $value,
42+
'entPhysicalIndex' => null,
43+
'entPhysicalIndex_measured' => null,
44+
'user_func' => null,
45+
'group' => null,
46+
]));
2547
}
Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,44 @@
11
<?php
22

3+
/*
4+
* @author Peca Nesovanovic <[email protected]>
5+
*/
6+
7+
// pre-cache
8+
$oidsEnv = SnmpQuery::cache()->enumStrings()->hideMib()->walk([
9+
'IPOMANII-MIB::ipmEnvEmd',
10+
])->table(1);
11+
312
// FIXME: EMD "stack" support
413
// FIXME: What to do with IPOMANII-MIB::ipmEnvEmdConfigHumiOffset.0 ?
5-
echo ' IPOMANII-MIB ';
6-
$emd_installed = snmp_get($device, 'IPOMANII-MIB::ipmEnvEmdStatusEmdType.0', '-Oqv');
7-
8-
if ($emd_installed == 'eMD-HT') {
9-
$descr = snmp_get($device, 'IPOMANII-MIB::ipmEnvEmdConfigHumiName.0', '-Oqv');
10-
$current = (snmp_get($device, 'IPOMANII-MIB::ipmEnvEmdStatusHumidity.0', '-Oqv') / 10);
11-
$high_limit = snmp_get($device, 'IPOMANII-MIB::ipmEnvEmdConfigHumiHighSetPoint.0', '-Oqv');
12-
$low_limit = snmp_get($device, 'IPOMANII-MIB::ipmEnvEmdConfigHumiLowSetPoint.0', '-Oqv');
14+
if ($oidsEnv[0]['ipmEnvEmdStatusEmdType'] == 'eMD-HT') {
15+
$descr = $oidsEnv[0]['ipmEnvEmdConfigHumiName'];
16+
$value = $oidsEnv[0]['ipmEnvEmdStatusHumidity'] / 10;
17+
$high_limit = $oidsEnv[0]['ipmEnvEmdConfigHumiHighSetPoint'];
18+
$low_limit = $oidsEnv[0]['ipmEnvEmdConfigHumiLowSetPoint'];
1319

14-
if ($descr != '' && is_numeric($current) && $current > '0') {
15-
$current_oid = '.1.3.6.1.4.1.2468.1.4.2.1.5.1.1.3.0';
20+
if ($descr != '' && is_numeric($value) && $value > '0') {
21+
$oid = '.1.3.6.1.4.1.2468.1.4.2.1.5.1.1.3.0';
1622
$descr = trim(str_replace('"', '', $descr));
1723

18-
discover_sensor(null, 'humidity', $device, $current_oid, '1', 'ipoman', $descr, '10', '1', $low_limit, null, null, $high_limit, $current);
24+
app('sensor-discovery')->discover(new \App\Models\Sensor([
25+
'poller_type' => 'snmp',
26+
'sensor_class' => 'humidity',
27+
'sensor_oid' => $oid,
28+
'sensor_index' => 1,
29+
'sensor_type' => 'ipoman',
30+
'sensor_descr' => $descr,
31+
'sensor_divisor' => 10,
32+
'sensor_multiplier' => 1,
33+
'sensor_limit_low' => $low_limit,
34+
'sensor_limit_low_warn' => null,
35+
'sensor_limit_warn' => null,
36+
'sensor_limit' => $high_limit,
37+
'sensor_current' => $value,
38+
'entPhysicalIndex' => null,
39+
'entPhysicalIndex_measured' => null,
40+
'user_func' => null,
41+
'group' => null,
42+
]));
1943
}
2044
}
Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
11
<?php
22

3-
echo ' IPOMANII-MIB ';
3+
/*
4+
* @author Peca Nesovanovic <[email protected]>
5+
*/
46

5-
$oids_out = [];
7+
// pre-cache
8+
$oidsOut = SnmpQuery::cache()->hideMib()->walk([
9+
'IPOMANII-MIB::outletConfigDesc',
10+
'IPOMANII-MIB::outletConfigLocation',
11+
])->table(1);
612

7-
d_echo('outletStatusKwatt ');
8-
$oids_out = snmpwalk_cache_multi_oid($device, 'outletStatusKwatt', $oids_out, 'IPOMANII-MIB');
13+
//data
14+
$oidsPowOut = SnmpQuery::hideMib()->walk([
15+
'IPOMANII-MIB::outletStatusKwatt',
16+
])->table(1);
917

10-
if (is_array($oids_out)) {
11-
foreach ($oids_out as $index => $entry) {
12-
$power_consumed_oid = '.1.3.6.1.4.1.2468.1.4.2.1.3.2.3.1.4.' . $index;
13-
$divisor = 1000;
14-
$descr = (trim($pre_cache['ipoman']['out'][$index]['outletConfigDesc'], '"') != '' ? trim($pre_cache['ipoman']['out'][$index]['outletConfigDesc'], '"') : "Output $index");
15-
discover_sensor(null, 'power_consumed', $device, $power_consumed_oid, $power_consumed_oid, 'ipoman', $descr, $divisor, 1, 0, null, null, 0);
16-
}
18+
foreach ($oidsPowOut as $index => $entry) {
19+
$oid = '.1.3.6.1.4.1.2468.1.4.2.1.3.2.3.1.4.' . $index;
20+
$divisor = 1000;
21+
$descr = (trim($oidsOut[$index]['outletConfigDesc'], '"') != '' ? trim($oidsOut[$index]['outletConfigDesc'], '"') : "Output $index");
22+
23+
app('sensor-discovery')->discover(new \App\Models\Sensor([
24+
'poller_type' => 'snmp',
25+
'sensor_class' => 'power_consumed',
26+
'sensor_oid' => $oid,
27+
'sensor_index' => $oid,
28+
'sensor_type' => 'ipoman',
29+
'sensor_descr' => $descr,
30+
'sensor_divisor' => $divisor,
31+
'sensor_multiplier' => 1,
32+
'sensor_limit_low' => 0,
33+
'sensor_limit_low_warn' => null,
34+
'sensor_limit_warn' => null,
35+
'sensor_limit' => 0,
36+
'sensor_current' => 0,
37+
'entPhysicalIndex' => null,
38+
'entPhysicalIndex_measured' => null,
39+
'user_func' => null,
40+
'group' => null,
41+
]));
1742
}

includes/discovery/sensors/pre-cache/ipoman.inc.php

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,44 @@
11
<?php
22

3+
/*
4+
* @author Peca Nesovanovic <[email protected]>
5+
*/
6+
7+
// pre-cache
8+
$oidsEnv = SnmpQuery::cache()->enumStrings()->hideMib()->walk([
9+
'IPOMANII-MIB::ipmEnvEmd',
10+
])->table(1);
11+
312
// FIXME: EMD "stack" support?
413
// FIXME: What to do with IPOMANII-MIB::ipmEnvEmdConfigTempOffset.0 ?
5-
echo ' IPOMANII-MIB ';
6-
$emd_installed = snmp_get($device, 'IPOMANII-MIB::ipmEnvEmdStatusEmdType.0', '-Oqv');
7-
8-
if ($emd_installed != 'disabled') {
9-
$descr = snmp_get($device, 'IPOMANII-MIB::ipmEnvEmdConfigTempName.0', '-Oqv');
10-
$current = (snmp_get($device, 'IPOMANII-MIB::ipmEnvEmdStatusTemperature.0', '-Oqv') / 10);
11-
$high_limit = snmp_get($device, 'IPOMANII-MIB::ipmEnvEmdConfigTempHighSetPoint.0', '-Oqv');
12-
$low_limit = snmp_get($device, 'IPOMANII-MIB::ipmEnvEmdConfigTempLowSetPoint.0', '-Oqv');
14+
if ($oidsEnv[0]['ipmEnvEmdStatusEmdType'] != 'disabled') {
15+
$descr = $oidsEnv[0]['ipmEnvEmdConfigTempName'];
16+
$value = $oidsEnv[0]['ipmEnvEmdStatusTemperature'] / 10;
17+
$high_limit = $oidsEnv[0]['ipmEnvEmdConfigTempHighSetPoint'];
18+
$low_limit = $oidsEnv[0]['ipmEnvEmdConfigTempLowSetPoint'];
1319

14-
if ($descr != '' && is_numeric($current) && $current > '0') {
15-
$current_oid = '.1.3.6.1.4.1.2468.1.4.2.1.5.1.1.2.0';
20+
if ($descr != '' && is_numeric($value) && $value > '0') {
21+
$oid = '.1.3.6.1.4.1.2468.1.4.2.1.5.1.1.2.0';
1622
$descr = trim(str_replace('"', '', $descr));
1723

18-
discover_sensor(null, 'temperature', $device, $current_oid, '1', 'ipoman', $descr, '10', '1', $low_limit, null, null, $high_limit, $current);
24+
app('sensor-discovery')->discover(new \App\Models\Sensor([
25+
'poller_type' => 'snmp',
26+
'sensor_class' => 'temperature',
27+
'sensor_oid' => $oid,
28+
'sensor_index' => 1,
29+
'sensor_type' => 'ipoman',
30+
'sensor_descr' => $descr,
31+
'sensor_divisor' => 10,
32+
'sensor_multiplier' => 1,
33+
'sensor_limit_low' => $low_limit,
34+
'sensor_limit_low_warn' => null,
35+
'sensor_limit_warn' => null,
36+
'sensor_limit' => $high_limit,
37+
'sensor_current' => $value,
38+
'entPhysicalIndex' => null,
39+
'entPhysicalIndex_measured' => null,
40+
'user_func' => null,
41+
'group' => null,
42+
]));
1943
}
2044
}

0 commit comments

Comments
 (0)