From dabcd8a82efa9c4ccd7c9600e77ef3613aae16fc Mon Sep 17 00:00:00 2001 From: GOUKI9999 Date: Wed, 7 Aug 2024 18:05:17 +0800 Subject: [PATCH] Add mutli option in config --- Monit/Monit.php | 24 +++++++++++++++++++----- Monit/config.blade.php | 7 ++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Monit/Monit.php b/Monit/Monit.php index 4125e3e9b2..885284e644 100644 --- a/Monit/Monit.php +++ b/Monit/Monit.php @@ -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; diff --git a/Monit/config.blade.php b/Monit/config.blade.php index 26b4af285c..cd8a4d354b 100644 --- a/Monit/config.blade.php +++ b/Monit/config.blade.php @@ -1,4 +1,5 @@

{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')

+
@@ -13,6 +14,10 @@ {!! Form::input('password', 'config[password]', '', ['placeholder' => __('app.apps.password'), 'data-config' => 'password', 'class' => 'form-control config-item']) !!}
- + + {!! 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']) !!} +
+
+