Skip to content

Commit

Permalink
Add mutli option in config
Browse files Browse the repository at this point in the history
  • Loading branch information
GOUKI9999 committed Aug 7, 2024
1 parent 5716ef2 commit dabcd8a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
24 changes: 19 additions & 5 deletions Monit/Monit.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,34 @@ public function livestats()
}

$status = 'active';
$data = [
'running_services' => $running_services,
'failed_services' => $failed_services
];
$metrics = [];

if (isset($this->config->availablestats) && in_array('running_services', $this->config->availablestats)) {
$metrics['running_services'] = $running_services;
}

if (isset($this->config->availablestats) && in_array('failed_services', $this->config->availablestats)) {
$metrics['failed_services'] = $failed_services;
}

$data = $metrics;
} else {
$data = [
'error' => 'Failed to connect to Monit. HTTP Status: ' . $response['httpcode']
];
}

// 返回JSON格式数据
return parent::getLiveStats($status, $data);
}

public static function getAvailableStats()
{
return [
'running_services' => 'Running Services',
'failed_services' => 'Failed Services'
];
}

private function url($endpoint)
{
$config = $this->config;
Expand Down
7 changes: 6 additions & 1 deletion Monit/config.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>

<div class="items">
<div class="input">
<label>{{ strtoupper(__('app.url')) }}</label>
Expand All @@ -13,6 +14,10 @@
{!! 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>
<label>Stats to show</label>
{!! Form::select('config[availablestats][]', App\SupportedApps\Monit\Monit::getAvailableStats(), isset($item) && isset($item->getconfig()->availablestats) ? $item->getconfig()->availablestats : null, ['multiple' => 'multiple', 'class' => 'form-control config-item']) !!}
</div>
<div class="input">
<button style="margin-top: 32px; display: block;" class="btn test" id="test_config">Test</button>
</div>
</div>

0 comments on commit dabcd8a

Please sign in to comment.