More cisco state fixes (#16369)

* More cisco state fixes
Turns out it was fetching values as strings.  Swap to SnmpQuery and fetch the data numeric as expected

* Apply fixes from StyleCI

* update MIB too

---------

Co-authored-by: Tony Murray <murrant@users.noreply.github.com>
This commit is contained in:
Tony Murray
2024-09-06 18:49:55 -05:00
committed by GitHub
parent 81d6eb57e6
commit f54e38f4fe
2 changed files with 155 additions and 143 deletions

View File

@@ -10,28 +10,28 @@
* the source code distribution for details.
*/
$role_data = snmpwalk_cache_oid($device, 'cswSwitchRole', [], 'CISCO-STACKWISE-MIB');
$redundant_data = snmp_get($device, 'cswRingRedundant.0', '-OQv', 'CISCO-STACKWISE-MIB');
$role_data = SnmpQuery::walk('CISCO-STACKWISE-MIB::cswSwitchRole')->values();
$redundant_data = SnmpQuery::enumStrings()->get('CISCO-STACKWISE-MIB::cswRingRedundant.0')->value();
$tables = [
['num_oid' => '.1.3.6.1.4.1.9.9.661.1.3.1.1.6.', 'oid' => 'c3gModemStatus', 'state_name' => 'c3gModemStatus', 'mib' => 'CISCO-WAN-3G-MIB', 'descr' => 'Modem status'],
['num_oid' => '.1.3.6.1.4.1.9.9.661.1.3.4.1.1.3.', 'oid' => 'c3gGsmCurrentBand', 'state_name' => 'c3gGsmCurrentBand', 'mib' => 'CISCO-WAN-3G-MIB', 'descr' => 'Current band'],
['num_oid' => '.1.3.6.1.4.1.9.9.661.1.3.2.1.5.', 'oid' => 'c3gGsmPacketService', 'state_name' => 'c3gGsmPacketService', 'mib' => 'CISCO-WAN-3G-MIB', 'descr' => 'Packet service'],
['num_oid' => '.1.3.6.1.4.1.9.9.661.1.3.2.1.6.', 'oid' => 'c3gGsmCurrentRoamingStatus', 'state_name' => 'c3gGsmCurrentRoamingStatus', 'mib' => 'CISCO-WAN-3G-MIB', 'descr' => 'Roaming status'],
['num_oid' => '.1.3.6.1.4.1.9.9.661.1.3.5.1.1.2.', 'oid' => 'c3gGsmSimStatus', 'state_name' => 'c3gGsmSimStatus', 'mib' => 'CISCO-WAN-3G-MIB', 'descr' => 'SIM status'],
['num_oid' => '.1.3.6.1.4.1.9.9.13.1.2.1.7.', 'oid' => 'ciscoEnvMonVoltageStatusTable', 'state_name' => 'ciscoEnvMonVoltageState', 'mib' => 'CISCO-ENVMON-MIB', 'descr' => 'ciscoEnvMonVoltageStatusDescr'],
['num_oid' => '.1.3.6.1.4.1.9.9.13.1.3.1.6.', 'oid' => 'ciscoEnvMonTemperatureStatusTable', 'state_name' => 'ciscoEnvMonTemperatureState', 'mib' => 'CISCO-ENVMON-MIB', 'descr' => 'ciscoEnvMonTemperatureStatusDescr'],
['num_oid' => '.1.3.6.1.4.1.9.9.13.1.4.1.3.', 'oid' => 'ciscoEnvMonFanStatusTable', 'state_name' => 'ciscoEnvMonFanState', 'mib' => 'CISCO-ENVMON-MIB', 'descr' => 'ciscoEnvMonFanStatusDescr'],
['num_oid' => '.1.3.6.1.4.1.9.9.13.1.5.1.3.', 'oid' => 'ciscoEnvMonSupplyStatusTable', 'state_name' => 'ciscoEnvMonSupplyState', 'mib' => 'CISCO-ENVMON-MIB', 'descr' => 'ciscoEnvMonSupplyStatusDescr'],
['num_oid' => '.1.3.6.1.4.1.9.9.117.1.1.2.1.2.', 'oid' => 'cefcFRUPowerStatusTable', 'state_name' => 'cefcFRUPowerOperStatus', 'mib' => 'CISCO-ENTITY-FRU-CONTROL-MIB', 'descr' => 'Sensor Name'],
['num_oid' => '.1.3.6.1.4.1.9.9.176.1.1.2.', 'oid' => 'cRFStatusUnitState', 'state_name' => 'cRFStatusUnitState', 'mib' => 'CISCO-RF-MIB', 'descr' => 'VSS Device State'],
['num_oid' => '.1.3.6.1.4.1.9.9.176.1.1.4.', 'oid' => 'cRFStatusPeerUnitState', 'state_name' => 'cRFStatusPeerUnitState', 'mib' => 'CISCO-RF-MIB', 'descr' => 'VSS Peer State'],
['num_oid' => '.1.3.6.1.4.1.9.9.176.1.2.14.', 'oid' => 'cRFCfgRedundancyOperMode', 'state_name' => 'cRFCfgRedundancyOperMode', 'mib' => 'CISCO-RF-MIB', 'descr' => 'VSS Mode'],
['num_oid' => '.1.3.6.1.4.1.9.9.500.1.1.3.', 'oid' => 'cswGlobals', 'state_name' => 'cswRingRedundant', 'mib' => 'CISCO-STACKWISE-MIB', 'descr' => 'Stack Ring - Redundant'],
['num_oid' => '.1.3.6.1.4.1.9.9.500.1.2.1.1.3.', 'oid' => 'cswSwitchRole', 'state_name' => 'cswSwitchRole', 'mib' => 'CISCO-STACKWISE-MIB', 'descr' => 'Stack Role - Switch#'],
['num_oid' => '.1.3.6.1.4.1.9.9.500.1.2.1.1.6.', 'oid' => 'cswSwitchState', 'state_name' => 'cswSwitchState', 'mib' => 'CISCO-STACKWISE-MIB', 'descr' => 'Stack State - Switch#'],
['num_oid' => '.1.3.6.1.4.1.9.9.500.1.2.2.1.1.', 'oid' => 'cswStackPortOperStatus', 'state_name' => 'cswStackPortOperStatus', 'mib' => 'CISCO-STACKWISE-MIB', 'descr' => 'Stack Port Status - '],
['num_oid' => '.1.3.6.1.4.1.9.9.601.1.3.1.1.4.', 'oid' => 'crepSegmentComplete', 'state_name' => 'crepSegmentComplete', 'mib' => 'CISCO-RESILIENT-ETHERNET-PROTOCOL-MIB', 'descr' => 'REP State - Segment '],
['num_oid' => '.1.3.6.1.4.1.9.9.661.1.3.1.1.6.', 'oid' => 'CISCO-WAN-3G-MIB::c3gModemStatus', 'state_name' => 'c3gModemStatus', 'descr' => 'Modem status'],
['num_oid' => '.1.3.6.1.4.1.9.9.661.1.3.4.1.1.3.', 'oid' => 'CISCO-WAN-3G-MIB::c3gGsmCurrentBand', 'state_name' => 'c3gGsmCurrentBand', 'descr' => 'Current band'],
['num_oid' => '.1.3.6.1.4.1.9.9.661.1.3.2.1.5.', 'oid' => 'CISCO-WAN-3G-MIB::c3gGsmPacketService', 'state_name' => 'c3gGsmPacketService', 'descr' => 'Packet service'],
['num_oid' => '.1.3.6.1.4.1.9.9.661.1.3.2.1.6.', 'oid' => 'CISCO-WAN-3G-MIB::c3gGsmCurrentRoamingStatus', 'state_name' => 'c3gGsmCurrentRoamingStatus', 'descr' => 'Roaming status'],
['num_oid' => '.1.3.6.1.4.1.9.9.661.1.3.5.1.1.2.', 'oid' => 'CISCO-WAN-3G-MIB::c3gGsmSimStatus', 'state_name' => 'c3gGsmSimStatus', 'descr' => 'SIM status'],
['num_oid' => '.1.3.6.1.4.1.9.9.13.1.2.1.7.', 'oid' => 'CISCO-ENVMON-MIB::ciscoEnvMonVoltageStatusTable', 'state_name' => 'ciscoEnvMonVoltageState', 'descr' => 'ciscoEnvMonVoltageStatusDescr'],
['num_oid' => '.1.3.6.1.4.1.9.9.13.1.3.1.6.', 'oid' => 'CISCO-ENVMON-MIB::ciscoEnvMonTemperatureStatusTable', 'state_name' => 'ciscoEnvMonTemperatureState', 'descr' => 'ciscoEnvMonTemperatureStatusDescr'],
['num_oid' => '.1.3.6.1.4.1.9.9.13.1.4.1.3.', 'oid' => 'CISCO-ENVMON-MIB::ciscoEnvMonFanStatusTable', 'state_name' => 'ciscoEnvMonFanState', 'descr' => 'ciscoEnvMonFanStatusDescr'],
['num_oid' => '.1.3.6.1.4.1.9.9.13.1.5.1.3.', 'oid' => 'CISCO-ENVMON-MIB::ciscoEnvMonSupplyStatusTable', 'state_name' => 'ciscoEnvMonSupplyState', 'descr' => 'ciscoEnvMonSupplyStatusDescr'],
['num_oid' => '.1.3.6.1.4.1.9.9.117.1.1.2.1.2.', 'oid' => 'CISCO-ENTITY-FRU-CONTROL-MIB::cefcFRUPowerStatusTable', 'state_name' => 'cefcFRUPowerOperStatus', 'descr' => 'Sensor Name'],
['num_oid' => '.1.3.6.1.4.1.9.9.176.1.1.2.', 'oid' => 'CISCO-RF-MIB::cRFStatusUnitState', 'state_name' => 'cRFStatusUnitState', 'descr' => 'VSS Device State'],
['num_oid' => '.1.3.6.1.4.1.9.9.176.1.1.4.', 'oid' => 'CISCO-RF-MIB::cRFStatusPeerUnitState', 'state_name' => 'cRFStatusPeerUnitState', 'descr' => 'VSS Peer State'],
['num_oid' => '.1.3.6.1.4.1.9.9.176.1.2.14.', 'oid' => 'CISCO-RF-MIB::cRFCfgRedundancyOperMode', 'state_name' => 'cRFCfgRedundancyOperMode', 'descr' => 'VSS Mode'],
['num_oid' => '.1.3.6.1.4.1.9.9.500.1.1.3.', 'oid' => 'CISCO-STACKWISE-MIB::cswGlobals', 'state_name' => 'cswRingRedundant', 'descr' => 'Stack Ring - Redundant'],
['num_oid' => '.1.3.6.1.4.1.9.9.500.1.2.1.1.3.', 'oid' => 'CISCO-STACKWISE-MIB::cswSwitchRole', 'state_name' => 'cswSwitchRole', 'descr' => 'Stack Role - Switch#'],
['num_oid' => '.1.3.6.1.4.1.9.9.500.1.2.1.1.6.', 'oid' => 'CISCO-STACKWISE-MIB::cswSwitchState', 'state_name' => 'cswSwitchState', 'descr' => 'Stack State - Switch#'],
['num_oid' => '.1.3.6.1.4.1.9.9.500.1.2.2.1.1.', 'oid' => 'CISCO-STACKWISE-MIB::cswStackPortOperStatus', 'state_name' => 'cswStackPortOperStatus', 'descr' => 'Stack Port Status - '],
['num_oid' => '.1.3.6.1.4.1.9.9.601.1.3.1.1.4.', 'oid' => 'CISCO-RESILIENT-ETHERNET-PROTOCOL-MIB::crepSegmentComplete', 'state_name' => 'crepSegmentComplete', 'descr' => 'REP State - Segment '],
];
$swrolenumber = 0;
@@ -40,24 +40,24 @@ $repsegmentnumber = 0;
foreach ($tables as $tablevalue) {
//Some switches on 15.x expose this information regardless if they are stacked or not, we try to mitigate that by doing the following.
if (($tablevalue['oid'] == 'cswGlobals' || $tablevalue['oid'] == 'cswSwitchRole' || $tablevalue['oid'] == 'cswSwitchState' || $tablevalue['oid'] == 'cswStackPortOperStatus') && $redundant_data == 'false' && count($role_data) == 1) {
if (($tablevalue['oid'] == 'cswGlobals' || $tablevalue['oid'] == 'cswSwitchRole' || $tablevalue['oid'] == 'cswSwitchState' || $tablevalue['oid'] == 'cswStackPortOperStatus') && $redundant_data == 'false' && count($role_data) <= 1) {
continue;
}
$temp = snmpwalk_cache_multi_oid($device, $tablevalue['oid'], [], $tablevalue['mib']);
$temp = SnmpQuery::hideMib()->walk($tablevalue['oid'])->valuesByIndex();
$cur_oid = $tablevalue['num_oid'];
if (is_array($temp)) {
if ((isset($temp[0][$tablevalue['state_name']]) && $temp[0][$tablevalue['state_name']] == 'nonRedundant') || (isset($temp[0]['cswMaxSwitchNum']) && $temp[0]['cswMaxSwitchNum'] == '1')) {
if (! empty($temp)) {
$state_name = $tablevalue['state_name'];
if ((isset($temp[0][$state_name]) && $temp[0][$state_name] == 'nonRedundant') || (isset($temp[0]['cswMaxSwitchNum']) && $temp[0]['cswMaxSwitchNum'] == '1')) {
break;
}
//Create State Index
$state_name = $tablevalue['state_name'];
//Create State Translation
if ($state_name == 'cRFStatusUnitState' || $state_name == 'cRFStatusPeerUnitState') {
$states = [
$states = match ($state_name) {
'cRFStatusUnitState','cRFStatusPeerUnitState' => [
['value' => 1, 'generic' => 3, 'graph' => 0, 'descr' => 'notKnown'],
['value' => 2, 'generic' => 0, 'graph' => 0, 'descr' => 'disabled'],
['value' => 3, 'generic' => 1, 'graph' => 0, 'descr' => 'initialization'],
@@ -74,9 +74,8 @@ foreach ($tables as $tablevalue) {
['value' => 14, 'generic' => 0, 'graph' => 0, 'descr' => 'active'],
['value' => 15, 'generic' => 1, 'graph' => 0, 'descr' => 'activeExtraload'],
['value' => 16, 'generic' => 1, 'graph' => 0, 'descr' => 'activeHandback'],
];
} elseif ($state_name == 'cRFCfgRedundancyOperMode') {
$states = [
],
'cRFCfgRedundancyOperMode' => [
['value' => 1, 'generic' => 0, 'graph' => 0, 'descr' => 'nonRedundant'],
['value' => 2, 'generic' => 0, 'graph' => 0, 'descr' => 'staticLoadShareNonRedundant'],
['value' => 3, 'generic' => 0, 'graph' => 0, 'descr' => 'dynamicLoadShareNonRedundant'],
@@ -85,21 +84,18 @@ foreach ($tables as $tablevalue) {
['value' => 6, 'generic' => 0, 'graph' => 0, 'descr' => 'coldStandbyRedundant'],
['value' => 7, 'generic' => 0, 'graph' => 0, 'descr' => 'warmStandbyRedundant'],
['value' => 8, 'generic' => 0, 'graph' => 0, 'descr' => 'hotStandbyRedundant'],
];
} elseif ($state_name == 'cswRingRedundant') {
$states = [
],
'cswRingRedundant' => [
['value' => 1, 'generic' => 0, 'graph' => 0, 'descr' => 'true'],
['value' => 2, 'generic' => 2, 'graph' => 0, 'descr' => 'false'],
];
} elseif ($state_name == 'cswSwitchRole') {
$states = [
],
'cswSwitchRole' => [
['value' => 1, 'generic' => 0, 'graph' => 0, 'descr' => 'master'],
['value' => 2, 'generic' => 0, 'graph' => 0, 'descr' => 'member'],
['value' => 3, 'generic' => 0, 'graph' => 0, 'descr' => 'notMember'],
['value' => 4, 'generic' => 0, 'graph' => 0, 'descr' => 'standby'],
];
} elseif ($state_name == 'cswSwitchState') {
$states = [
],
'cswSwitchState' => [
['value' => 1, 'generic' => 1, 'graph' => 0, 'descr' => 'waiting'],
['value' => 2, 'generic' => 1, 'graph' => 0, 'descr' => 'progressing'],
['value' => 3, 'generic' => 1, 'graph' => 0, 'descr' => 'added'],
@@ -111,9 +107,8 @@ foreach ($tables as $tablevalue) {
['value' => 9, 'generic' => 1, 'graph' => 0, 'descr' => 'provisioned'],
['value' => 10, 'generic' => 2, 'graph' => 0, 'descr' => 'invalid'],
['value' => 11, 'generic' => 1, 'graph' => 0, 'descr' => 'removed'],
];
} elseif ($state_name == 'cefcFRUPowerOperStatus') {
$states = [
],
'cefcFRUPowerOperStatus' => [
['value' => 1, 'generic' => 2, 'graph' => 0, 'descr' => 'off (other)'],
['value' => 2, 'generic' => 0, 'graph' => 0, 'descr' => 'on'],
['value' => 3, 'generic' => 1, 'graph' => 0, 'descr' => 'off (admin)'],
@@ -126,16 +121,14 @@ foreach ($tables as $tablevalue) {
['value' => 10, 'generic' => 2, 'graph' => 0, 'descr' => 'off (cooling)'],
['value' => 11, 'generic' => 2, 'graph' => 0, 'descr' => 'off (connector rating)'],
['value' => 12, 'generic' => 1, 'graph' => 0, 'descr' => 'on (no inline power)'],
];
} elseif ($state_name == 'c3gModemStatus') {
$states = [
],
'c3gModemStatus' => [
['value' => 1, 'generic' => 3, 'graph' => 0, 'descr' => 'unknown'],
['value' => 2, 'generic' => 2, 'graph' => 0, 'descr' => 'offline'],
['value' => 3, 'generic' => 0, 'graph' => 0, 'descr' => 'online'],
['value' => 4, 'generic' => 1, 'graph' => 0, 'descr' => 'low power mode'],
];
} elseif ($state_name == 'c3gGsmCurrentBand') {
$states = [
],
'c3gGsmCurrentBand' => [
['value' => 1, 'generic' => 3, 'graph' => 0, 'descr' => 'unknown'],
['value' => 2, 'generic' => 2, 'graph' => 0, 'descr' => 'invalid'],
['value' => 3, 'generic' => 3, 'graph' => 0, 'descr' => 'none'],
@@ -148,9 +141,8 @@ foreach ($tables as $tablevalue) {
['value' => 10, 'generic' => 0, 'graph' => 0, 'descr' => 'wcdma1900'],
['value' => 11, 'generic' => 0, 'graph' => 0, 'descr' => 'wcdma2100'],
['value' => 12, 'generic' => 0, 'graph' => 0, 'descr' => 'lte band'],
];
} elseif ($state_name == 'c3gGsmPacketService') {
$states = [
],
'c3gGsmPacketService' => [
['value' => 1, 'generic' => 3, 'graph' => 0, 'descr' => 'unknown'],
['value' => 2, 'generic' => 1, 'graph' => 0, 'descr' => 'none'],
['value' => 3, 'generic' => 0, 'graph' => 0, 'descr' => 'gprs'],
@@ -161,15 +153,13 @@ foreach ($tables as $tablevalue) {
['value' => 8, 'generic' => 0, 'graph' => 0, 'descr' => 'hspa'],
['value' => 9, 'generic' => 0, 'graph' => 0, 'descr' => 'hspa plus'],
['value' => 10, 'generic' => 0, 'graph' => 0, 'descr' => 'lte'],
];
} elseif ($state_name == 'c3gGsmCurrentRoamingStatus') {
$states = [
],
'c3gGsmCurrentRoamingStatus' => [
['value' => 1, 'generic' => 3, 'graph' => 0, 'descr' => 'unknown'],
['value' => 2, 'generic' => 0, 'graph' => 0, 'descr' => 'roaming'],
['value' => 3, 'generic' => 0, 'graph' => 0, 'descr' => 'home'],
];
} elseif ($state_name == 'c3gGsmSimStatus') {
$states = [
],
'c3gGsmSimStatus' => [
['value' => 1, 'generic' => 3, 'graph' => 0, 'descr' => 'unknown'],
['value' => 2, 'generic' => 0, 'graph' => 0, 'descr' => 'ok'],
['value' => 3, 'generic' => 0, 'graph' => 0, 'descr' => 'not inserted'],
@@ -183,28 +173,26 @@ foreach ($tables as $tablevalue) {
['value' => 11, 'generic' => 2, 'graph' => 0, 'descr' => 'wcchv2Rejecteddma2100'],
['value' => 12, 'generic' => 2, 'graph' => 0, 'descr' => 'mepLocked'],
['value' => 13, 'generic' => 2, 'graph' => 0, 'descr' => 'networkRejected'],
];
} elseif ($state_name == 'crepSegmentComplete') {
$states = [
],
'crepSegmentComplete' => [
['value' => 0, 'generic' => 3, 'graph' => 0, 'descr' => 'unknown'],
['value' => 1, 'generic' => 0, 'graph' => 0, 'descr' => 'complete'],
['value' => 2, 'generic' => 2, 'graph' => 0, 'descr' => 'incomplete'],
];
} else {
$states = [
],
default => [
['value' => 1, 'generic' => 0, 'graph' => 0, 'descr' => 'normal'],
['value' => 2, 'generic' => 1, 'graph' => 0, 'descr' => 'warning'],
['value' => 3, 'generic' => 2, 'graph' => 0, 'descr' => 'critical'],
['value' => 4, 'generic' => 3, 'graph' => 0, 'descr' => 'shutdown'],
['value' => 5, 'generic' => 3, 'graph' => 0, 'descr' => 'notPresent'],
['value' => 6, 'generic' => 2, 'graph' => 0, 'descr' => 'notFunctioning'],
];
}
],
};
create_state_index($state_name, $states);
foreach ($temp as $index => $entry) {
$state_group = null;
if ($tablevalue['state_name'] == 'ciscoEnvMonTemperatureState' && (empty($entry[$tablevalue['descr']]))) {
if ($state_name == 'ciscoEnvMonTemperatureState' && (empty($entry[$tablevalue['descr']]))) {
d_echo('Invalid sensor, skipping..');
} else {
//Discover Sensors
@@ -221,15 +209,15 @@ foreach ($tables as $tablevalue) {
$stack_port_descr = get_port_by_index_cache($device['device_id'], $index);
$descr = $tablevalue['descr'] . $stack_port_descr['ifDescr'];
} elseif ($state_name == 'cefcFRUPowerOperStatus') {
$descr = snmp_get($device, 'entPhysicalName.' . $index, '-Oqv', 'ENTITY-MIB');
$descr = SnmpQuery::get('ENTITY-MIB::entPhysicalName.' . $index)->value();
} elseif ($state_name == 'c3gModemStatus' || $state_name == 'c3gGsmCurrentBand' || $state_name == 'c3gGsmPacketService' || $state_name == 'c3gGsmCurrentRoamingStatus' || $state_name == 'c3gGsmSimStatus') {
$descr = $tablevalue['descr'];
$state_group = snmp_get($device, 'entPhysicalName.' . $index, '-Oqv', 'ENTITY-MIB');
$state_group = SnmpQuery::get('ENTITY-MIB::entPhysicalName.' . $index)->value();
} elseif ($state_name == 'crepSegmentComplete') {
$repsegmentnumber++;
$descr = $tablevalue['descr'] . $repsegmentnumber;
}
discover_sensor(null, 'state', $device, $cur_oid . $index, $index, $state_name, trim($descr), 1, 1, null, null, null, null, $entry[$tablevalue['state_name']], 'snmp', $index, null, null, $state_group);
discover_sensor(null, 'state', $device, $cur_oid . $index, $index, $state_name, trim($descr), 1, 1, null, null, null, null, $entry[$state_name], 'snmp', $index, null, null, $state_group);
//Create Sensor To State Index
create_sensor_to_state_index($device, $state_name, $index);
@@ -238,4 +226,4 @@ foreach ($tables as $tablevalue) {
}
}
unset($role_data, $redundant_data);
unset($role_data, $redundant_data, $temp);