mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
refactor: Updated Ups nut support
This commit is contained in:
@@ -20,15 +20,28 @@
|
||||
*
|
||||
*/
|
||||
|
||||
// (2016-11-25, R.Morris) ups-nut, try "extend" -> if not, fall back to "exec" support.
|
||||
// -> Similar to approach used by Distro, but skip "legacy UCD-MIB shell support"
|
||||
//
|
||||
//NET-SNMP-EXTEND-MIB::nsExtendOutputFull."ups-nut"
|
||||
$name = 'ups-nut';
|
||||
$app_id = $app['app_id'];
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.7.117.112.115.45.110.117.116';
|
||||
$ups_nut = snmp_get($device, $oid, '-Oqv');
|
||||
|
||||
// If "extend" (used above) fails, try "exec" support.
|
||||
// Note, exec always splits outputs on newline, so need to use snmp_walk (not a single SNMP entry!)
|
||||
if (!$ups_nut) {
|
||||
// Data is in an array, due to how "exec" works with ups-nut.sh output, so snmp_walk to retrieve it
|
||||
$oid = '.1.3.6.1.4.1.2021.7890.2.101';
|
||||
$ups_nut=snmp_walk($device, $oid, '-Oqv');
|
||||
}
|
||||
//print_r(array_values(explode("\n", $ups_nut)));
|
||||
|
||||
echo ' '.$name;
|
||||
|
||||
list ($charge, $battery_low, $remaining, $bat_volt, $input_volt, $line_volt, $load) = explode("\n", $ups_nut);
|
||||
// (2016-11-25, R.Morris) Correct list and data below, to match latest ups-nut.sh script (missing one input, and misaligned).
|
||||
list ($charge, $battery_low, $remaining, $bat_volt, $bat_nom, $line_nom, $input_volt, $load) = explode("\n", $ups_nut);
|
||||
|
||||
$rrd_name = array('app', $name, $app_id);
|
||||
$rrd_def = array(
|
||||
@@ -36,20 +49,24 @@ $rrd_def = array(
|
||||
'DS:battery_low:GAUGE:600:0:100',
|
||||
'DS:time_remaining:GAUGE:600:0:U',
|
||||
'DS:battery_voltage:GAUGE:600:0:U',
|
||||
'DS:battery_nominal:GAUGE:600:0:U',
|
||||
'DS:line_nominal:GAUGE:600:0:U',
|
||||
'DS:input_voltage:GAUGE:600:0:U',
|
||||
'DS:nominal_voltage:GAUGE:600:0:U',
|
||||
'DS:load:GAUGE:600:0:100'
|
||||
);
|
||||
//print_r(array_values($rrd_def));
|
||||
|
||||
$fields = array(
|
||||
'charge' => $charge,
|
||||
'battery_low' => $battery_low,
|
||||
'time_remaining' => $remaining/60,
|
||||
'battery_voltage' => $bat_volt,
|
||||
'input_voltage' => $line_volt,
|
||||
'nominal_voltage' => $input_volt,
|
||||
'load' => $load,
|
||||
'battery_nominal' => $bat_nom,
|
||||
'line_nominal' => $line_nom,
|
||||
'input_voltage' => $input_volt,
|
||||
'load' => $load
|
||||
);
|
||||
//print_r(array_values($fields));
|
||||
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
|
||||
Reference in New Issue
Block a user