From f3cf20a4fad08bad8608a1bacf4b8263fb2a32b2 Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 23 Oct 2016 04:15:57 +1100 Subject: [PATCH] added support for megatec ups - added ups status and fixed index for voltage and frequency --- .../sensors/frequencies/netagent2.inc.php | 2 +- .../sensors/states/netagent2.inc.php | 92 +++++++++++++++++++ .../sensors/voltages/netagent2.inc.php | 2 +- tests/snmpsim/netagent2.snmprec | 1 + 4 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 includes/discovery/sensors/states/netagent2.inc.php diff --git a/includes/discovery/sensors/frequencies/netagent2.inc.php b/includes/discovery/sensors/frequencies/netagent2.inc.php index bb357a9a0f..30ada21e3d 100644 --- a/includes/discovery/sensors/frequencies/netagent2.inc.php +++ b/includes/discovery/sensors/frequencies/netagent2.inc.php @@ -61,7 +61,7 @@ if ($device['os'] == 'netagent2') { if (!empty($out_frequency) || $out_frequency == 0) { $type = 'netagent2'; - $index = 0; + $index = 1; $limit = 60; $warnlimit = 51; $lowlimit = 0; diff --git a/includes/discovery/sensors/states/netagent2.inc.php b/includes/discovery/sensors/states/netagent2.inc.php new file mode 100644 index 0000000000..3479151047 --- /dev/null +++ b/includes/discovery/sensors/states/netagent2.inc.php @@ -0,0 +1,92 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2016 Tony Murray + * @author Tony Murray + */ + +if ($device['os'] == 'netagent2') { + $ups_status_oid = '.1.3.6.1.4.1.935.1.1.1.4.1.1.0'; + $ups_status = snmp_get($device, $ups_status_oid, '-Oqv'); + + if (!empty($ups_status) || $ups_status == 0) { + // UPS status OID (Value : 0-1 Unknown, 2 On Line, 3 On Battery, 4 On Boost, 5 Sleeping, 6 On Bypass, 7 Rebooting, 8 Standby, 9 On Buck ) + $state_name = 'netagent2upsstatus'; + $state_index_id = create_state_index($state_name); + + if ($state_index_id) { + $states = array( + array($state_index_id,'unknown',0,0,3) , + array($state_index_id,'unknown',0,1,3) , + array($state_index_id,'OnLine',1,2,0) , + array($state_index_id,'OnBattery',1,3,1) , + array($state_index_id,'OnBoost',1,4,0) , + array($state_index_id,'Sleeping',1,4,1) , + array($state_index_id,'OnBypass',1,6,0) , + array($state_index_id,'Rebooting',1,7,1) , + array($state_index_id,'Standby',1,8,0) , + array($state_index_id,'OnBuck',1,9,0) + ); + + 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'); + } + } + + $index = 0; + $limit = 10; + $warnlimit = null; + $lowlimit = null; + $lowwarnlimit = null; + $divisor = 1; + $status = $ups_status / $divisor; + $descr = 'UPS Status'; + + discover_sensor( + $valid['sensor'], + 'status', + $device, + $in_voltage_oid, + $index, + $state_name, + $descr, + $divisor, + '1', + $lowlimit, + $lowwarnlimit, + $warnlimit, + $limit, + $status + ); + create_sensor_to_state_index( + $device, + $state_name, + $index + ); + } +}//end if diff --git a/includes/discovery/sensors/voltages/netagent2.inc.php b/includes/discovery/sensors/voltages/netagent2.inc.php index eb96fe119b..0c31dcd5ec 100644 --- a/includes/discovery/sensors/voltages/netagent2.inc.php +++ b/includes/discovery/sensors/voltages/netagent2.inc.php @@ -61,7 +61,7 @@ if ($device['os'] == 'netagent2') { if (!empty($out_voltage) || $out_voltage == 0) { $type = 'netagent2'; - $index = 0; + $index = 1; $limit = 300; $warnlimit = 253; $lowlimit = 0; diff --git a/tests/snmpsim/netagent2.snmprec b/tests/snmpsim/netagent2.snmprec index 79b0a86783..68ecf2bb72 100644 --- a/tests/snmpsim/netagent2.snmprec +++ b/tests/snmpsim/netagent2.snmprec @@ -8,3 +8,4 @@ 1.3.6.1.4.1.935.1.1.1.2.2.3.0|2|250 1.3.6.1.4.1.935.1.1.1.3.2.1.0|2|2545 1.3.6.1.4.1.935.1.1.1.4.2.1.0|2|2285 +1.3.6.1.4.1.935.1.1.1.4.1.1.0|2|9 \ No newline at end of file