ajout heimdall
This commit is contained in:
109
heimdall/config/www/SupportedApps/Portainer/Portainer.php
Executable file
109
heimdall/config/www/SupportedApps/Portainer/Portainer.php
Executable file
@@ -0,0 +1,109 @@
|
||||
<?php namespace App\SupportedApps\Portainer;
|
||||
use Exception;
|
||||
|
||||
class Portainer extends \App\SupportedApps implements \App\EnhancedApps
|
||||
{
|
||||
public $config;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
try {
|
||||
$token = $this->auth();
|
||||
echo "Successfully communicated with the API";
|
||||
} catch (Exception $err) {
|
||||
echo $err->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public function auth()
|
||||
{
|
||||
$attrs = [];
|
||||
|
||||
$body["username"] = $this->config->username;
|
||||
$body["password"] = $this->config->password;
|
||||
$vars = [
|
||||
"http_errors" => false,
|
||||
"timeout" => 5,
|
||||
"body" => json_encode($body),
|
||||
];
|
||||
|
||||
$result = parent::execute(
|
||||
$this->url("api/auth"),
|
||||
$attrs,
|
||||
$vars,
|
||||
"POST"
|
||||
);
|
||||
if (null === $result) {
|
||||
throw new Exception("Could not connect to Portainer");
|
||||
}
|
||||
|
||||
$response = json_decode($result->getBody());
|
||||
|
||||
if (!isset($response->jwt)) {
|
||||
throw new Exception("Invalid credentials");
|
||||
}
|
||||
|
||||
return $response->jwt;
|
||||
}
|
||||
|
||||
public function livestats()
|
||||
{
|
||||
$status = "inactive";
|
||||
$running = 0;
|
||||
$stopped = 0;
|
||||
|
||||
$token = $this->auth();
|
||||
$headers = [
|
||||
"Authorization" => "Bearer " . $token,
|
||||
"Accept" => "application/json",
|
||||
];
|
||||
$attrs = [
|
||||
"headers" => $headers,
|
||||
];
|
||||
|
||||
$result = parent::execute(
|
||||
$this->url("api/endpoints?limit=100&start=0"),
|
||||
$attrs,
|
||||
[]
|
||||
);
|
||||
if (null === $result) {
|
||||
throw new Exception("Could not connect to Portainer");
|
||||
}
|
||||
|
||||
$response = json_decode($result->getBody());
|
||||
if (count($response) === 0) {
|
||||
throw new Exception("No endpoints");
|
||||
}
|
||||
|
||||
foreach ($response as $endpoint) {
|
||||
if (count($endpoint->Snapshots) === 0) {
|
||||
throw new Exception("No snapshots");
|
||||
}
|
||||
|
||||
$snapshot = $endpoint->Snapshots[0];
|
||||
$data = [
|
||||
($running += $snapshot->RunningContainerCount),
|
||||
($stopped += $snapshot->StoppedContainerCount),
|
||||
];
|
||||
}
|
||||
|
||||
$data = [
|
||||
"running" => $running,
|
||||
"stopped" => $stopped,
|
||||
];
|
||||
if ($running || $stopped) {
|
||||
$status = "active";
|
||||
}
|
||||
return parent::getLiveStats($status, $data);
|
||||
}
|
||||
|
||||
public function url($endpoint)
|
||||
{
|
||||
$api_url = parent::normaliseurl($this->config->url) . $endpoint;
|
||||
return $api_url;
|
||||
}
|
||||
}
|
||||
10
heimdall/config/www/SupportedApps/Portainer/app.json
Executable file
10
heimdall/config/www/SupportedApps/Portainer/app.json
Executable file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"appid": "07b796b3a10eaa8b6f485ed2379187a39400b459",
|
||||
"name": "Portainer",
|
||||
"website": "https://portainer.io",
|
||||
"license": "zlib License",
|
||||
"description": "Portainer is a simple management solution for Docker. Easily manage your Docker hosts and Docker Swarm clusters via Portainer web user interface.",
|
||||
"enhanced": true,
|
||||
"tile_background": "dark",
|
||||
"icon": "portainer.svg"
|
||||
}
|
||||
19
heimdall/config/www/SupportedApps/Portainer/config.blade.php
Executable file
19
heimdall/config/www/SupportedApps/Portainer/config.blade.php
Executable file
@@ -0,0 +1,19 @@
|
||||
<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.username') }}</label>
|
||||
{!! Form::text('config[username]', isset($item) ? $item->getconfig()->username : null, ['placeholder' => __('app.apps.username'), 'data-config' => 'username', 'class' => 'form-control config-item']) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<label>{{ __('app.apps.password') }}</label>
|
||||
{!! Form::input('password', 'config[password]', '', ['placeholder' => __('app.apps.password'), 'data-config' => 'password', 'class' => 'form-control config-item']) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
10
heimdall/config/www/SupportedApps/Portainer/livestats.blade.php
Executable file
10
heimdall/config/www/SupportedApps/Portainer/livestats.blade.php
Executable file
@@ -0,0 +1,10 @@
|
||||
<ul class="livestats">
|
||||
<li>
|
||||
<span class="title">Running</span>
|
||||
<strong>{!! $running !!}</strong>
|
||||
</li>
|
||||
<li>
|
||||
<span class="title">Stopped</span>
|
||||
<strong>{!! $stopped !!}</strong>
|
||||
</li>
|
||||
</ul>
|
||||
BIN
heimdall/config/www/SupportedApps/Portainer/portainer.png
Executable file
BIN
heimdall/config/www/SupportedApps/Portainer/portainer.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
Reference in New Issue
Block a user