abstract class ValueComparisonSensorPluginBase in Monitoring 8
Provides abstract functionality for a value comparison sensor.
Uses "value" offset to store the expected value against which the actual value will be compared to. You can prepopulate this offset with initial value that will be used as the expected one on the sensor enable.
Hierarchy
- class \Drupal\monitoring\SensorPlugin\SensorPluginBase implements SensorPluginInterface uses MessengerTrait, StringTranslationTrait
- class \Drupal\monitoring\SensorPlugin\ValueComparisonSensorPluginBase
Expanded class hierarchy of ValueComparisonSensorPluginBase
2 files declare their use of ValueComparisonSensorPluginBase
- ConfigValueSensorPlugin.php in src/
Plugin/ monitoring/ SensorPlugin/ ConfigValueSensorPlugin.php - Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\ConfigValueSensorPlugin
- StateValueSensorPlugin.php in src/
Plugin/ monitoring/ SensorPlugin/ StateValueSensorPlugin.php - Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\StateValueSensorPlugin
File
- src/
SensorPlugin/ ValueComparisonSensorPluginBase.php, line 20 - Contains \Drupal\monitoring\SensorPlugin\ValueComparisonSensorPluginBase
Namespace
Drupal\monitoring\SensorPluginView source
abstract class ValueComparisonSensorPluginBase extends SensorPluginBase {
/**
* Gets the value description that will be shown in the settings form.
*
* @return string
* Value description.
*/
protected abstract function getValueDescription();
/**
* Gets the current value.
*
* @return mixed
* The current value.
*/
protected abstract function getValue();
/**
* Gets the current value as text.
*
* @return string
* The expected value.
*/
protected function getValueText() {
if ($this->sensorConfig
->isBool()) {
$actual_value = $this
->getValue() ? 'TRUE' : 'FALSE';
}
else {
$actual_value = $this
->getValue();
}
return $actual_value;
}
/**
* Gets the expected value.
*
* @return mixed
* The expected value.
*/
protected function getExpectedValue() {
return $this->sensorConfig
->getSetting('value');
}
/**
* Adds expected value setting field into the sensor settings form.
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['value'] = array(
'#title' => t('Expected value'),
'#description' => $this
->getValueDescription(),
'#default_value' => $this
->getExpectedValue(),
);
if ($this->sensorConfig
->isBool()) {
$form['value']['#type'] = 'checkbox';
}
elseif ($this->sensorConfig
->isNumeric()) {
$form['value']['#type'] = 'number';
}
else {
$form['value']['#type'] = 'textfield';
}
return $form;
}
/**
* {@inheritdoc}
*/
public function runSensor(SensorResultInterface $result) {
$result
->setValue($this
->getValue());
$result
->setExpectedValue($this
->getExpectedValue());
}
}
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 |
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 |
SensorPluginBase:: |
function | Instantiates a sensor object. | 8 | |
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. | |
ValueComparisonSensorPluginBase:: |
public | function |
Adds expected value setting field into the sensor settings form. Overrides SensorPluginBase:: |
1 |
ValueComparisonSensorPluginBase:: |
protected | function | Gets the expected value. | |
ValueComparisonSensorPluginBase:: |
abstract protected | function | Gets the current value. | 2 |
ValueComparisonSensorPluginBase:: |
abstract protected | function | Gets the value description that will be shown in the settings form. | 2 |
ValueComparisonSensorPluginBase:: |
protected | function | Gets the current value as text. | |
ValueComparisonSensorPluginBase:: |
public | function |
Runs the sensor, updating $sensor_result. Overrides SensorPluginInterface:: |