You are here

function monitoring_sensor_result_second_last in Monitoring 8

Gets second last sensor result.

Parameters

string $sensor_name: The name of the sensor.

Return value

\Drupal\monitoring\Entity\SensorResultEntity|null A SensorResultEntity representing the second last sensor result.

Deprecated

in 8.x-1.x, remove before 8.x-2.0.

File

./monitoring.module, line 290
Monitoring bootstrap file.

Code

function monitoring_sensor_result_second_last($sensor_name) {
  $result = \Drupal::entityQuery('monitoring_sensor_result')
    ->condition('sensor_name', $sensor_name)
    ->sort('timestamp', 'DESC')
    ->sort('record_id', 'DESC')
    ->range(1, 1)
    ->execute();
  if (!empty($result)) {
    return SensorResultEntity::load(reset($result));
  }
  return NULL;
}