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:
Tony Murray
2020-07-23 09:57:22 -05:00
committed by GitHub
parent 2fc037ab23
commit 020c5fd7e1
102 changed files with 321 additions and 2385 deletions

View File

@@ -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)) {