You are here

protected function DisappearedSensorsSensorPlugin::updateAvailableSensorsList in Monitoring 8

Updates the available sensor list.

Parameters

array $available_sensors: The available sensors list.

\Drupal\monitoring\Entity\SensorConfig[] $sensor_config: The current sensor config.

Return value

array Updated available sensors list.

1 call to DisappearedSensorsSensorPlugin::updateAvailableSensorsList()
DisappearedSensorsSensorPlugin::runSensor in src/Plugin/monitoring/SensorPlugin/DisappearedSensorsSensorPlugin.php
Runs the sensor, updating $sensor_result.

File

src/Plugin/monitoring/SensorPlugin/DisappearedSensorsSensorPlugin.php, line 86
Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\DisappearedSensorsSensorPlugin.

Class

DisappearedSensorsSensorPlugin
Monitors if sensors disappeared without prior being disabled.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin

Code

protected function updateAvailableSensorsList($available_sensors, $sensor_config) {
  $new_sensors = array();
  foreach ($sensor_config as $key => $config) {

    // Check for newly added sensors. This is needed as some sensors get
    // enabled by default and not via monitoring_sensor_enable() callback that
    // takes care of updating the available sensors list.
    if (!isset($available_sensors[$key])) {
      $new_sensors[$key] = array(
        'name' => $key,
        'enabled' => $config
          ->isEnabled(),
      );
    }
    elseif ($available_sensors[$key]['enabled'] != $config
      ->isEnabled()) {
      $available_sensors[$key]['enabled'] = $config
        ->isEnabled();
    }
  }

  // If we have new sensors add it to available list.
  if (!empty($new_sensors)) {
    \Drupal::state()
      ->set('monitoring.available_sensors', $available_sensors + $new_sensors);
    \Drupal::logger('monitoring')
      ->notice('@count new sensor/s added: @names', array(
      '@count' => count($new_sensors),
      '@names' => implode(', ', array_keys($new_sensors)),
    ));
  }
  return $available_sensors;
}