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

Rewrite state sensors to walk entire table for TIMOS #8588

Merged
merged 2 commits into from Apr 25, 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
114 changes: 43 additions & 71 deletions includes/discovery/sensors/state/timos.inc.php
@@ -1,81 +1,53 @@
<?php
$oids = snmpwalk_cache_numerical_oid($device, 'tmnxChassisPowerSupplyTable', $power_supply_table = array(), 'TIMETRA-CHASSIS-MIB', null, '-OQUsne');

$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),
if (!empty($oids)) {
// Create State Index
$dev_state_name = 'tmnxDeviceState';
$dev_states = array(
array('value' => 1, 'generic' => 3, 'graph' => 0, 'descr' => 'Unknown'),
array('value' => 2, 'generic' => 3, 'graph' => 0, 'descr' => 'Not Equipped'),
array('value' => 3, 'generic' => 0, 'graph' => 0, 'descr' => 'OK'),
array('value' => 4, 'generic' => 2, 'graph' => 0, 'descr' => 'Failed'),
array('value' => 5, 'generic' => 1, 'graph' => 0, 'descr' => 'Out of Service')
);
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),
create_state_index($dev_state_name, $dev_states);

$ps_state_name = 'tmnxChassisPowerSupplyAssignedTypes';
$ps_states = array(
array('value' => 0, 'generic' => 3, 'graph' => 0, 'descr' => 'None'),
array('value' => 1, 'generic' => 0, 'graph' => 0, 'descr' => 'DC'),
array('value' => 2, 'generic' => 0, 'graph' => 0, 'descr' => 'Single AC'),
array('value' => 3, 'generic' => 0, 'graph' => 0, 'descr' => 'Multiple AC')
);
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),
);
create_state_index($ps_state_name, $ps_states);

$ps_table = array(
array('tbl_index' => 2, 'desc' => 'AC Status PS ', 'type' => $dev_state_name),
array('tbl_index' => 3, 'desc' => 'DC Status PS ', 'type' => $dev_state_name),
array('tbl_index' => 4, 'desc' => 'Temperature Status PS ', 'type' => $dev_state_name),
array('tbl_index' => 6, 'desc' => 'Power Supply 1 Status PS ', 'type' => $dev_state_name),
array('tbl_index' => 7, 'desc' => 'Power Supply 2 Status PS ', 'type' => $dev_state_name),
array('tbl_index' => 8, 'desc' => 'Assigned Type PS ', 'type' => $ps_state_name),
array('tbl_index' => 9, 'desc' => 'Input Status PS ', 'type' => $dev_state_name),
array('tbl_index' => 10, 'desc' => 'Output Status PS ', 'type' => $dev_state_name),
);

$base_oid = '.1.3.6.1.4.1.6527.3.1.2.2.1.5.1.';

foreach ($ps_table as $entry) {
foreach ($oids as $index => $value) {
$num_oid = $base_oid.$entry['tbl_index'].".1.".$index;
$sensor_index = 'tmnxPowerSupplyTable.'.$entry['tbl_index'].".1.".$index;
$desc = $entry['desc'].$index;

$pst = snmpwalk_cache_numerical_oid($device, 'tmnxChassisPowerSupplyTable', $power_supply_table = array(), 'TIMETRA-CHASSIS-MIB', null, '-OQUsn');
$power_supply_table = end($pst);
//Discover sensors
discover_sensor($valid['sensor'], 'state', $device, $num_oid, $sensor_index, $entry['type'], $desc, 1, 1, null, null, null, null, $value[$num_oid]);

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);
// Create sensor to state index
create_sensor_to_state_index($device, $entry['type'], $sensor_index);
}
}
}

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