You are here

public function SensorRunner::runSensors in Monitoring 8

Same name and namespace in other branches
  1. 7 lib/Drupal/monitoring/SensorRunner.php \Drupal\monitoring\SensorRunner::runSensors()

Runs the defined sensors.

Parameters

\Drupal\monitoring\Entity\SensorConfig[] $sensors_config_all: List of sensor config object that we want to run.

bool $force: Force sensor execution.

bool $verbose: Collect verbose info.

Return value

\Drupal\monitoring\Result\SensorResultInterface[] Array of sensor results.

Throws

\Drupal\monitoring\Sensor\DisabledSensorException Thrown if any of the passed sensors is not enabled.

See also

\Drupal\monitoring\SensorRunner::runSensor()

File

src/SensorRunner.php, line 123
Contains \Drupal\monitoring\SensorRunner.

Class

SensorRunner
Instantiate and run requested sensors.

Namespace

Drupal\monitoring

Code

public function runSensors(array $sensors_config_all = array(), $force = FALSE, $verbose = FALSE) {
  $this->verbose = $verbose;
  $this->forceRun = $force;
  if (empty($sensors_config_all)) {
    $sensors_config_all = $this->sensorManager
      ->getEnabledSensorConfig();
  }
  $this
    ->loadCache($sensors_config_all);
  $results = array();
  foreach ($sensors_config_all as $name => $sensor_config) {
    if ($result = $this
      ->runSensor($sensor_config)) {
      $result
        ->setPreviousResult(monitoring_sensor_result_last($result
        ->getSensorId()));
      $results[$name] = $result;
    }
  }
  $this
    ->logResults($results);
  $this
    ->cacheResults($results);

  // Trigger a hook to allow processing of sensors data.
  \Drupal::moduleHandler()
    ->invokeAll('monitoring_run_sensors', [
    $results,
  ]);
  return $results;
}