including some more dashboard components
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\SupportedApps\UptimeKuma;
|
||||
|
||||
class UptimeKuma extends \App\SupportedApps implements \App\EnhancedApps
|
||||
{
|
||||
public $config;
|
||||
|
||||
private $mapping = [
|
||||
0 => "down",
|
||||
1 => "up",
|
||||
2 => "pending",
|
||||
3 => "maintenance",
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
private function getAttrs()
|
||||
{
|
||||
if (empty($this->config->apikey)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$basicAuthValue = base64_encode(":" . $this->config->apikey);
|
||||
|
||||
return [
|
||||
"headers" => [
|
||||
"Authorization" => "Basic " . $basicAuthValue,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
|
||||
$test = parent::appTest($this->url("metrics"), $this->getAttrs());
|
||||
echo $test->status;
|
||||
}
|
||||
|
||||
public function livestats()
|
||||
{
|
||||
$status = "inactive";
|
||||
|
||||
$response = parent::execute($this->url("metrics"), $this->getAttrs());
|
||||
$body = $response->getBody();
|
||||
|
||||
$lines = explode("\n", $body);
|
||||
|
||||
$data = [
|
||||
"up" => 0,
|
||||
"down" => 0,
|
||||
"pending" => 0,
|
||||
"maintenance" => 0,
|
||||
"unknown" => 0,
|
||||
];
|
||||
|
||||
foreach ($lines as $line) {
|
||||
if (strlen($line) === 0 || strpos($line, '#') === 0) {
|
||||
// If the line is empty or is a comment we can skip it
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strpos($line, 'monitor_status') !== 0) {
|
||||
// If the line is a metric but not a monitor we can ignore it
|
||||
continue;
|
||||
}
|
||||
|
||||
// We only really care about the state, which is the integer at the end
|
||||
// of the line.
|
||||
//
|
||||
// This can be 0 (Down), 1 (Up), 2 (Pending), 3 (Maintenance)
|
||||
//
|
||||
// We only care about the down or up but let's translate all of them.
|
||||
$state = intval(substr($line, strrpos($line, ' ')));
|
||||
|
||||
$data[$this->mapping[$state] ?? 'unknown']++;
|
||||
}
|
||||
|
||||
if ($data["down"] > 0) {
|
||||
$status = "active";
|
||||
}
|
||||
|
||||
return parent::getLiveStats($status, $data);
|
||||
}
|
||||
|
||||
public function url($endpoint)
|
||||
{
|
||||
$api_url = parent::normaliseurl($this->config->url) .
|
||||
$endpoint;
|
||||
|
||||
return $api_url;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"appid": "366c6646eedab83cc4b349f198424d2291cbfa76",
|
||||
"name": "Uptime Kuma",
|
||||
"website": "https://uptime.kuma.pet",
|
||||
"license": "MIT License",
|
||||
"description": "It is a self-hosted monitoring tool like \"Uptime Robot\".",
|
||||
"enhanced": true,
|
||||
"tile_background": "dark",
|
||||
"icon": "uptimekuma.svg"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
|
||||
<div class="items">
|
||||
<input type="hidden" data-config="dataonly" class="config-item" name="config[dataonly]" value="1" />
|
||||
<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) : null, ['placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', 'class' => 'form-control config-item']) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<label>Skip TLS verification</label>
|
||||
<div class="toggleinput" style="margin-top: 26px; padding-left: 15px;">
|
||||
{!! Form::hidden('config[ignore_tls]', 0, ['class' => 'config-item', 'data-config' => 'ignore_tls']) !!}
|
||||
<label class="switch">
|
||||
<?php
|
||||
$checked = false;
|
||||
if (isset($item) && !empty($item) && isset($item->getconfig()->ignore_tls)) {
|
||||
$checked = $item->getconfig()->ignore_tls;
|
||||
}
|
||||
$set_checked = $checked ? ' checked="checked"' : '';
|
||||
?>
|
||||
<input type="checkbox" class="config-item" data-config="ignore_tls" name="config[ignore_tls]" value="1" <?php echo $set_checked; ?> />
|
||||
<span class="slider round"></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input">
|
||||
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,10 @@
|
||||
<ul class="livestats">
|
||||
<li>
|
||||
<span class="title">Up</span>
|
||||
<strong>{!! $up ?? 0 !!}</strong>
|
||||
</li>
|
||||
<li>
|
||||
<span class="title">Down</span>
|
||||
<strong>{!! $down ?? 0 !!}</strong>
|
||||
</li>
|
||||
</ul>
|
||||
Reference in New Issue
Block a user