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

Apply fixes from StyleCI #31

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions LibreNMS/OS/Comware.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function discoverTransceiverMetrics(Collection $transceivers): Collection
'oid' => ".1.3.6.1.4.1.25506.2.70.1.1.1.9.$ifIndex",
'value' => $transceiver['HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiverCurTXPower'] / 100, // dBm
'divisor' => 100,
]), $transceiver, 'PwrOut', fn($v) => Convert::uwToDbm($v / 10)));
]), $transceiver, 'PwrOut', fn ($v) => Convert::uwToDbm($v / 10)));
}

// RX Power
Expand All @@ -161,7 +161,7 @@ public function discoverTransceiverMetrics(Collection $transceivers): Collection
'oid' => ".1.3.6.1.4.1.25506.2.70.1.1.1.12.$ifIndex",
'value' => $transceiver['HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiverCurRXPower'] / 100,
'divisor' => 100,
]), $transceiver, 'RcvPwr', fn($v) => Convert::uwToDbm($v / 10)));
]), $transceiver, 'RcvPwr', fn ($v) => Convert::uwToDbm($v / 10)));
}

// Temperature
Expand Down Expand Up @@ -193,7 +193,7 @@ public function discoverTransceiverMetrics(Collection $transceivers): Collection
'oid' => ".1.3.6.1.4.1.25506.2.70.1.1.1.17.$ifIndex",
'value' => $transceiver['HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiverVoltage'],
'divisor' => 100,
]), $transceiver, 'Vcc', fn($v) => $v / 10000));
]), $transceiver, 'Vcc', fn ($v) => $v / 10000));
}

// Channels
Expand All @@ -220,7 +220,7 @@ public function discoverTransceiverMetrics(Collection $transceivers): Collection
'oid' => ".1.3.6.1.4.1.25506.2.70.1.2.1.2.$ifIndex.$channel",
'value' => $channelDatum['HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiverChannelCurTXPower'] / 100,
'divisor' => 100,
]), $transceiver, 'PwrOut', fn($v) => Convert::uwToDbm($v / 10)));
]), $transceiver, 'PwrOut', fn ($v) => Convert::uwToDbm($v / 10)));
}

// RX Power
Expand All @@ -232,7 +232,7 @@ public function discoverTransceiverMetrics(Collection $transceivers): Collection
'oid' => ".1.3.6.1.4.1.25506.2.70.1.2.1.3.$ifIndex.$channel",
'value' => $channelDatum['HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiverChannelCurTXPower'] / 100,
'divisor' => 100,
]), $transceiver, 'RcvPwr', fn($v) => Convert::uwToDbm($v / 10)));
]), $transceiver, 'RcvPwr', fn ($v) => Convert::uwToDbm($v / 10)));
}

// Bias Current
Expand All @@ -255,10 +255,10 @@ public function discoverTransceiverMetrics(Collection $transceivers): Collection

private function setTransceiverThresholds(TransceiverMetric $metric, array $data, string $slug, callable $transform = null): TransceiverMetric
{
$transform ??= fn($v) => $v; // default do nothing transform
$transform ??= fn ($v) => $v; // default do nothing transform
$metric->threshold_min_critical = ! empty($data["HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiver{$slug}LoAlarm"]) ? $transform($data["HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiver{$slug}LoAlarm"]) : null;
$metric->threshold_min_warning = ! empty($data["HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiver{$slug}LoWarn"]) ? $transform($data["HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiver{$slug}LoWarn"]) : null;
$metric->threshold_max_warning = ! empty($data["HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiver{$slug}HiWarn"]) ? $transform($data["HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiver{$slug}HiWarn"]) : null;
$metric->threshold_min_warning = ! empty($data["HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiver{$slug}LoWarn"]) ? $transform($data["HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiver{$slug}LoWarn"]) : null;
$metric->threshold_max_warning = ! empty($data["HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiver{$slug}HiWarn"]) ? $transform($data["HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiver{$slug}HiWarn"]) : null;
$metric->threshold_max_critical = ! empty($data["HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiver{$slug}HiAlarm"]) ? $transform($data["HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiver{$slug}HiAlarm"]) : null;

return $metric;
Expand Down
2 changes: 1 addition & 1 deletion LibreNMS/OS/Exa.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function discoverTransceiverMetrics(Collection $transceivers): Collection
'type' => 'bias',
'oid' => ".1.3.6.1.4.1.6321.1.2.2.2.1.6.2.1.6.$index",
'value' => $portData['E7-Calix-MIB::e7OltPonPortTxBias'] / 1000,
'divisor' => 1000
'divisor' => 1000,
]));
}

