. * * @link http://librenms.org * @copyright 2018 Tony Murray * @author Tony Murray */ namespace App\Providers; use Illuminate\Contracts\Foundation\Application; use Illuminate\Support\ServiceProvider; use LibreNMS\Data\Store\Datastore; use LibreNMS\Interfaces\Data\Datastore as DatastoreContract; class DatastoreServiceProvider extends ServiceProvider { protected $namespace = 'LibreNMS\\Data\\Store\\'; protected $stores = [ 'LibreNMS\Data\Store\Graphite', 'LibreNMS\Data\Store\InfluxDB', 'LibreNMS\Data\Store\OpenTSDB', 'LibreNMS\Data\Store\Prometheus', 'LibreNMS\Data\Store\Rrd', ]; public function register() { // set up bindings foreach ($this->stores as $store) { $this->app->singleton($store); } // bind the Datastore object $this->app->singleton('Datastore', function (Application $app, $options) { // only tag datastores enabled by config $stores = array_filter($this->stores, function ($store) { /** @var DatastoreContract $store */ return $store::isEnabled(); }); $app->tag($stores, ['datastore']); return new Datastore(iterator_to_array($app->tagged('datastore'))); }); // additional bindings $this->registerInflux(); } public function registerInflux() { $this->app->singleton('InfluxDB\Database', function ($app) { return \LibreNMS\Data\Store\InfluxDB::createFromConfig(); }); } }