function monitoring_sensor_result_last in Monitoring 7
Same name and namespace in other branches
- 8 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.
1 call to monitoring_sensor_result_last()
- SensorRunner::logResults in lib/
Drupal/ monitoring/ SensorRunner.php - Log results if needed.
File
- ./
monitoring.module, line 474 - Monitoring bootstrap file.
Code
function monitoring_sensor_result_last($sensor_name) {
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'monitoring_sensor_result');
$query
->propertyCondition('sensor_name', $sensor_name);
$query
->propertyOrderBy('timestamp', 'DESC');
$query
->range(0, 1);
$result = $query
->execute();
if (isset($result['monitoring_sensor_result'])) {
$row = array_shift($result['monitoring_sensor_result']);
return entity_load_single('monitoring_sensor_result', $row->record_id);
}
return NULL;
}