Files

89 lines
2.3 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Http\Controllers;
use App\Models\Device;
use App\Models\Poller;
use App\Models\PollerCluster;
2020-03-22 13:29:31 -05:00
use App\Models\PollerGroup;
use Carbon\Carbon;
use Illuminate\Http\Request;
2020-03-22 13:29:31 -05:00
use LibreNMS\Config;
class PollerController extends Controller
{
public $rrdstep;
public function __construct()
{
2020-03-22 13:29:31 -05:00
$this->rrdstep = Config::get('rrd.step');
}
public function logTab(Request $request)
{
return view('poller.log', [
'current_tab' => 'log',
'filter' => $request->input('filter', 'active')
]);
}
public function groupsTab()
{
return view('poller.groups', [
'current_tab' => 'groups',
2020-03-22 13:29:31 -05:00
'poller_groups' => PollerGroup::query()->withCount('devices')->get(),
'default_group_id' => Config::get('distributed_poller_group'),
'ungrouped_count' => Device::where('poller_group', 0)->count(),
]);
}
public function pollerTab()
{
return view('poller.poller', [
'current_tab' => 'poller',
'pollers' => $this->poller(),
'poller_cluster' => $this->pollerCluster(),
]);
}
public function performanceTab()
{
return view('poller.performance', ['current_tab' => 'performance']);
}
2020-03-22 13:29:31 -05:00
protected function pollerStatus($poller, $last)
{
2020-03-22 13:29:31 -05:00
$since_last_poll = Carbon::parse($last)->diffInSeconds();
2020-03-22 13:29:31 -05:00
$poller->row_class = $this->checkTimeSinceLastPoll($since_last_poll);
$poller->long_not_polled = (\Auth::user()->hasGlobalAdmin() && ($since_last_poll > ($this->rrdstep * 2)));
return $poller;
}
private function poller()
{
2020-03-22 13:29:31 -05:00
return Poller::query()->orderBy('poller_name')->get()->map(function ($poller) {
return $this->pollerStatus($poller, $poller->last_polled);
});
}
private function pollerCluster()
{
2020-03-22 13:29:31 -05:00
return PollerCluster::with('stats')->orderBy('poller_name')->get()->map(function ($poller) {
return $this->pollerStatus($poller, $poller->last_report);
});
}
2020-03-22 13:29:31 -05:00
private function checkTimeSinceLastPoll($seconds)
{
if ($seconds >= $this->rrdstep) {
return 'danger';
} elseif ($seconds >= ($this->rrdstep * 0.95)) {
return 'warning';
}
2020-03-22 13:29:31 -05:00
return 'success';
}
}