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

Update TrueNASCORE livestats to differentiate between notices/info and alerts that need immediate attention #671

Merged
merged 2 commits into from
Jan 26, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions TrueNASCORE/TrueNASCORE.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace App\SupportedApps\TrueNASCORE;

class TrueNASCORE extends \App\SupportedApps implements \App\EnhancedApps

Check failure on line 3 in TrueNASCORE/TrueNASCORE.php

View workflow job for this annotation

GitHub Actions / Lint Code Base

Class App\SupportedApps\TrueNASCORE\TrueNASCORE extends unknown class App\SupportedApps.

Check failure on line 3 in TrueNASCORE/TrueNASCORE.php

View workflow job for this annotation

GitHub Actions / Lint Code Base

Class App\SupportedApps\TrueNASCORE\TrueNASCORE implements unknown interface App�nhancedApps.
{
public $config;

Expand All @@ -14,7 +14,7 @@

public function test()
{
$test = parent::appTest($this->url("core/ping"), $this->attrs());

Check failure on line 17 in TrueNASCORE/TrueNASCORE.php

View workflow job for this annotation

GitHub Actions / Lint Code Base

App\SupportedApps\TrueNASCORE\TrueNASCORE::test() calls parent::appTest() but App\SupportedApps\TrueNASCORE\TrueNASCORE does not extend any class.
if ($test->code === 200) {
$data = $test->response;
if ($test->response != '"pong"') {
Expand All @@ -29,22 +29,22 @@
$status = "inactive";
$data = [];

$res = parent::execute($this->url("system/info"), $this->attrs());

Check failure on line 32 in TrueNASCORE/TrueNASCORE.php

View workflow job for this annotation

GitHub Actions / Lint Code Base

App\SupportedApps\TrueNASCORE\TrueNASCORE::livestats() calls parent::execute() but App\SupportedApps\TrueNASCORE\TrueNASCORE does not extend any class.
$details = json_decode($res->getBody());
$seconds = $details->uptime_seconds ?? 0;
$data["uptime"] = $this->uptime($seconds);

$res = parent::execute($this->url("alert/list"), $this->attrs());

Check failure on line 37 in TrueNASCORE/TrueNASCORE.php

View workflow job for this annotation

GitHub Actions / Lint Code Base

App\SupportedApps\TrueNASCORE\TrueNASCORE::livestats() calls parent::execute() but App\SupportedApps\TrueNASCORE\TrueNASCORE does not extend any class.
$details = json_decode($res->getBody(), true);
$data["alert_tot"] = $this->alerts($details);
list($data["alert_tot"], $data["alert_crit"]) = $this->alerts($details);

return parent::getLiveStats($status, $data);

Check failure on line 41 in TrueNASCORE/TrueNASCORE.php

View workflow job for this annotation

GitHub Actions / Lint Code Base

App\SupportedApps\TrueNASCORE\TrueNASCORE::livestats() calls parent::getLiveStats() but App\SupportedApps\TrueNASCORE\TrueNASCORE does not extend any class.
}

public function url($endpoint)
{
$api_url =
parent::normaliseurl($this->config->url) . "api/v2.0/" . $endpoint;

Check failure on line 47 in TrueNASCORE/TrueNASCORE.php

View workflow job for this annotation

GitHub Actions / Lint Code Base

App\SupportedApps\TrueNASCORE\TrueNASCORE::url() calls parent::normaliseurl() but App\SupportedApps\TrueNASCORE\TrueNASCORE does not extend any class.
return $api_url;
}

Expand Down Expand Up @@ -109,14 +109,17 @@

public function alerts($alert)
{
$count = 0;
$count_total = $count_critical = 0;
foreach ($alert as $key => $value) {
if ($value["dismissed"] == false) {
$count += 1;
$count_total += 1;
if (!in_array($value["level"], array("NOTICE", "INFO"))) {
mvdkleijn marked this conversation as resolved.
Show resolved Hide resolved
$count_critical += 1;
}
}
}

return strval($count);
return array(strval($count_total), strval($count_critical));
}

public function getConfigValue($key, $default = null)
Expand Down
2 changes: 1 addition & 1 deletion TrueNASCORE/livestats.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
</li>
<li>
<span class="title">Alerts</span>
<strong>{!! $alert_tot !!}</strong>
<strong>{!! $alert_tot !!} / <span style="background-color: #d64d55; padding: 3px; color: white; font-size: 12px; border-radius: 3px; opacity: 1;">{!! $alert_crit !!}</span></strong>
mvdkleijn marked this conversation as resolved.
Show resolved Hide resolved
</li>
</ul>
Loading