You are here

function SensorInterface::runSensor in Monitoring 7

Runs the sensor, updating $sensor_result.

An implementation must provide any checks necessary to be able to populate the provides sensor result instance with a combination of the following possibilities:

Based on the provided information, the sensor result will then be compiled. It will attempt to set the sensor status if not already done explicitly by the sensor and will build a default message, unless a message was already set with SensorResultInterface::setMessage().

Sensors with unknown status can either be set based on an expected value or thresholds. If the value does not match the expected value, the status is set to critical. Sensors that support thresholds should either subclass \Drupal\monitoring\Sensor\SensorThresholds or implement \Drupal\monitoring\SensorThresholdsInterface and provide their own configuration form.

The default sensor message will include information about the sensor value, expected value, thresholds, the configured time interval and additional status messages defined. Provided value labels and value types will be considered for displaying the sensor value, see hook_monitoring_sensor_info() for their documentation. If neither value nor status messages are provided, the message will default to "No value".

Compiled message examples:

  • $90.00 in 1 day, expected $100.00. This is the message for a sensor with a commerce_currency value type, a configured time interval of one day and a value of 90 and expected value of 100.
  • 53 login attempts in 6 hours, exceeds 20, 10 for user administrator. This the message for a failed login sensor with value 53 with a threshold configuration of exceeds 20 and a status message "10 for user administrator".

Parameters

SensorResultInterface $sensor_result: Sensor result object.

Throws

\Exception Can throw any exception. Must be caught and handled by the caller.

See also

\Drupal\monitoring\Result\SensorResultInterface::setValue()

\Drupal\monitoring\Result\SensorResultInterface::setExpectedValue()

\Drupal\monitoring\Result\SensorResultInterface::compile()

\Drupal\monitoring\Result\SensorResultInterface::setMessage()

\Drupal\monitoring\Result\SensorResultInterface::addStatusMessage()

13 methods override SensorInterface::runSensor()
SensorCoreRequirements::runSensor in lib/Drupal/monitoring/Sensor/Sensors/SensorCoreRequirements.php
Runs the sensor, updating $sensor_result.
SensorCronLastRunAge::runSensor in lib/Drupal/monitoring/Sensor/Sensors/SensorCronLastRunAge.php
Runs the sensor, updating $sensor_result.
SensorDatabaseAggregator::runSensor in lib/Drupal/monitoring/Sensor/Sensors/SensorDatabaseAggregator.php
Runs the sensor, updating $sensor_result.
SensorDisappearedSensors::runSensor in lib/Drupal/monitoring/Sensor/Sensors/SensorDisappearedSensors.php
Runs the sensor, updating $sensor_result.
SensorDrupalUpdate::runSensor in lib/Drupal/monitoring/Sensor/Sensors/SensorDrupalUpdate.php
Runs the sensor, updating $sensor_result.

... See full list

File

lib/Drupal/monitoring/Sensor/SensorInterface.php, line 91
Monitoring sensor interface.

Class

SensorInterface
Interface for a sensor defining basic operations.

Namespace

Drupal\monitoring\Sensor

Code

function runSensor(SensorResultInterface $sensor_result);