class TestSensor in Monitoring 7
Test sensor to report status as provided by external arguments.
Hierarchy
- class \Drupal\monitoring\Sensor\Sensor implements SensorInterface
- class \Drupal\monitoring\Sensor\SensorConfigurable implements SensorConfigurableInterface
- class \Drupal\monitoring\Sensor\SensorThresholds implements SensorThresholdsInterface
- class \Drupal\monitoring_test\Sensor\Sensors\TestSensor implements SensorExtendedInfoInterface
- class \Drupal\monitoring\Sensor\SensorThresholds implements SensorThresholdsInterface
- class \Drupal\monitoring\Sensor\SensorConfigurable implements SensorConfigurableInterface
Expanded class hierarchy of TestSensor
File
- test/
lib/ Drupal/ monitoring_test/ Sensor/ Sensors/ TestSensor.php, line 17 - Contains \Drupal\monitoring_test\Sensor\Sensors\TestSensor.
Namespace
Drupal\monitoring_test\Sensor\SensorsView source
class TestSensor extends SensorThresholds implements SensorExtendedInfoInterface {
protected $testSensorResultData;
function __construct(SensorInfo $info) {
parent::__construct($info);
// Load test sensor data which will be used in the runSensor() logic.
$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) {
// Sleep here for a while as running this sensor may result in 0 execution
// time.
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';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Sensor:: |
protected | property | Current sensor info object. | |
Sensor:: |
public | function |
Gets sensor name (not the label). Overrides SensorInterface:: |
|
Sensor:: |
public | function |
Determines if sensor is enabled. Overrides SensorInterface:: |
|
SensorThresholds:: |
protected | function | Sets a form error for the given threshold key. | |
SensorThresholds:: |
public | function |
Gets settings form for a specific sensor. Overrides SensorConfigurable:: |
1 |
SensorThresholds:: |
public | function |
Form validator for a sensor settings form. Overrides SensorConfigurable:: |
|
TestSensor:: |
protected | property | ||
TestSensor:: |
public | function |
Provide additional info about sensor call. Overrides SensorExtendedInfoInterface:: |
|
TestSensor:: |
public | function |
Runs the sensor, updating $sensor_result. Overrides SensorInterface:: |
|
TestSensor:: |
function |
Instantiates a sensor object. Overrides Sensor:: |