mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Remove legacy code and fix missing device graphs (#11950)
* removing $graphs global * remove unused things * fix some additional graphs * Fix graphs persisting too soon * correct name for poller module performance graph * only one type of graph is used here
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
namespace LibreNMS;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\DeviceGraph;
|
||||
use DeviceCache;
|
||||
use Illuminate\Support\Str;
|
||||
use LibreNMS\Device\WirelessSensor;
|
||||
@@ -45,16 +46,18 @@ class OS implements ProcessorDiscovery
|
||||
}
|
||||
|
||||
private $device; // annoying use of references to make sure this is in sync with global $device variable
|
||||
private $graphs; // stores device graphs
|
||||
private $cache; // data cache
|
||||
private $pre_cache; // pre-fetch data cache
|
||||
|
||||
/**
|
||||
* OS constructor. Not allowed to be created directly. Use OS::make()
|
||||
* @param $device
|
||||
* @param array $device
|
||||
*/
|
||||
private function __construct(&$device)
|
||||
{
|
||||
$this->device = &$device;
|
||||
$this->graphs = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,6 +90,29 @@ class OS implements ProcessorDiscovery
|
||||
return DeviceCache::get($this->getDeviceId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable a graph for this device
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function enableGraph($name)
|
||||
{
|
||||
$this->graphs[$name] = true;
|
||||
}
|
||||
|
||||
public function persistGraphs()
|
||||
{
|
||||
$device = $this->getDeviceModel();
|
||||
$graphs = collect(array_keys($this->graphs));
|
||||
|
||||
// delete extra graphs
|
||||
$device->graphs->keyBy('graph')->collect()->except($graphs)->each->delete();
|
||||
// create missing graphs
|
||||
$device->graphs()->saveMany($graphs->diff($device->graphs->pluck('graph'))->map(function ($graph) {
|
||||
return new DeviceGraph(['graph' => $graph]);
|
||||
}));
|
||||
}
|
||||
|
||||
public function preCache()
|
||||
{
|
||||
if (is_null($this->pre_cache)) {
|
||||
|
Reference in New Issue
Block a user