Apply fixes from StyleCI (#12120)

This commit is contained in:
Jellyfrog
2020-09-21 15:40:17 +02:00
committed by GitHub
parent 77c531527c
commit 82f43cb98d
1733 changed files with 18337 additions and 18540 deletions

View File

@@ -40,16 +40,16 @@ if ($device['os_group'] == 'cisco') {
d_echo($oids);
$entitysensor['voltsDC'] = 'voltage';
$entitysensor['voltsAC'] = 'voltage';
$entitysensor['amperes'] = 'current';
$entitysensor['watt'] = 'power';
$entitysensor['hertz'] = 'freq';
$entitysensor['voltsDC'] = 'voltage';
$entitysensor['voltsAC'] = 'voltage';
$entitysensor['amperes'] = 'current';
$entitysensor['watt'] = 'power';
$entitysensor['hertz'] = 'freq';
$entitysensor['percentRH'] = 'humidity';
$entitysensor['rpm'] = 'fanspeed';
$entitysensor['celsius'] = 'temperature';
$entitysensor['watts'] = 'power';
$entitysensor['dBm'] = 'dbm';
$entitysensor['rpm'] = 'fanspeed';
$entitysensor['celsius'] = 'temperature';
$entitysensor['watts'] = 'power';
$entitysensor['dBm'] = 'dbm';
if (is_array($oids)) {
foreach ($oids as $index => $entry) {
@@ -65,55 +65,55 @@ if ($device['os_group'] == 'cisco') {
// Set description based on measured entity if it exists
if (is_numeric($entry['entSensorMeasuredEntity']) && $entry['entSensorMeasuredEntity']) {
$measured_descr = $entity_array[$entry['entSensorMeasuredEntity']]['entPhysicalName'];
if (!$measured_descr) {
if (! $measured_descr) {
$measured_descr = $entity_array[$entry['entSensorMeasuredEntity']]['entPhysicalDescr'];
}
$descr = $measured_descr.' - '.$descr;
$descr = $measured_descr . ' - ' . $descr;
}
// Bit dirty also, clean later
$descr = str_replace('Temp: ', '', $descr);
$descr = str_ireplace('temperature ', '', $descr);
$oid = '.1.3.6.1.4.1.9.9.91.1.1.1.1.4.'.$index;
$oid = '.1.3.6.1.4.1.9.9.91.1.1.1.1.4.' . $index;
$current = $entry['entSensorValue'];
$type = $entitysensor[$entry['entSensorType']];
$type = $entitysensor[$entry['entSensorType']];
// echo("$index : ".$entry['entSensorScale']."|");
// FIXME this stuff is foul
if ($entry['entSensorScale'] == 'nano') {
$divisor = '1000000000';
$divisor = '1000000000';
$multiplier = '1';
}
if ($entry['entSensorScale'] == 'micro') {
$divisor = '1000000';
$divisor = '1000000';
$multiplier = '1';
}
if ($entry['entSensorScale'] == 'milli') {
$divisor = '1000';
$divisor = '1000';
$multiplier = '1';
}
if ($entry['entSensorScale'] == 'units') {
$divisor = '1';
$divisor = '1';
$multiplier = '1';
}
if ($entry['entSensorScale'] == 'kilo') {
$divisor = '1';
$divisor = '1';
$multiplier = '1000';
}
if ($entry['entSensorScale'] == 'mega') {
$divisor = '1';
$divisor = '1';
$multiplier = '1000000';
}
if ($entry['entSensorScale'] == 'giga') {
$divisor = '1';
$divisor = '1';
$multiplier = '1000000000';
}
@@ -122,15 +122,15 @@ if ($device['os_group'] == 'cisco') {
// Workaround for a Cisco SNMP bug
&& $entry['entSensorPrecision'] != '1615384784'
) {
$divisor = $divisor.str_pad('', $entry['entSensorPrecision'], '0');
$divisor = $divisor . str_pad('', $entry['entSensorPrecision'], '0');
}
$current = ($current * $multiplier / $divisor);
// Set thresholds to null
$limit = null;
$limit_low = null;
$warn_limit = null;
$limit = null;
$limit_low = null;
$warn_limit = null;
$warn_limit_low = null;
// Check thresholds for this entry (bit dirty, but it works!)
@@ -186,10 +186,10 @@ if ($device['os_group'] == 'cisco') {
}
if ($entity_array[$phys_index]['entPhysicalClass'] === 'port') {
if (Str::contains($entity_array[$phys_index][0]['entAliasMappingIdentifier'], 'ifIndex.')) {
list(, $tmp_ifindex) = explode(".", $entity_array[$phys_index][0]['entAliasMappingIdentifier']);
[, $tmp_ifindex] = explode(".", $entity_array[$phys_index][0]['entAliasMappingIdentifier']);
$tmp_port = get_port_by_index_cache($device['device_id'], $tmp_ifindex);
if (is_array($tmp_port)) {
$entPhysicalIndex = $tmp_ifindex;
$entPhysicalIndex = $tmp_ifindex;
$entry['entSensorMeasuredEntity'] = 'ports';
}
}
@@ -199,19 +199,19 @@ if ($device['os_group'] == 'cisco') {
}
}
discover_sensor($valid['sensor'], $type, $device, $oid, $index, 'cisco-entity-sensor', ucwords($descr), $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current, 'snmp', $entPhysicalIndex, $entry['entSensorMeasuredEntity'], null);
#Cisco IOS-XR : add a fake sensor to graph as dbm
//Cisco IOS-XR : add a fake sensor to graph as dbm
if ($type == "power" and $device['os'] == "iosxr" and (preg_match("/power (R|T)x/i", $descr) or preg_match("/(R|T)x Power/i", $descr))) {
// convert Watts to dbm
$type = "dbm";
$limit_low = 10 * log10($limit_low*1000);
$warn_limit_low = 10 * log10($warn_limit_low*1000);
$warn_limit = 10 * log10($warn_limit*1000);
$limit = 10 * log10($limit*1000);
$current = round(10 * log10($current*1000), 3);
$multiplier = 1;
$divisor = 1;
//echo("\n".$valid['sensor'].", $type, $device, $oid, $index, 'cisco-entity-sensor', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current");
discover_sensor($valid['sensor'], $type, $device, $oid, $index, 'cisco-entity-sensor', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current, 'snmp', $entPhysicalIndex, $entry['entSensorMeasuredEntity'], null);
// convert Watts to dbm
$type = "dbm";
$limit_low = 10 * log10($limit_low * 1000);
$warn_limit_low = 10 * log10($warn_limit_low * 1000);
$warn_limit = 10 * log10($warn_limit * 1000);
$limit = 10 * log10($limit * 1000);
$current = round(10 * log10($current * 1000), 3);
$multiplier = 1;
$divisor = 1;
//echo("\n".$valid['sensor'].", $type, $device, $oid, $index, 'cisco-entity-sensor', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current");
discover_sensor($valid['sensor'], $type, $device, $oid, $index, 'cisco-entity-sensor', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current, 'snmp', $entPhysicalIndex, $entry['entSensorMeasuredEntity'], null);
}
}