Skip to content
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 7 commits into from Mar 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions includes/definitions/aos-emu2.yaml
Expand Up @@ -2,9 +2,50 @@ os: aos-emu2
text: 'APC Environmental Monitoring Unit'
type: environment
icon: apc
over:
- {graph: device_temperature, text: Temperature}
- {graph: device_humidity, text: Humidity}
mib_dir:
- apc
discovery:
- sysObjectID:
- .1.3.6.1.4.1.318.1.3.8.2
- .1.3.6.1.4.1.318.1.3.8.3
discovery_modules:
Copy link
Member

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.

ports: 0
ports-stack: 0
entity-physical: 0
processors: 0
mempools: 0
cisco-vrf-lite: 0
storage: 0
hr-device: 0
discovery-protocols: 0
bgp-peers: 0
vlans: 0
ucd-diskio: 0
services: 0
stp: 0
ntp: 0
wireless: 0
fdb-table: 0
poller_modules:
ipmi: 0
entity-physical: 0
processors: 0
mempools: 0
storage: 0
netstats: 0
hr-mib: 0
ucd-mib: 0
ipSystemStats: 0
ports: 0
bgp-peers: 0
ospf: 0
ucd-diskio: 0
services: 0
stp: 0
ntp: 0
wireless: 0
fdb-table: 0
applications: 0
114 changes: 114 additions & 0 deletions includes/discovery/sensors/state/aos-emu2.inc.php
@@ -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'];
Copy link
Member

Choose a reason for hiding this comment

The 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);
}