You are here

class TestSensor in Monitoring 7

Test sensor to report status as provided by external arguments.

Hierarchy

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\Sensors
View 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

Namesort descending Modifiers Type Description Overrides
Sensor::$info protected property Current sensor info object.
Sensor::getSensorName public function Gets sensor name (not the label). Overrides SensorInterface::getSensorName
Sensor::isEnabled public function Determines if sensor is enabled. Overrides SensorInterface::isEnabled
SensorThresholds::setFormError protected function Sets a form error for the given threshold key.
SensorThresholds::settingsForm public function Gets settings form for a specific sensor. Overrides SensorConfigurable::settingsForm 1
SensorThresholds::settingsFormValidate public function Form validator for a sensor settings form. Overrides SensorConfigurable::settingsFormValidate
TestSensor::$testSensorResultData protected property
TestSensor::resultVerbose public function Provide additional info about sensor call. Overrides SensorExtendedInfoInterface::resultVerbose
TestSensor::runSensor public function Runs the sensor, updating $sensor_result. Overrides SensorInterface::runSensor
TestSensor::__construct function Instantiates a sensor object. Overrides Sensor::__construct