class TestSensorPlugin in Monitoring 8
Test sensor to report status as provided by external arguments.
Plugin annotation
@SensorPlugin(
id = "test_sensor",
label = @Translation("Test SensorPlugin"),
description = @Translation("Test sensor to report status as provided by external arguments."),
addable = TRUE
)
Hierarchy
- class \Drupal\monitoring\SensorPlugin\SensorPluginBase implements SensorPluginInterface uses MessengerTrait, StringTranslationTrait
- class \Drupal\monitoring_test\Plugin\monitoring\SensorPlugin\TestSensorPlugin implements ExtendedInfoSensorPluginInterface
Expanded class hierarchy of TestSensorPlugin
File
- modules/
test/ src/ Plugin/ monitoring/ SensorPlugin/ TestSensorPlugin.php, line 25 - Contains \Drupal\monitoring_test\Plugin\monitoring\SensorPlugin\TestSensorPlugin.
Namespace
Drupal\monitoring_test\Plugin\monitoring\SensorPluginView source
class TestSensorPlugin extends SensorPluginBase implements ExtendedInfoSensorPluginInterface {
protected $testSensorResultData;
function __construct(SensorConfig $sensor_config, $sensor_id, $definition) {
parent::__construct($sensor_config, $sensor_id, $definition);
// Load test sensor data which will be used in the runSensor() logic.
$this->testSensorResultData = \Drupal::state()
->get('monitoring_test.sensor_result_data', array(
'sensor_status' => NULL,
'sensor_message' => NULL,
'sensor_value' => NULL,
'sensor_expected_value' => NULL,
'sensor_exception_message' => NULL,
));
}
/**
* {@inheritdoc}
*/
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']);
}
}
/**
* {@inheritdoc}
*/
public function resultVerbose(SensorResultInterface $result) {
$output = [];
$output['test'] = array(
'#type' => 'item',
'#title' => t('Test'),
'#markup' => 'call debug',
);
return $output;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
SensorPluginBase:: |
protected | property | Allows plugins to control if the value type can be configured. | 6 |
SensorPluginBase:: |
protected | property | The plugin implementation definition. | |
SensorPluginBase:: |
protected | property | The plugin_id. | |
SensorPluginBase:: |
protected | property | Current sensor config object. | |
SensorPluginBase:: |
protected | property | ||
SensorPluginBase:: |
public | function |
Service setter. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
13 |
SensorPluginBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides SensorPluginInterface:: |
4 |
SensorPluginBase:: |
public static | function |
Creates an instance of the sensor with config. Overrides SensorPluginInterface:: |
7 |
SensorPluginBase:: |
public | function |
Configurable value type. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Default configuration for a sensor. Overrides SensorPluginInterface:: |
8 |
SensorPluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
|
SensorPluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
SensorPluginBase:: |
public | function |
Gets sensor name (not the label). Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
@todo: Replace with injection Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Determines if sensor is enabled. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
3 |
SensorPluginBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
2 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TestSensorPlugin:: |
protected | property | ||
TestSensorPlugin:: |
public | function |
Provide additional info about sensor call. Overrides ExtendedInfoSensorPluginInterface:: |
|
TestSensorPlugin:: |
public | function |
Runs the sensor, updating $sensor_result. Overrides SensorPluginInterface:: |
|
TestSensorPlugin:: |
function |
Instantiates a sensor object. Overrides SensorPluginBase:: |