Expand Down
9 changes: 4 additions & 5 deletions LibreNMS/OS/Junos.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,12 @@ public function discoverTransceiverMetrics(Collection $transceivers): Collection
'oid' => ".1.3.6.1.4.1.2636.3.60.1.1.1.1.6.$ifIndex",
'value' => $data['JUNIPER-DOM-MIB::jnxDomCurrentModuleVoltage'] / 1000,
'divisor' => 1000,
'threshold_min_critical' => isset($data['JUNIPER-DOM-MIB::jnxDomCurrentModuleVoltageCurrentLowAlarmThreshold']) ? $data['JUNIPER-DOM-MIB::jnxDomCurrentModuleVoltageCurrentLowAlarmThreshold'] / 1000 : null,
'threshold_min_warning' => isset($data['JUNIPER-DOM-MIB::jnxDomCurrentModuleVoltageCurrentLowWarningThreshold']) ? $data['JUNIPER-DOM-MIB::jnxDomCurrentModuleVoltageCurrentLowWarningThreshold'] / 1000 : null,
'threshold_max_warning' => isset($data['JUNIPER-DOM-MIB::jnxDomCurrentModuleVoltageCurrentHighWarningThreshold']) ? $data['JUNIPER-DOM-MIB::jnxDomCurrentModuleVoltageCurrentHighWarningThreshold'] / 1000 : null,
'threshold_max_critical' => isset($data['JUNIPER-DOM-MIB::jnxDomCurrentModuleVoltageCurrentHighAlarmThreshold']) ? $data['JUNIPER-DOM-MIB::jnxDomCurrentModuleVoltageCurrentHighAlarmThreshold'] / 1000 : null,
'threshold_min_critical' => isset($data['JUNIPER-DOM-MIB::jnxDomCurrentModuleVoltageCurrentLowAlarmThreshold']) ? $data['JUNIPER-DOM-MIB::jnxDomCurrentModuleVoltageCurrentLowAlarmThreshold'] / 1000 : null,
'threshold_min_warning' => isset($data['JUNIPER-DOM-MIB::jnxDomCurrentModuleVoltageCurrentLowWarningThreshold']) ? $data['JUNIPER-DOM-MIB::jnxDomCurrentModuleVoltageCurrentLowWarningThreshold'] / 1000 : null,
'threshold_max_warning' => isset($data['JUNIPER-DOM-MIB::jnxDomCurrentModuleVoltageCurrentHighWarningThreshold']) ? $data['JUNIPER-DOM-MIB::jnxDomCurrentModuleVoltageCurrentHighWarningThreshold'] / 1000 : null,
'threshold_max_critical' => isset($data['JUNIPER-DOM-MIB::jnxDomCurrentModuleVoltageCurrentHighAlarmThreshold']) ? $data['JUNIPER-DOM-MIB::jnxDomCurrentModuleVoltageCurrentHighAlarmThreshold'] / 1000 : null,
]));
}

}

return $metrics;
Expand Down
4 changes: 1 addition & 3 deletions LibreNMS/OS/Ocnos.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

class Ocnos extends OS implements TransceiverDiscovery
{

public function discoverTransceivers(): Collection
{
return SnmpQuery::enumStrings()->walk('IPI-CMM-CHASSIS-MIB::cmmTransEEPROMTable')->mapTable(function ($data, $cmmStackUnitIndex, $cmmTransIndex) {
Expand All @@ -45,7 +44,7 @@ public function discoverTransceivers(): Collection
$distance = $data['IPI-CMM-CHASSIS-MIB::cmmTransLengthKmtrs'] * 1000;
} elseif (! empty($data['IPI-CMM-CHASSIS-MIB::cmmTransLengthOM4']) && $data['IPI-CMM-CHASSIS-MIB::cmmTransLengthOM4'] !== '-100002') {
$distance = (int) $data['IPI-CMM-CHASSIS-MIB::cmmTransLengthOM4'];
} elseif (! empty($data['IPI-CMM-CHASSIS-MIB::cmmTransLengthOM3'] )&& $data['IPI-CMM-CHASSIS-MIB::cmmTransLengthOM3'] !== '-100002') {
} elseif (! empty($data['IPI-CMM-CHASSIS-MIB::cmmTransLengthOM3']) && $data['IPI-CMM-CHASSIS-MIB::cmmTransLengthOM3'] !== '-100002') {
$distance = (int) $data['IPI-CMM-CHASSIS-MIB::cmmTransLengthOM3'];
} elseif (! empty($data['IPI-CMM-CHASSIS-MIB::cmmTransLengthOM2']) && $data['IPI-CMM-CHASSIS-MIB::cmmTransLengthOM2'] !== '-100002') {
$distance = (int) $data['IPI-CMM-CHASSIS-MIB::cmmTransLengthOM2'];
Expand Down Expand Up @@ -148,7 +147,6 @@ public function discoverTransceiverMetrics(Collection $transceivers): Collection
return $metrics;
}


private function getTransceiverMetric(Transceiver $transceiver, int $snmp_field_index, string $chassis, string $module, string $channel, array $data, string $type, string $slug, string $threshold_slug = null): TransceiverMetric
{
$divisor = 100;
Expand Down
1 change: 1 addition & 0 deletions LibreNMS/OS/Routeros.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ public function discoverTransceivers(): Collection

return \SnmpQuery::cache()->walk('MIKROTIK-MIB::mtxrOpticalTable')->mapTable(function ($data, $ifIndex) use ($ifIndexToPortId) {
$wavelength = $data['MIKROTIK-MIB::mtxrOpticalWavelength'] ?? null;

return new Transceiver([
'port_id' => $ifIndexToPortId->get($ifIndex),
'index' => $ifIndex,
Expand Down
1 change: 1 addition & 0 deletions LibreNMS/Util/Convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static function uwToDbm(int|float|string|null $microWatt): float|int
{
return $microWatt == 0 ? -60 : 10 * log10($microWatt / 1000);
}

public static function mwToDbm(int|float|string|null $milliWatt): float|int
{
return $milliWatt == 0 ? -60 : 10 * log10($milliWatt);
Expand Down
1 change: 0 additions & 1 deletion includes/discovery/transceivers.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* @author Tony Murray <murraytony@gmail.com>
*/


use LibreNMS\OS;

if (! $os instanceof OS) {
Expand Down