Skip to content

Commit

Permalink
fix: Adding state sensor support for RFC1628 UPS (librenms#6153)
Browse files Browse the repository at this point in the history
* Adding state sensor support for RFC1628 UPS

* added runtime for rfc1628

* Delete rfc1628.inc.php
  • Loading branch information
0-skill authored and murrant committed Mar 12, 2017
1 parent ea5a4b3 commit 9c43fbd
Showing 1 changed file with 71 additions and 34 deletions.
105 changes: 71 additions & 34 deletions includes/discovery/sensors/state/rfc1628.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,79 @@

echo 'RFC1628 ';

$oids = snmp_walk($device, '.1.3.6.1.2.1.33.1.2.2', '-Osqn', 'UPS-MIB');
d_echo($oids."\n");

$oids = trim($oids);
foreach (explode("\n", $oids) as $data) {
$data = trim($data);
if ($data) {
list($oid,$descr) = explode(' ', $data, 2);
$split_oid = explode('.', $oid);
$current_id = $split_oid[(count($split_oid) - 1)];
$current_oid = ".1.3.6.1.2.1.33.1.2.2.$current_id";
$current = snmp_get($device, $current_oid, '-O vq');
$descr = 'Seconds on Battery'.(count(explode("\n", $oids)) == 1 ? '' : ' '.($current_id + 1));
$type = 'rfc1628';
$index = (500 + $current_id);

discover_sensor($valid['sensor'], 'state', $device, $current_oid, $index, $type, $descr, '1', '1', null, null, null, null, $current);
// Battery Status (Value : 1 unknown, 2 batteryNormal, 3 batteryLow, 4 batteryDepleted)
$state = snmp_get($device, "upsBatteryStatus.0", "-Ovqe", 'UPS-MIB');
$cur_oid = '.1.3.6.1.2.1.33.1.2.1.0';
$index = '0';

if (is_numeric($state)) {
//Create State Index
$state_name = 'upsBatteryStatusState';
$state_index_id = create_state_index($state_name);

//Create State Translation
if ($state_index_id) {
$states = array(
array($state_index_id,'Unknown',0,1,3) ,
array($state_index_id,'Normal',0,2,0) ,
array($state_index_id,'Low',0,3,2) ,
array($state_index_id,'Depleted',0,4,2) ,
);
foreach ($states as $value) {
$insert = array(
'state_index_id' => $value[0],
'state_descr' => $value[1],
'state_draw_graph' => $value[2],
'state_value' => $value[3],
'state_generic_value' => $value[4]
);
dbInsert($insert, 'state_translations');
}
}

//Discover Sensors
discover_sensor($valid['sensor'], 'state', $device, $cur_oid, $index, $state_name, 'Battery Status', '1', '1', null, null, null, null, $state, 'snmp', $index);

//Create Sensor To State Index
create_sensor_to_state_index($device, $state_name, $index);
}

$oids = snmp_walk($device, '.1.3.6.1.2.1.33.1.2.3', '-Osqn', 'UPS-MIB');
d_echo($oids."\n");

$oids = trim($oids);
foreach (explode("\n", $oids) as $data) {
$data = trim($data);
if ($data) {
list($oid,$descr) = explode(' ', $data, 2);
$split_oid = explode('.', $oid);
$current_id = $split_oid[(count($split_oid) - 1)];
$current_oid = ".1.3.6.1.2.1.33.1.2.3.$current_id";
$current = snmp_get($device, $current_oid, '-O vq');
$descr = 'Battery: Estimated minutes remaining'.(count(explode("\n", $oids)) == 1 ? '' : ' '.($current_id + 1));
$type = 'rfc1628';
$index = (510 + $current_id);

discover_sensor($valid['sensor'], 'state', $device, $current_oid, $index, $type, $descr, '1', '1', null, null, null, null, $current);
// Output Source (Value : 1 other, 2 none, 3 normal, 4 bypass, 5 battery, 6 booster, 7 reducer)
$state = snmp_get($device, "upsOutputSource.0", "-Ovqe", 'UPS-MIB');
$cur_oid = '.1.3.6.1.2.1.33.1.4.1.0';
$index = '0';

if (is_numeric($state)) {
//Create State Index
$state_name = 'upsOutputSourceState';
$state_index_id = create_state_index($state_name);

//Create State Translation
if ($state_index_id) {
$states = array(
array($state_index_id,'Other',0,1,3) ,
array($state_index_id,'None',0,2,3) ,
array($state_index_id,'Normal',0,3,0) ,
array($state_index_id,'Bypass',0,4,2) ,
array($state_index_id,'Battery',0,5,2) ,
array($state_index_id,'Booster',0,6,2) ,
array($state_index_id,'Reducer',0,7,2) ,
);
foreach ($states as $value) {
$insert = array(
'state_index_id' => $value[0],
'state_descr' => $value[1],
'state_draw_graph' => $value[2],
'state_value' => $value[3],
'state_generic_value' => $value[4]
);
dbInsert($insert, 'state_translations');
}
}

//Discover Sensors
discover_sensor($valid['sensor'], 'state', $device, $cur_oid, $index, $state_name, 'Output Source', '1', '1', null, null, null, null, $state, 'snmp', $index);

//Create Sensor To State Index
create_sensor_to_state_index($device, $state_name, $index);
}

0 comments on commit 9c43fbd

Please sign in to comment.