New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AOS-EMU2: Add contact,relay,outlet discovery; update yaml,snmprec,json #8317
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
640c166
Add contact,relay,outlet discovery; update yaml,snmprec,json
axemann caf97fd
Fix formatting
axemann 82d53c1
Another attempt at fixing sensors
laf 1910e06
Update state mappings and fix json sensor ordering
murrant 06f5615
Capture values numerically.
murrant 2500251
Fix whitespace.
murrant fc33589
Update sensors test data for order_by
murrant File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
/** | ||
* aos-emu2.inc.php | ||
* | ||
* LibreNMS sensors state discovery module for APC EMU2 | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* @package LibreNMS | ||
* @link http://librenms.org | ||
* @copyright 2018 Ben Gibbons | ||
* @author Ben Gibbons <axemann@gmail.com> | ||
*/ | ||
|
||
// Input Contact discovery | ||
|
||
$contacts['emu2_contacts'] = snmpwalk_group($device, 'emsInputContactStatusEntry', 'PowerNet-MIB'); | ||
|
||
foreach ($contacts['emu2_contacts'] as $id => $contact) { | ||
$index = $contact['emsInputContactStatusInputContactIndex']; | ||
$oid = '.1.3.6.1.4.1.318.1.1.10.3.14.1.1.3.' . $index; | ||
$descr = $contact['emsInputContactStatusInputContactName']; | ||
$currentstate = $contact['emsInputContactStatusInputContactState']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This returns a string when you use the mib, so you need to convert the string to a numeric value. |
||
$normalstate = $contact['emsInputContactStatusInputContactNormalState']; | ||
if (is_array($contacts['emu2_contacts']) && $normalstate == '1') { | ||
$state_name = 'emsInputContactNormalState_NC'; | ||
$states = array( | ||
array('value' => 1, 'generic' => 0, 'graph' => 0, 'descr' => 'Closed'), | ||
array('value' => 2, 'generic' => 1, 'graph' => 0, 'descr' => 'Open'), | ||
); | ||
create_state_index($state_name, $states); | ||
} elseif (is_array($contacts['emu2_contacts']) && $normalstate == '2') { | ||
$state_name = 'emsInputContactNormalState_NO'; | ||
$states = array( | ||
array('value' => 1, 'generic' => 1, 'graph' => 0, 'descr' => 'Closed'), | ||
array('value' => 2, 'generic' => 0, 'graph' => 0, 'descr' => 'Open'), | ||
); | ||
create_state_index($state_name, $states); | ||
} | ||
|
||
discover_sensor($valid['sensor'], 'state', $device, $oid, $index, $state_name, $descr, '1', '1', null, null, null, null, $currentstate, 'snmp', $index); | ||
create_sensor_to_state_index($device, $state_name, $index); | ||
} | ||
|
||
// Output Relay discovery | ||
|
||
$relays['emu2_relays'] = snmpwalk_group($device, 'emsOutputRelayStatusEntry', 'PowerNet-MIB'); | ||
|
||
foreach ($relays['emu2_relays'] as $id => $relay) { | ||
$index = $relay['emsOutputRelayStatusOutputRelayIndex']; | ||
$oid = '.1.3.6.1.4.1.318.1.1.10.3.15.1.1.3.' . $index; | ||
$descr = $relay['emsOutputRelayStatusOutputRelayName']; | ||
$currentstate = $relay['emsOutputRelayStatusOutputRelayState']; | ||
$normalstate = $relay['emsOutputRelayStatusOutputRelayNormalState']; | ||
if (is_array($relays['emu2_relays']) && $normalstate == '1') { | ||
$state_name = 'emsOutputRelayNormalState_NC'; | ||
$states = array( | ||
array('value' => 1, 'generic' => 0, 'graph' => 0, 'descr' => 'Closed'), | ||
array('value' => 2, 'generic' => 1, 'graph' => 0, 'descr' => 'Open'), | ||
); | ||
create_state_index($state_name, $states); | ||
} elseif (is_array($relays['emu2_relays']) && $normalstate == '2') { | ||
$state_name = 'emsOutputRelayNormalState_NO'; | ||
$states = array( | ||
array('value' => 1, 'generic' => 1, 'graph' => 0, 'descr' => 'Closed'), | ||
array('value' => 2, 'generic' => 0, 'graph' => 0, 'descr' => 'Open'), | ||
); | ||
create_state_index($state_name, $states); | ||
} | ||
|
||
discover_sensor($valid['sensor'], 'state', $device, $oid, $index, $state_name, $descr, '1', '1', null, null, null, null, $currentstate, 'snmp', $index); | ||
create_sensor_to_state_index($device, $state_name, $index); | ||
} | ||
|
||
// Outlet discovery | ||
|
||
$outlets['emu2_outlets'] = snmpwalk_group($device, 'emsOutletStatusEntry', 'PowerNet-MIB'); | ||
|
||
foreach ($outlets['emu2_outlets'] as $id => $outlet) { | ||
$index = $outlet['emsOutletStatusOutletIndex']; | ||
$oid = '.1.3.6.1.4.1.318.1.1.10.3.16.1.1.3.' . $index; | ||
$descr = $outlet['emsOutletStatusOutletName']; | ||
$currentstate = $outlet['emsOutletStatusOutletState']; | ||
$normalstate = $outlet['emsOutletStatusOutletNormalState']; | ||
if (is_array($outlets['emu2_outlets']) && $normalstate == '1') { | ||
$state_name = 'emsOutletNormalState_ON'; | ||
$states = array( | ||
array('value' => 1, 'generic' => 0, 'graph' => 0, 'descr' => 'On'), | ||
array('value' => 2, 'generic' => 1, 'graph' => 0, 'descr' => 'Off'), | ||
); | ||
create_state_index($state_name, $states); | ||
} elseif (is_array($outlets['emu2_outlets']) && $normalstate == '2') { | ||
$state_name = 'emsOutletNormalState_OFF'; | ||
$states = array( | ||
array('value' => 1, 'generic' => 1, 'graph' => 0, 'descr' => 'On'), | ||
array('value' => 2, 'generic' => 0, 'graph' => 0, 'descr' => 'Off'), | ||
); | ||
create_state_index($state_name, $states); | ||
} | ||
|
||
discover_sensor($valid['sensor'], 'state', $device, $oid, $index, $state_name, $descr, '1', '1', null, null, null, null, $currentstate, 'snmp', $index); | ||
create_sensor_to_state_index($device, $state_name, $index); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is kind of pointless and misleading to disable all these modules. Most don't do anything on your device.