mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Better services graphing support (#10185)
* Move services graph code from device to service and remove unused code * Add proper support for services to dashboard graph weidget * Fix phpdoc in ServiceController still pointing to MuninPluginController
This commit is contained in:
@@ -32,7 +32,7 @@ class Graph
|
||||
{
|
||||
public static function getTypes()
|
||||
{
|
||||
return ['device', 'port', 'application', 'munin'];
|
||||
return ['device', 'port', 'application', 'munin', 'service'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
55
app/Http/Controllers/Select/ServiceController.php
Normal file
55
app/Http/Controllers/Select/ServiceController.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* ServiceController.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
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2018 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Select;
|
||||
|
||||
use App\Models\Service;
|
||||
|
||||
class ServiceController extends SelectController
|
||||
{
|
||||
|
||||
/**
|
||||
* Defines the base query for this resource
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder
|
||||
*/
|
||||
protected function baseQuery($request)
|
||||
{
|
||||
return Service::hasAccess($request->user())
|
||||
->with(['device' => function ($query) {
|
||||
$query->select('device_id', 'hostname', 'sysName');
|
||||
}])
|
||||
->select('service_id', 'service_type', 'service_desc', 'device_id');
|
||||
}
|
||||
|
||||
public function formatItem($service)
|
||||
{
|
||||
return [
|
||||
'id' => $service->service_id,
|
||||
'text' => $service->device->shortDisplayName() . ' - ' . $service->service_type . ' (' . $service->service_desc . ')'
|
||||
];
|
||||
}
|
||||
}
|
@@ -30,6 +30,7 @@ use App\Models\Bill;
|
||||
use App\Models\Device;
|
||||
use App\Models\MuninPlugin;
|
||||
use App\Models\Port;
|
||||
use App\Models\Service;
|
||||
use App\Models\UserWidget;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -50,6 +51,7 @@ class GraphController extends WidgetController
|
||||
'graph_port' => null,
|
||||
'graph_application' => null,
|
||||
'graph_munin' => null,
|
||||
'graph_service' => null,
|
||||
'graph_ports' => [],
|
||||
'graph_custom' => [],
|
||||
'graph_manual' => null,
|
||||
@@ -87,6 +89,10 @@ class GraphController extends WidgetController
|
||||
if ($munin = MuninPlugin::find($settings['graph_munin'])) {
|
||||
return $munin->device->displayName() . ' / ' . $munin->mplug_type . ' / ' . $settings['graph_type'];
|
||||
}
|
||||
} elseif ($type == 'service') {
|
||||
if ($service = Service::find($settings['graph_service'])) {
|
||||
return $service->device->displayName() . ' / ' . $service->service_type . ' (' . $service->service_desc . ')' . ' / ' . $settings['graph_type'];
|
||||
}
|
||||
}
|
||||
|
||||
// fall back for types where we couldn't find the item
|
||||
@@ -133,6 +139,11 @@ class GraphController extends WidgetController
|
||||
}
|
||||
$data['munin_text'] = isset($mplug) ? $mplug->device->displayName() . ' - ' . $mplug->mplug_type : __('Munin plugin does not exist');
|
||||
|
||||
if ($primary == 'service' && $data['graph_service']) {
|
||||
$service = Service::with('device')->find($data['graph_service']);
|
||||
}
|
||||
$data['service_text'] = isset($service) ? $service->device->displayName() . ' - ' . $service->service_type . ' (' . $service->service_desc . ')' : __('Service does not exist');
|
||||
|
||||
$data['graph_ports'] = Port::whereIn('port_id', $data['graph_ports'])
|
||||
->select('ports.device_id', 'port_id', 'ifAlias', 'ifName', 'ifDescr')
|
||||
->with(['device' => function ($query) {
|
||||
@@ -171,6 +182,11 @@ class GraphController extends WidgetController
|
||||
$params[] = 'device='.$mplug->device_id;
|
||||
$params[] = 'plugin='.$mplug->mplug_type;
|
||||
}
|
||||
} elseif ($type == 'service') {
|
||||
if ($service = Service::find($settings['graph_service'])) {
|
||||
$params[] = 'device='.$service->device_id;
|
||||
$params[] = 'id='.$service->service_id;
|
||||
}
|
||||
} elseif ($type == 'aggregate') {
|
||||
$aggregate_type = $this->getGraphType(false);
|
||||
if ($aggregate_type == 'custom') {
|
||||
@@ -255,6 +271,7 @@ class GraphController extends WidgetController
|
||||
$settings['graph_port'] = $this->convertLegacySettingId($settings['graph_port'], 'port_id');
|
||||
$settings['graph_application'] = $this->convertLegacySettingId($settings['graph_application'], 'app_id');
|
||||
$settings['graph_munin'] = $this->convertLegacySettingId($settings['graph_munin'], 'mplug_id');
|
||||
$settings['graph_service'] = $this->convertLegacySettingId($settings['graph_service'], 'service_id');
|
||||
$settings['graph_bill'] = $this->convertLegacySettingId($settings['graph_bill'], 'bill_id');
|
||||
|
||||
$settings['graph_custom'] = (array)$settings['graph_custom'];
|
||||
|
@@ -10,7 +10,7 @@ if (is_numeric($vars['id'])) {
|
||||
$rrd_filename = rrd_name($device['hostname'], array('service', $service['service_type'], $service['service_id']));
|
||||
|
||||
$title = generate_device_link($device);
|
||||
$title .= ' :: Service :: '.htmlentities($service['service_type']);
|
||||
$title .= ' :: Service :: '.htmlentities($service['service_type']).' - '.htmlentities($service['service_desc']);
|
||||
$auth = true;
|
||||
}
|
||||
}
|
||||
|
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
$scale_max = '1';
|
||||
|
||||
require 'includes/html/graphs/common.inc.php';
|
||||
|
||||
$service_text = substr(str_pad($service['service_type'], 28), 0, 28);
|
||||
|
||||
$rrd_options .= " COMMENT:' Cur Avail\\n'";
|
||||
$rrd_options .= " DEF:status=$rrd_filename:status:AVERAGE";
|
||||
$rrd_options .= ' CDEF:percent=status,100,*';
|
||||
$rrd_options .= ' CDEF:down=status,1,LT,status,UNKN,IF';
|
||||
$rrd_options .= ' CDEF:percentdown=down,100,*';
|
||||
$rrd_options .= ' AREA:percent#CCFFCC';
|
||||
$rrd_options .= ' AREA:percentdown#FFCCCC';
|
||||
$rrd_options .= " LINE1.5:percent#009900:'".$service_text."'";
|
||||
// Ugly hack :(
|
||||
$rrd_options .= ' LINE1.5:percentdown#cc0000';
|
||||
$rrd_options .= ' GPRINT:status:LAST:%3.0lf';
|
||||
$rrd_options .= ' GPRINT:percent:AVERAGE:%3.5lf%%\l';
|
@@ -16,10 +16,10 @@ require_once 'includes/services.inc.php';
|
||||
$services = service_get($device['device_id']);
|
||||
|
||||
// Determine which key is the service we want to show.
|
||||
if (isset($vars['service'])) {
|
||||
if (isset($vars['id'])) {
|
||||
// Service is set, find its key.
|
||||
foreach ($services as $key => $service) {
|
||||
if ($service['service_id'] == $vars['service']) {
|
||||
if ($service['service_id'] == $vars['id']) {
|
||||
// We have found the service we want.
|
||||
$vars['service'] = $key;
|
||||
}
|
@@ -113,8 +113,8 @@ if (count($services) > '0') {
|
||||
$graphs = json_decode($service['service_ds'], true);
|
||||
foreach ($graphs as $k => $v) {
|
||||
$graph_array['device'] = $device['device_id'];
|
||||
$graph_array['type'] = 'device_service';
|
||||
$graph_array['service'] = $service['service_id'];
|
||||
$graph_array['type'] = 'service_graph';
|
||||
$graph_array['id'] = $service['service_id'];
|
||||
$graph_array['ds'] = $k;
|
||||
|
||||
echo '<tr>';
|
||||
|
@@ -69,6 +69,14 @@
|
||||
@endif
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group graph_select_extra-{{ $id }}" id="graph_select_service-{{ $id }}" style="display: none;">
|
||||
<label for="graph_service-{{ $id }}" class="control-label">@lang('Service')</label>
|
||||
<select class="form-control" id="graph_service-{{ $id }}" name="graph_service" data-placeholder="@lang('Select a service')">
|
||||
@if($graph_service)
|
||||
<option value="{{ $graph_service }}">{{ $service_text }}</option>
|
||||
@endif
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group graph_select_extra-{{ $id }}" id="graph_select_bill-{{ $id }}" style="display: none;">
|
||||
<label for="graph_bill-{{ $id }}" class="control-label">@lang('Bill')</label>
|
||||
<select class="form-control" id="graph_bill-{{ $id }}" name="graph_bill" data-placeholder="@lang('Select a bill')">
|
||||
@@ -111,6 +119,7 @@
|
||||
};
|
||||
}, '{{ $graph_application ?: '' }}');
|
||||
init_select2('#graph_munin-{{ $id }}', 'munin', {limit: 100}, '{{ $graph_munin ?: '' }}');
|
||||
init_select2('#graph_service-{{ $id }}', 'service', {limit: 100}, '{{ $graph_service ?: '' }}');
|
||||
init_select2('#graph_bill-{{ $id }}', 'bill', {limit: 100}, '{{ $graph_bill ?: '' }}');
|
||||
init_select2('#graph_custom-{{ $id }}', 'graph-aggregate', {}, false);
|
||||
init_select2('#graph_ports-{{ $id }}', 'port', {limit: 100}, {{ $graph_port_ids }});
|
||||
|
@@ -72,6 +72,7 @@ Route::group(['middleware' => ['auth', '2fa'], 'guard' => 'auth'], function () {
|
||||
Route::get('syslog', 'SyslogController');
|
||||
Route::get('location', 'LocationController');
|
||||
Route::get('munin', 'MuninPluginController');
|
||||
Route::get('service', 'ServiceController');
|
||||
Route::get('port', 'PortController');
|
||||
Route::get('port-field', 'PortFieldController');
|
||||
});
|
||||
|
Reference in New Issue
Block a user