Skip to content
Open
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
10 changes: 6 additions & 4 deletions app/Http/Formatters/AlertLogDetailFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private function formatPort(array $detail): ?string
($port->ifAlias && $port->ifAlias != $port->ifDescr)
? $this->line('Alias', $port->ifAlias)
: null,
!empty($detail['isisISAdjState'])
! empty($detail['isisISAdjState'])
? $this->line('Adjacent', $detail['isisISAdjIPAddrAddress'] ?? 'Unknown')
: null,
]);
Expand Down Expand Up @@ -243,7 +243,7 @@ private function formatApplication(array $detail): ?string
return $this->lines([
$this->linkLine('Application', $app_url, $app_type),
$this->line('Status', $detail['app_status'] ?? null),
!empty($detail['metric'])
! empty($detail['metric'])
? $this->line('Metric', e($detail['metric']) . ' = ' . e($detail['value'] ?? 'N/A'), escape: false)
: null,
]);
Expand All @@ -263,6 +263,7 @@ private function line(string $label, mixed $value, bool $escape = true): ?string
}

$formatted_value = $escape ? e($value) : $value;

return $label . ': ' . $formatted_value;
}

Expand All @@ -279,7 +280,8 @@ private function linkLine(string $label, string $url, string $text): string
*/
private function inlineList(array $items): ?string
{
$filtered = array_filter($items, fn($item) => $item !== null && $item !== '');
$filtered = array_filter($items, fn ($item) => $item !== null && $item !== '');

return empty($filtered) ? null : implode(', ', $filtered);
}

Expand All @@ -288,6 +290,6 @@ private function inlineList(array $items): ?string
*/
private function lines(array $lines): string
{
return implode('<br>', array_filter($lines, fn($line) => $line !== null && $line !== ''));
return implode('<br>', array_filter($lines, fn ($line) => $line !== null && $line !== ''));
}
}
72 changes: 36 additions & 36 deletions tests/Unit/Http/Formatters/AlertLogDetailFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function testFormatBasicRuleAlert(): void
{
$details = [
'rule' => [
['message' => 'Test alert', 'value' => 10]
]
['message' => 'Test alert', 'value' => 10],
],
];

$output = $this->formatter->format($details);
Expand All @@ -35,15 +35,15 @@ public function testFormatAlertWithDiff(): void
$details = [
'diff' => [
'added' => [
['message' => 'New item']
['message' => 'New item'],
],
'resolved' => [
['message' => 'Fixed item']
]
['message' => 'Fixed item'],
],
],
'rule' => [
['message' => 'Still alert']
]
['message' => 'Still alert'],
],
];

$output = $this->formatter->format($details);
Expand All @@ -61,9 +61,9 @@ public function testFormatBill(): void
'rule' => [
[
'bill_id' => 123,
'bill_name' => 'Test Bill'
]
]
'bill_name' => 'Test Bill',
],
],
];

$output = $this->formatter->format($details);
Expand All @@ -82,8 +82,8 @@ public function testFormatPort(): void
'device_id' => 1,
'ifDescr' => 'eth0',
'ifAlias' => 'WAN Interface',
]
]
],
],
];

$output = $this->formatter->format($details);
Expand All @@ -104,9 +104,9 @@ public function testFormatSensor(): void
'sensor_current' => 35,
'sensor_limit' => 40,
'sensor_limit_warn' => 38,
'sensor_descr' => 'CPU Temp'
]
]
'sensor_descr' => 'CPU Temp',
],
],
];

$output = $this->formatter->format($details);
Expand All @@ -128,9 +128,9 @@ public function testFormatSensorState(): void
'sensor_current' => 2,
'state_descr' => 'Critical',
'state_value' => 2, // Used by StateTranslation if constructor receives it
'sensor_descr' => 'Power State'
]
]
'sensor_descr' => 'Power State',
],
],
];

$output = $this->formatter->format($details);
Expand All @@ -147,9 +147,9 @@ public function testFormatAccessPoint(): void
[
'accesspoint_id' => 101,
'device_id' => 1,
'name' => 'AP-01'
]
]
'name' => 'AP-01',
],
],
];

$output = $this->formatter->format($details);
Expand All @@ -170,9 +170,9 @@ public function testFormatService(): void
'service_type' => 'http',
'service_ip' => '1.2.3.4',
'service_desc' => 'Web Service',
'service_message' => 'Connection refused'
]
]
'service_message' => 'Connection refused',
],
],
];

$output = $this->formatter->format($details);
Expand All @@ -195,9 +195,9 @@ public function testFormatBgpPeer(): void
'bgpPeerIdentifier' => '10.0.0.1',
'bgpPeerDescr' => 'ISP-A',
'bgpPeerRemoteAs' => 65001,
'bgpPeerState' => 'idle'
]
]
'bgpPeerState' => 'idle',
],
],
];

$output = $this->formatter->format($details);
Expand All @@ -219,9 +219,9 @@ public function testFormatMempool(): void
'mempool_descr' => 'System RAM',
'mempool_perc' => 85.5,
'mempool_free' => 1024 * 1024 * 100, // 100MB
'mempool_total' => 1024 * 1024 * 1024 // 1GB
]
]
'mempool_total' => 1024 * 1024 * 1024, // 1GB
],
],
];

$output = $this->formatter->format($details);
Expand All @@ -244,9 +244,9 @@ public function testFormatApplication(): void
'app_type' => 'nginx',
'app_status' => 'up',
'metric' => 'requests',
'value' => 5000
]
]
'value' => 5000,
],
],
];

$output = $this->formatter->format($details);
Expand All @@ -267,9 +267,9 @@ public function testFallbackFormatting(): void
'device_id' => 1, // should be skipped
'some_id' => 123, // should be skipped (contains id)
'description' => 'test', // should be skipped (contains desc)
'another_val' => 'present'
]
]
'another_val' => 'present',
],
],
];

$output = $this->formatter->format($details);
Expand Down
Loading