TestSensor.php in Monitoring 7
File
test/lib/Drupal/monitoring_test/Sensor/Sensors/TestSensor.php
View source
<?php
namespace Drupal\monitoring_test\Sensor\Sensors;
use Drupal\monitoring\Sensor\SensorExtendedInfoInterface;
use Drupal\monitoring\Sensor\SensorInfo;
use Drupal\monitoring\Result\SensorResultInterface;
use Drupal\monitoring\Sensor\SensorThresholds;
class TestSensor extends SensorThresholds implements SensorExtendedInfoInterface {
protected $testSensorResultData;
function __construct(SensorInfo $info) {
parent::__construct($info);
$this->testSensorResultData = variable_get('test_sensor_result_data', array(
'sensor_status' => NULL,
'sensor_message' => NULL,
'sensor_value' => NULL,
'sensor_expected_value' => NULL,
'sensor_exception_message' => NULL,
));
}
public function runSensor(SensorResultInterface $result) {
usleep(1);
if (isset($this->testSensorResultData['sensor_exception_message'])) {
throw new \RuntimeException($this->testSensorResultData['sensor_exception_message']);
}
if (isset($this->testSensorResultData['sensor_value'])) {
$result
->setValue($this->testSensorResultData['sensor_value']);
}
if (!empty($this->testSensorResultData['sensor_status'])) {
$result
->setStatus($this->testSensorResultData['sensor_status']);
}
if (!empty($this->testSensorResultData['sensor_message'])) {
$result
->addStatusMessage($this->testSensorResultData['sensor_message']);
}
}
public function resultVerbose(SensorResultInterface $result) {
return 'call debug';
}
}
Classes
Name |
Description |
TestSensor |
Test sensor to report status as provided by external arguments. |