You are here

class StateValueSensorPlugin in Monitoring 8

Generic sensor that checks for a state value.

Plugin annotation


@SensorPlugin(
  id = "state_value",
  label = @Translation("State Value"),
  description = @Translation("Checks for a specific state value."),
  addable = FALSE
)

Hierarchy

Expanded class hierarchy of StateValueSensorPlugin

File

src/Plugin/monitoring/SensorPlugin/StateValueSensorPlugin.php, line 22
Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\StateValueSensorPlugin

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin
View source
class StateValueSensorPlugin extends ValueComparisonSensorPluginBase {

  /**
   * {@inheritdoc}
   */
  protected function getValueDescription() {
    return t('The expected value of state %key, current value: %actVal', array(
      '%key' => $this->sensorConfig
        ->getSetting('key'),
      '%actVal' => $this
        ->getValueText(),
    ));
  }

  /**
   * {@inheritdoc}
   */
  protected function getValue() {
    $state = $this
      ->getState();
    $key = $this->sensorConfig
      ->getSetting('key');
    if (empty($key)) {
      return NULL;
    }
    return $state
      ->get($key);
  }

  /**
   * Gets state.
   *
   * @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface
   *   The state.
   */
  protected function getState() {
    return $this
      ->getService('state');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
SensorPluginBase::$configurableValueType protected property Allows plugins to control if the value type can be configured. 6
SensorPluginBase::$pluginDefinition protected property The plugin implementation definition.
SensorPluginBase::$pluginId protected property The plugin_id.
SensorPluginBase::$sensorConfig protected property Current sensor config object.
SensorPluginBase::$services protected property
SensorPluginBase::addService public function Service setter. Overrides SensorPluginInterface::addService
SensorPluginBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides SensorPluginInterface::calculateDependencies 4
SensorPluginBase::create public static function Creates an instance of the sensor with config. Overrides SensorPluginInterface::create 7
SensorPluginBase::getConfigurableValueType public function Configurable value type. Overrides SensorPluginInterface::getConfigurableValueType
SensorPluginBase::getDefaultConfiguration public function Default configuration for a sensor. Overrides SensorPluginInterface::getDefaultConfiguration 8
SensorPluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
SensorPluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
SensorPluginBase::getSensorId public function Gets sensor name (not the label). Overrides SensorPluginInterface::getSensorId
SensorPluginBase::getService public function @todo: Replace with injection Overrides SensorPluginInterface::getService
SensorPluginBase::isEnabled public function Determines if sensor is enabled. Overrides SensorPluginInterface::isEnabled
SensorPluginBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm 3
SensorPluginBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm 2
SensorPluginBase::__construct function Instantiates a sensor object. 8
StateValueSensorPlugin::getState protected function Gets state.
StateValueSensorPlugin::getValue protected function Gets the current value. Overrides ValueComparisonSensorPluginBase::getValue
StateValueSensorPlugin::getValueDescription protected function Gets the value description that will be shown in the settings form. Overrides ValueComparisonSensorPluginBase::getValueDescription
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
ValueComparisonSensorPluginBase::buildConfigurationForm public function Adds expected value setting field into the sensor settings form. Overrides SensorPluginBase::buildConfigurationForm 1
ValueComparisonSensorPluginBase::getExpectedValue protected function Gets the expected value.
ValueComparisonSensorPluginBase::getValueText protected function Gets the current value as text.
ValueComparisonSensorPluginBase::runSensor public function Runs the sensor, updating $sensor_result. Overrides SensorPluginInterface::runSensor