Skip to content

Commit

Permalink
Merge branch 'linuxserver:master' into EnhancedGotify
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroBuffon authored Jul 13, 2024
2 parents fb2a18e + 95926bd commit 246f80f
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 5 deletions.
101 changes: 100 additions & 1 deletion Glances/Glances.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,105 @@

namespace App\SupportedApps\Glances;

class Glances extends \App\SupportedApps
class Glances extends \App\SupportedApps implements \App\EnhancedApps
{
public $config;

public function __construct()
{
}

public function test()
{
$test = parent::appTest($this->url("status"));
echo $test->status;
}

public function livestats()
{
$status = "inactive";
$details = [];

if (isset($this->config->availablestats) && is_array($this->config->availablestats)) {
$details = ["visiblestats" => []];
foreach ($this->config->availablestats as $stat) {
$newstat = new \stdClass();
$availableStats = self::getAvailableStats();

if (isset($availableStats[$stat])) {
$newstat->title = $availableStats[$stat];

// Fetch CpuTotal
if ($stat === "CpuTotal") {
$Response = parent::execute($this->url("cpu/total"));
$result = json_decode($Response->getBody());
if (isset($result->total)) {
$newstat->value = $result->total;
} else {
$newstat->value = null; // or some default value
}
}

// Fetch MemTotal
if ($stat === "MemTotal") {
$Response = parent::execute($this->url("mem/total"));
$result = json_decode($Response->getBody());
if (isset($result->total)) {
$newstat->value = $this->convertBytesToGigabytes($result->total);
} else {
$newstat->value = null; // or some default value
}
}

// Fetch MemAvail
if ($stat === "MemAvail") {
$Response = parent::execute($this->url("mem/available"));
$result = json_decode($Response->getBody());
if (isset($result->available)) {
$newstat->value = $this->convertBytesToGigabytes($result->available);
} else {
$newstat->value = null; // or some default value
}
}

// Fetch MemAvail
if ($stat === "MemUsage") {
$Response = parent::execute($this->url("mem/used"));
$result = json_decode($Response->getBody());
if (isset($result->used)) {
$newstat->value = $this->convertBytesToGigabytes($result->used);
} else {
$newstat->value = null; // or some default value
}
}

$details["visiblestats"][] = $newstat;
}
}
}

return parent::getLiveStats($status, $details);
}

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

public static function getAvailableStats()
{
return [
"CpuTotal" => "CpuTotal",
"MemTotal" => "MemTotal",
"MemAvail" => "MemAvail",
"MemUsage" => "MemUsage",
];
}

private function convertBytesToGigabytes($bytes)
{
$gigabytes = $bytes / (1024 ** 3); // Converts bytes to gigabytes
return round($gigabytes, 2) . ' GB'; // Rounds to 4 significant digits
}
}
2 changes: 1 addition & 1 deletion Glances/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"website": "https://nicolargo.github.io/glances",
"license": "GNU Lesser General Public License v3.0 only",
"description": "Glances is a cross-platform monitoring tool which aims to present a large amount of monitoring information through a curses or Web based interface.",
"enhanced": false,
"enhanced": true,
"tile_background": "dark",
"icon": "glances.png"
}
14 changes: 14 additions & 0 deletions Glances/config.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
<div class="items">
<div class="input">
<label>{{ strtoupper(__('app.url')) }}</label>
{!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}
</div>
<div class="input">
<label>Stats to show</label>
{!! Form::select('config[availablestats][]', App\SupportedApps\Glances\Glances::getAvailableStats(), isset($item) ? $item->getConfig()->availablestats ?? null : null, ['multiple' => 'multiple']) !!}
</div>
<div class="input">
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
</div>
</div>
8 changes: 8 additions & 0 deletions Glances/livestats.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<ul class="livestats">
@foreach ($visiblestats as $stat)
<li>
<span class="title">{!! $stat->title !!}</span>
<strong>{!! $stat->value !!}</strong>
</li>
@endforeach
</ul>
2 changes: 1 addition & 1 deletion Gotify/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"enhanced": true,
"tile_background": "dark",
"icon": "gotify.png"
}
}
76 changes: 75 additions & 1 deletion Mailcow/Mailcow.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,80 @@

namespace App\SupportedApps\Mailcow;

class Mailcow extends \App\SupportedApps
class Mailcow extends \App\SupportedApps implements \App\EnhancedApps
{
public $config;

public function __construct()
{
}

public function test()
{
$attrs = $this->getAttrs();
$test = parent::appTest($this->url("status/containers"), $attrs);
echo $test->status;
}

public function livestats()
{
$status = "inactive";
$data = [];
$attrs = $this->getAttrs();

// Fetch mailboxes
$mailboxesResponse = parent::execute($this->url("mailbox/all"), $attrs);
$mailboxes = json_decode($mailboxesResponse->getBody());

// Count mailboxes
if ($mailboxes) {
$data["mailboxes"] = count($mailboxes);
} else {
$data["mailboxes"] = 0;
}

// Fetch clients
$domainsResponse = parent::execute($this->url("domain/all"), $attrs);
$domains = json_decode($domainsResponse->getBody());

// Count clients
if ($domains) {
$data["domains"] = count($domains);
} else {
$data["domains"] = 0;
}

// Fetch messages
$queueResponse = parent::execute($this->url("mailq/all"), $attrs);
$queue = json_decode($queueResponse->getBody());

// Count messages
if ($queue && isset($queue->messages)) {
$data["queue"] = count($queue->messages);
} else {
$data["queue"] = 0;
}

// Determine status based on data
if ($data["mailboxes"] > 0 || $data["domains"] > 0 || $data["queue"] >= 0) {
$status = "active";
}

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

public function url($endpoint)
{
$api_url = parent::normaliseurl($this->config->url) . "api/v1/get/" . $endpoint;
return $api_url;
}
private function getAttrs()
{
return [
"headers" => [
"Accept" => "application/json",
"X-API-Key" => $this->config->apikey
],
];
}
}
2 changes: 1 addition & 1 deletion Mailcow/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"website": "https://mailcow.email",
"license": "GNU General Public License v3.0 only",
"description": "Mailcow is a Docker based email server which provides an elegant web interface for managing domains, mailboxes and more.",
"enhanced": false,
"enhanced": true,
"tile_background": "dark",
"icon": "mailcow.svg"
}
14 changes: 14 additions & 0 deletions Mailcow/config.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
<div class="items">
<div class="input">
<label>{{ strtoupper(__('app.url')) }}</label>
{!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}
</div>
<div class="input">
<label>{{ __('app.apps.apikey') }}</label>
{!! Form::text('config[apikey]', isset($item) ? $item->getconfig()->apikey : null, ['placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', 'class' => 'form-control config-item']) !!}
</div>
<div class="input">
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
</div>
</div>
14 changes: 14 additions & 0 deletions Mailcow/livestats.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<ul class="livestats">
<li>
<span class="title">Mailboxes</span>
<strong>{!! $mailboxes !!}</strong>
</li>
<li>
<span class="title">Domains</span>
<strong>{!! $domains !!}</strong>
</li>
<li>
<span class="title">Queue</span>
<strong>{!! $queue !!}</strong>
</li>
</ul>

0 comments on commit 246f80f

Please sign in to comment.