mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix poller enabling graphs for display (#11743)
This commit is contained in:
@ -59,7 +59,7 @@ class OS implements Module
|
||||
$os->pollOS();
|
||||
} else {
|
||||
// legacy poller files
|
||||
$device = $os->getDevice();
|
||||
global $graphs, $device;
|
||||
if (is_file(base_path('/includes/polling/os/' . $device['os'] . '.inc.php'))) {
|
||||
// OS Specific
|
||||
include base_path('/includes/polling/os/' . $device['os'] . '.inc.php');
|
||||
|
@ -55,7 +55,7 @@ class Graph
|
||||
|
||||
if ($device != null) {
|
||||
// find the MIB subtypes
|
||||
$graphs = $device->graphs();
|
||||
$graphs = $device->graphs->pluck('graph');
|
||||
|
||||
foreach (Config::get('graph_types') as $type => $type_data) {
|
||||
foreach (array_keys($type_data) as $subtype) {
|
||||
|
@ -230,18 +230,6 @@ class Device extends BaseModel
|
||||
return asset('images/os/generic.svg');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of enabled graphs for this device.
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function graphs()
|
||||
{
|
||||
return DB::table('device_graphs')
|
||||
->where('device_id', $this->device_id)
|
||||
->pluck('graph');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the max_depth field based on parents
|
||||
* Performs SQL query, so make sure all parents are saved first
|
||||
@ -532,6 +520,11 @@ class Device extends BaseModel
|
||||
return $this->hasMany(\App\Models\Eventlog::class, 'device_id', 'device_id');
|
||||
}
|
||||
|
||||
public function graphs()
|
||||
{
|
||||
return $this->hasMany(\App\Models\DeviceGraph::class, 'device_id');
|
||||
}
|
||||
|
||||
public function groups()
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\DeviceGroup::class, 'device_group_device', 'device_id', 'device_group_id');
|
||||
|
9
app/Models/DeviceGraph.php
Normal file
9
app/Models/DeviceGraph.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class DeviceGraph extends DeviceRelatedModel
|
||||
{
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['graph'];
|
||||
}
|
@ -1,17 +1,16 @@
|
||||
<?php
|
||||
|
||||
use App\Models\DeviceGraph;
|
||||
use Illuminate\Support\Str;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\RRD\RrdDefinition;
|
||||
use LibreNMS\Enum\Alert;
|
||||
use LibreNMS\Exceptions\JsonAppException;
|
||||
use LibreNMS\Exceptions\JsonAppPollingFailedException;
|
||||
use LibreNMS\Exceptions\JsonAppParsingFailedException;
|
||||
use LibreNMS\Exceptions\JsonAppBlankJsonException;
|
||||
use LibreNMS\Exceptions\JsonAppMissingKeysException;
|
||||
use LibreNMS\Exceptions\JsonAppWrongVersionException;
|
||||
use LibreNMS\Exceptions\JsonAppExtendErroredException;
|
||||
use App\Models\Location;
|
||||
use LibreNMS\Exceptions\JsonAppMissingKeysException;
|
||||
use LibreNMS\Exceptions\JsonAppParsingFailedException;
|
||||
use LibreNMS\Exceptions\JsonAppPollingFailedException;
|
||||
use LibreNMS\Exceptions\JsonAppWrongVersionException;
|
||||
use LibreNMS\RRD\RrdDefinition;
|
||||
|
||||
function bulk_sensor_snmpget($device, $sensors)
|
||||
{
|
||||
@ -231,10 +230,11 @@ function record_sensor_data($device, $all_sensors)
|
||||
*/
|
||||
function poll_device($device, $force_module = false)
|
||||
{
|
||||
global $device;
|
||||
global $device, $graphs;
|
||||
|
||||
$device_start = microtime(true);
|
||||
|
||||
$graphs = [];
|
||||
$attribs = DeviceCache::getPrimary()->getAttribs();
|
||||
$device['attribs'] = $attribs;
|
||||
|
||||
@ -290,9 +290,6 @@ function poll_device($device, $force_module = false)
|
||||
$response = device_is_up($device, true);
|
||||
|
||||
if ($response['status'] == '1') {
|
||||
$graphs = array();
|
||||
$oldgraphs = array();
|
||||
|
||||
if ($device['snmp_disable']) {
|
||||
Config::set('poller_modules', []);
|
||||
} else {
|
||||
@ -367,28 +364,15 @@ function poll_device($device, $force_module = false)
|
||||
|
||||
if (!$force_module && !empty($graphs)) {
|
||||
echo "Enabling graphs: ";
|
||||
// FIXME EVENTLOGGING -- MAKE IT SO WE DO THIS PER-MODULE?
|
||||
// This code cycles through the graphs already known in the database and the ones we've defined as being polled here
|
||||
// If there any don't match, they're added/deleted from the database.
|
||||
// Ideally we should hold graphs for xx days/weeks/polls so that we don't needlessly hide information.
|
||||
foreach (dbFetch('SELECT `graph` FROM `device_graphs` WHERE `device_id` = ?', array($device['device_id'])) as $graph) {
|
||||
if (isset($graphs[$graph['graph']])) {
|
||||
$oldgraphs[$graph['graph']] = true;
|
||||
} else {
|
||||
dbDelete('device_graphs', '`device_id` = ? AND `graph` = ?', array($device['device_id'], $graph['graph']));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($graphs as $graph => $value) {
|
||||
if (!isset($oldgraphs[$graph])) {
|
||||
$graphs = collect($graphs)->keys();
|
||||
DeviceCache::getPrimary()->graphs->keyBy('graph')->collect()->except($graphs)->each->delete(); // delete extra graphs
|
||||
DeviceCache::getPrimary()->graphs() // create missing graphs
|
||||
->saveMany($graphs->diff(DeviceCache::getPrimary()->graphs->pluck('graph'))->map(function ($graph) {
|
||||
echo '+';
|
||||
dbInsert(array('device_id' => $device['device_id'], 'graph' => $graph), 'device_graphs');
|
||||
}
|
||||
|
||||
echo $graph.' ';
|
||||
}
|
||||
return new DeviceGraph(['graph' => $graph]);
|
||||
}));
|
||||
echo PHP_EOL;
|
||||
}//end if
|
||||
}
|
||||
|
||||
// Ping response
|
||||
if (can_ping_device($attribs) === true && !empty($response['ping_time'])) {
|
||||
|
Reference in New Issue
Block a user