You are here

public function SensorManager::enableSensor in Monitoring 7

Same name and namespace in other branches
  1. 8 src/Sensor/SensorManager.php \Drupal\monitoring\Sensor\SensorManager::enableSensor()

Enable a sensor.

Checks if the sensor is enabled and enables it if not.

Parameters

string $sensor_name: Sensor name to be enabled.

Throws

\Drupal\monitoring\Sensor\NonExistingSensorException Thrown if the requested sensor does not exist.

File

lib/Drupal/monitoring/Sensor/SensorManager.php, line 120
Contains \Drupal\monitoring\Sensor\SensorManager.

Class

SensorManager
Manages sensor definitions and settings.

Namespace

Drupal\monitoring\Sensor

Code

public function enableSensor($sensor_name) {
  $sensor_info = $this
    ->getSensorInfoByName($sensor_name);
  if (!$sensor_info
    ->isEnabled()) {
    $settings = monitoring_sensor_settings_get($sensor_name);
    $settings['enabled'] = TRUE;
    monitoring_sensor_settings_save($sensor_name, $settings);
    $available_sensors = variable_get('monitoring_available_sensors', array());
    if (!isset($available_sensors[$sensor_name])) {

      // Use the watchdog message as the disappeared sensor does when new
      // sensors are detected.
      watchdog('monitoring', '@count new sensor/s added: @names', array(
        '@count' => 1,
        '@names' => $sensor_name,
      ));
    }
    $available_sensors[$sensor_name]['enabled'] = TRUE;
    $available_sensors[$sensor_name]['name'] = $sensor_name;
    variable_set('monitoring_available_sensors', $available_sensors);
  }
}