Files
librenms-librenms/app/Http/Controllers/Widgets/ComponentStatusController.php
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2.4 KiB
PHP
Raw Normal View History

2018-12-16 15:18:17 -06:00
<?php
/**
* ComponentStatusController.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2021-02-09 00:29:04 +01:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-12-16 15:18:17 -06:00
*
2021-02-09 00:29:04 +01:00
* @link https://www.librenms.org
2021-09-10 20:09:53 +02:00
*
2018-12-16 15:18:17 -06:00
* @copyright 2018 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace App\Http\Controllers\Widgets;
use App\Models\Component;
use Illuminate\Http\Request;
2023-05-24 22:21:54 +02:00
use Illuminate\Support\Facades\DB;
2018-12-16 15:18:17 -06:00
use Illuminate\View\View;
class ComponentStatusController extends WidgetController
{
protected $title = 'Component Status';
2019-08-08 02:59:14 +02:00
protected $defaults = [
'device_group' => null,
];
2018-12-16 15:18:17 -06:00
/**
2021-09-08 23:35:56 +02:00
* @param Request $request
2018-12-16 15:18:17 -06:00
* @return View
*/
public function getView(Request $request)
{
2019-08-08 02:59:14 +02:00
$data = $this->getSettings();
2018-12-16 15:18:17 -06:00
$status = [
[
'color' => 'text-success',
'text' => __('Ok'),
],
[
'color' => 'grey',
'text' => __('Warning'),
],
[
'color' => 'text-danger',
'text' => __('Critical'),
],
];
$component_status = Component::query()
->select('status', DB::raw("count('status') as total"))
->groupBy('status')
->where('disabled', '!=', 0)
2019-08-08 02:59:14 +02:00
->when($data['device_group'], function ($query) use ($data) {
2021-04-08 15:14:49 +02:00
return $query->inDeviceGroup($data['device_group']);
2019-08-08 02:59:14 +02:00
})
2018-12-16 15:18:17 -06:00
->get()->pluck('total', 'status')->toArray();
foreach ($status as $key => $value) {
$status[$key]['total'] = isset($component_status[$key]) ? $component_status[$key] : 0;
}
return view('widgets.component-status', compact('status'));
}
2019-08-08 02:59:14 +02:00
public function getSettingsView(Request $request)
{
return view('widgets.settings.component-status', $this->getSettings(true));
}
2018-12-16 15:18:17 -06:00
}