You are here

protected function SensorDisappearedSensors::updateAvailableSensorsList in Monitoring 7

Updates the available sensor list.

Parameters

array $available_sensors: The available sensors list.

\Drupal\monitoring\Sensor\SensorInfo[] $sensor_info: The current sensor info.

Return value

array Updated available sensors list.

1 call to SensorDisappearedSensors::updateAvailableSensorsList()
SensorDisappearedSensors::runSensor in lib/Drupal/monitoring/Sensor/Sensors/SensorDisappearedSensors.php
Runs the sensor, updating $sensor_result.

File

lib/Drupal/monitoring/Sensor/Sensors/SensorDisappearedSensors.php, line 72
Contains \Drupal\monitoring\Sensor\Sensors\SensorDisappearedSensors.

Class

SensorDisappearedSensors
Monitors if sensors disappeared without prior being disabled.

Namespace

Drupal\monitoring\Sensor\Sensors

Code

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

    // 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' => $info
          ->isEnabled(),
      );
    }
    elseif ($available_sensors[$key]['enabled'] != $info
      ->isEnabled()) {
      $available_sensors[$key]['enabled'] = $info
        ->isEnabled();
    }
  }

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