function monitoring_sensor_result_last in Monitoring 8
Same name and namespace in other branches
- 7 monitoring.module \monitoring_sensor_result_last()
Gets last sensor result.
Parameters
string $sensor_name: The name of the sensor.
Return value
\Drupal\monitoring\Entity\SensorResultEntity|null A SensorResultEntity representing the last sensor result.
2 calls to monitoring_sensor_result_last()
- MonitoringCoreKernelTest::testPreviousSensorResult in tests/
src/ Kernel/ MonitoringCoreKernelTest.php - Tests if the previous sensor result retrieved is the expected one.
- SensorRunner::runSensors in src/
SensorRunner.php - Runs the defined sensors.
File
- ./
monitoring.module, line 264 - Monitoring bootstrap file.
Code
function monitoring_sensor_result_last($sensor_name) {
$result = \Drupal::entityQuery('monitoring_sensor_result')
->condition('sensor_name', $sensor_name)
->sort('timestamp', 'DESC')
->sort('record_id', 'DESC')
->range(0, 1)
->execute();
if (!empty($result)) {
return SensorResultEntity::load(reset($result));
}
return NULL;
}