2018-12-16 15:18:17 -06:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* DeviceSummaryController.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
|
2018-12-16 15:18:17 -06:00
|
|
|
* @copyright 2018 Tony Murray
|
|
|
|
* @author Tony Murray <murraytony@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Widgets;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use LibreNMS\Config;
|
2019-05-10 11:02:39 -05:00
|
|
|
use LibreNMS\Util\ObjectCache;
|
2018-12-16 15:18:17 -06:00
|
|
|
|
|
|
|
abstract class DeviceSummaryController extends WidgetController
|
|
|
|
{
|
|
|
|
protected $title = 'Device Summary';
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
// init defaults we need to check config, so do it in construct
|
|
|
|
$this->defaults = [
|
2020-09-21 14:54:51 +02:00
|
|
|
'show_services' => (int) Config::get('show_services', 1),
|
|
|
|
'summary_errors' => (int) Config::get('summary_errors', 0),
|
2018-12-16 15:18:17 -06:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSettingsView(Request $request)
|
|
|
|
{
|
2019-08-08 02:59:14 +02:00
|
|
|
return view('widgets.settings.device-summary', $this->getSettings(true));
|
2018-12-16 15:18:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getData(Request $request)
|
|
|
|
{
|
|
|
|
$data = $this->getSettings();
|
|
|
|
|
2020-01-15 18:32:29 +01:00
|
|
|
$data['devices'] = ObjectCache::deviceCounts(['total', 'up', 'down', 'ignored', 'disabled', 'disable_notify']);
|
2018-12-16 15:18:17 -06:00
|
|
|
|
2019-05-10 11:02:39 -05:00
|
|
|
$data['ports'] = $data['summary_errors'] ?
|
|
|
|
ObjectCache::portCounts(['total', 'up', 'down', 'ignored', 'shutdown', 'errored']) :
|
|
|
|
ObjectCache::portCounts(['total', 'up', 'down', 'ignored', 'shutdown']);
|
2018-12-16 15:18:17 -06:00
|
|
|
|
|
|
|
if ($data['show_services']) {
|
2019-05-10 11:02:39 -05:00
|
|
|
$data['services'] = ObjectCache::serviceCounts(['total', 'ok', 'critical', 'ignored', 'disabled']);
|
2018-12-16 15:18:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|