newdevice: Added TiMOS temperature and power supply state sensors. (#6657)

* Add TiMOS temperature and power supply state sensors.

* Refactor the sensor discovery, making it a little cleaner

* Discover TiMOS device serial number
Pull proper hardware OID instead of parsing sysDescr

* Make the style gods happy

* Refactoring for some of the requested changes

* Break out the arrays into variables as scrutinizer requests...

* Fix missing semicolon
This commit is contained in:
Nick Peelman
2017-05-22 12:59:38 -04:00
committed by Neil Lathwood
parent c728e4b0cf
commit 77c5b1e304
3 changed files with 130 additions and 7 deletions

View File

@@ -0,0 +1,81 @@
<?php
$nokia_device_state_name = 'tmnxDeviceState';
$nokia_device_state_index = create_state_index($nokia_device_state_name);
if ($nokia_device_state_index !== null) {
$nokia_device_states = array(
array($nokia_device_state_index, 'Unknown', 1,1,3),
array($nokia_device_state_index, 'Not Equippped', 1,2,3),
array($nokia_device_state_index, 'Ok', 1,3,0),
array($nokia_device_state_index, 'Failed', 1,4,2),
array($nokia_device_state_index, 'Out Of Service', 1,5,1),
array($nokia_device_state_index, 'Not Provisioned', 1,6,3),
);
foreach ($nokia_device_states as $state) {
$insert = array(
'state_index_id' => $state[0],
'state_descr' => $state[1],
'state_draw_graph' => $state[2],
'state_value' => $state[3],
'state_generic_value' => $state[4],
);
dbInsert($insert, 'state_translations');
}
}
$nokia_device_ps_assigned_types_name = 'tmnxChassisPowerSupplyAssignedTypes';
$nokia_device_ps_assigned_types_index = create_state_index($nokia_device_ps_assigned_types_name);
if ($nokia_device_ps_assigned_types_index !== null) {
$nokia_device_ps_assigned_types = array(
array($nokia_device_ps_assigned_types_index, 'None', 0,0,0),
array($nokia_device_ps_assigned_types_index, 'DC', 0,1,0),
array($nokia_device_ps_assigned_types_index, 'Single AC', 0,2,0),
array($nokia_device_ps_assigned_types_index, 'Multiple AC', 0,3,0),
array($nokia_device_ps_assigned_types_index, 'default', 0,4,3),
);
foreach ($nokia_device_ps_assigned_types as $state) {
$insert = array(
'state_index_id' => $state[0],
'state_descr' => $state[1],
'state_draw_graph' => $state[2],
'state_value' => $state[3],
'state_generic_value' => $state[4],
);
dbInsert($insert, 'state_translations');
}
}
$base_oid = '.1.3.6.1.4.1.6527.3.1.2.2.1.5.1.';
$power_supply_oids = array(
array('sub_oid' => '2.1.1', 'desc' => 'AC Status', 'type' => $nokia_device_state_name),
array('sub_oid' => '3.1.1', 'desc' => 'DC Status', 'type' => $nokia_device_state_name),
array('sub_oid' => '6.1.1', 'desc' => 'Power Supply 1', 'type' => $nokia_device_state_name),
array('sub_oid' => '7.1.1', 'desc' => 'Power Supply 2', 'type' => $nokia_device_state_name),
array('sub_oid' => '8.1.1', 'desc' => 'Power Supply Type', 'type' => $nokia_device_ps_assigned_types_name),
array('sub_oid' => '9.1.1', 'desc' => 'Power In', 'type' => $nokia_device_state_name),
array('sub_oid' => '10.1.1', 'desc' => 'Power Out', 'type' => $nokia_device_state_name),
);
$pst = snmpwalk_cache_numerical_oid($device, 'tmnxChassisPowerSupplyTable', $power_supply_table = array(), 'TIMETRA-CHASSIS-MIB', 'aos', '-OQUsn');
$power_supply_table = end($pst);
foreach ($power_supply_oids as $data) {
$full_oid = $base_oid . $data['sub_oid'];
$index = "tmnxChassisPowerSupplyTable." . $data['sub_oid'];
discover_sensor($valid['sensor'], 'state', $device, $full_oid, $index, $data['type'], $data['desc'], 1, 1, null, null, null, null, $power_supply_table[$full_oid], 'snmp', $index);
create_sensor_to_state_index($device, $data['type'], $index);
unset($full_oid);
}
unset(
$power_supply_state_table,
$nokia_device_state_name,
$nokia_device_state_index,
$nokia_device_states,
$nokia_device_ps_assigned_types_name,
$nokia_device_ps_assigned_types_index,
$nokia_device_ps_assigned_types,
$base_oid,
$power_supply_oids
);

View File

@@ -0,0 +1,35 @@
<?php
$description_root_oid = '.1.3.6.1.4.1.6527.3.1.2.2.1.8.1.8';
$sensor_present_root_oid = '.1.3.6.1.4.1.6527.3.1.2.2.1.8.1.17';
$temperature_root_oid = '.1.3.6.1.4.1.6527.3.1.2.2.1.8.1.18';
$threshold_root_oid = '.1.3.6.1.4.1.6527.3.1.2.2.1.8.1.19';
$temp_sensors = snmpwalk_cache_oid($device, 'tmnxHwID', $temp_sensors = array(), 'TIMETRA-CHASSIS-MIB', 'aos');
$temp_sensors = snmpwalk_cache_oid($device, $description_root_oid, $temp_sensors, 'TIMETRA-CHASSIS-MIB', 'aos');
$temp_sensors = snmpwalk_cache_oid($device, $sensor_present_root_oid, $temp_sensors, 'TIMETRA-CHASSIS-MIB', 'aos');
$temp_sensors = snmpwalk_cache_oid($device, $temperature_root_oid, $temp_sensors, 'TIMETRA-CHASSIS-MIB', 'aos');
$temp_sensors = snmpwalk_cache_oid($device, $threshold_root_oid, $temp_sensors, 'TIMETRA-CHASSIS-MIB', 'aos');
foreach ($temp_sensors as $sub_oid => $component) {
$descr = $component['tmnxHwName'];
$temp_present = $component['tmnxHwTempSensor'];
$temperature = $component['tmnxHwTemperature'];
$temp_thresh = $component['tmnxHwTempThreshold'];
if ($temp_present == true && $descr != '' && $temperature != -1) {
$temperature_oid = $temperature_root_oid . '.' . $sub_oid;
discover_sensor($valid['sensor'], 'temperature', $device, $temperature_oid, "tmnxHwTemperature.$sub_oid", 'nokia', $descr, '1', '1', null, null, null, $temp_thresh, $temperature);
}
}
unset(
$descr,
$temp_present,
$temperature,
$temp_thresh,
$temp_sensors,
$description_root_oid,
$sensor_present_root_oid,
$temperature_root_oid,
$threshold_root_oid
);

View File

@@ -10,13 +10,20 @@ $versionModifier = trim(snmp_get($device, '1.3.6.1.4.1.6527.3.1.2.1.1.7.0', '-OQ
$version = 'v' . $majorVersion . '.' . $minorVersion . '.' . $versionModifier;
//SNMPv2-MIB::sysDescr.0 = STRING: TiMOS-B-9.0.R3 both/hops Nokia SAS-Sx 48Tp4SFP+ (PoE) 7210 Copyright (c) 2000-2017 Nokia.
//All rights reserved. All use subject to applicable license agreements.
//Built on Thu Jan 5 11:01:16 IST 2017 by builder in /home/builder/9.0B1/R3/panos/main
$chassis_type_name_array = snmpwalk_cache_oid($device, 'tmnxChassisTypeName', $a = array(), 'TIMETRA-CHASSIS-MIB', 'aos', '-OQUs');
$pattern = "~(cpm|both)\/(hops64|hops|x86_64) (?'hardware'.*)\sCopyright~";
preg_match($pattern, $poll_device['sysDescr'], $matches);
$hardware_array = reset($chassis_type_name_array);
$hardware = end($hardware_array);
if ($matches['hardware']) {
$hardware = $matches['hardware'];
$props = snmpwalk_cache_numerical_oid($device, 'tmnxHwEntry.7', $props = array(), 'TIMETRA-CHASSIS-MIB', 'aos', '-OQne');
foreach ($props as $p) {
foreach ($p as $k => $v) {
if ($v == 3) {
$shrapnel = explode('.', $k);
$unitID = end($shrapnel);
$serial = snmp_get($device, "1.3.6.1.4.1.6527.3.1.2.2.1.8.1.5.1.$unitID", '-OQv', 'TIMETRA-CHASSIS-MIB', 'aos');
unset($shrapnel);
}
}
}
unset($props, $p, $k, $v, $unitID);