You are here

public function SensorThresholds::settingsForm in Monitoring 7

Gets settings form for a specific sensor.

Parameters

$form: Drupal $form structure.

array $form_state: Drupal $form_state object. Carrying the string sensor_name.

Return value

array Drupal form structure.

Overrides SensorConfigurable::settingsForm

1 call to SensorThresholds::settingsForm()
SensorDatabaseAggregator::settingsForm in lib/Drupal/monitoring/Sensor/Sensors/SensorDatabaseAggregator.php
Gets settings form for a specific sensor.
1 method overrides SensorThresholds::settingsForm()
SensorDatabaseAggregator::settingsForm in lib/Drupal/monitoring/Sensor/Sensors/SensorDatabaseAggregator.php
Gets settings form for a specific sensor.

File

lib/Drupal/monitoring/Sensor/SensorThresholds.php, line 20
Contains \Drupal\monitoring\Sensor\SensorThresholds.

Class

SensorThresholds
Abstract class providing configuration form for Sensor with thresholds.

Namespace

Drupal\monitoring\Sensor

Code

public function settingsForm($form, &$form_state) {
  $form = parent::settingsForm($form, $form_state);
  $form['thresholds'] = array(
    '#type' => 'fieldset',
    '#title' => t('Sensor thresholds'),
    '#description' => t('Here you can set limit values that switch the sensor to a given status.'),
    '#prefix' => '<div id="monitoring-sensor-thresholds">',
    '#suffix' => '</div>',
  );
  if (isset($form_state['values'][monitoring_sensor_settings_key($this
    ->getSensorName())]['thresholds']['type'])) {
    $type = $form_state['values'][monitoring_sensor_settings_key($this
      ->getSensorName())]['thresholds']['type'];
  }
  else {
    $type = $this->info
      ->getThresholdsType();
  }
  $form['thresholds']['type'] = array(
    '#type' => 'select',
    '#title' => t('Threshold type'),
    '#options' => array(
      'exceeds' => t('Exceeds'),
      'falls' => t('Falls'),
      'inner_interval' => t('Inner interval'),
      'outer_interval' => t('Outer interval'),
    ),
    '#default_value' => $type,
    '#ajax' => array(
      'callback' => 'monitoring_sensor_thresholds_ajax',
      'wrapper' => 'monitoring-sensor-thresholds',
    ),
  );
  switch ($type) {
    case 'exceeds':
      $form['thresholds']['#description'] = t('The sensor will be set to the corresponding status if the value exceeds the limits.');
      $form['thresholds']['warning'] = array(
        '#type' => 'textfield',
        '#title' => t('Warning'),
        '#default_value' => $this->info
          ->getThresholdValue('warning'),
        '#element_validate' => array(
          'element_validate_number',
        ),
      );
      $form['thresholds']['critical'] = array(
        '#type' => 'textfield',
        '#title' => t('Critical'),
        '#default_value' => $this->info
          ->getThresholdValue('critical'),
        '#element_validate' => array(
          'element_validate_number',
        ),
      );
      break;
    case 'falls':
      $form['thresholds']['#description'] = t('The sensor will be set to the corresponding status if the value falls below the limits.');
      $form['thresholds']['warning'] = array(
        '#type' => 'textfield',
        '#title' => t('Warning'),
        '#default_value' => $this->info
          ->getThresholdValue('warning'),
        '#element_validate' => array(
          'element_validate_number',
        ),
      );
      $form['thresholds']['critical'] = array(
        '#type' => 'textfield',
        '#title' => t('Critical'),
        '#default_value' => $this->info
          ->getThresholdValue('critical'),
        '#element_validate' => array(
          'element_validate_number',
        ),
      );
      break;
    case 'inner_interval':
      $form['thresholds']['#description'] = t('The sensor will be set to the corresponding status if the value is within the limits.');
      $form['thresholds']['warning_low'] = array(
        '#type' => 'textfield',
        '#title' => t('Warning low'),
        '#default_value' => $this->info
          ->getThresholdValue('warning_low'),
        '#element_validate' => array(
          'element_validate_number',
        ),
      );
      $form['thresholds']['warning_high'] = array(
        '#type' => 'textfield',
        '#title' => t('Warning high'),
        '#default_value' => $this->info
          ->getThresholdValue('warning_high'),
        '#element_validate' => array(
          'element_validate_number',
        ),
      );
      $form['thresholds']['critical_low'] = array(
        '#type' => 'textfield',
        '#title' => t('Critical low'),
        '#default_value' => $this->info
          ->getThresholdValue('critical_low'),
        '#element_validate' => array(
          'element_validate_number',
        ),
      );
      $form['thresholds']['critical_high'] = array(
        '#type' => 'textfield',
        '#title' => t('Critical high'),
        '#default_value' => $this->info
          ->getThresholdValue('critical_high'),
        '#element_validate' => array(
          'element_validate_number',
        ),
      );
      break;
    case 'outer_interval':
      $form['thresholds']['#description'] = t('The sensor will be set to the corresponding status if the value is outside of the limits.');
      $form['thresholds']['warning_low'] = array(
        '#type' => 'textfield',
        '#title' => t('Warning low'),
        '#default_value' => $this->info
          ->getThresholdValue('warning_low'),
        '#element_validate' => array(
          'element_validate_number',
        ),
      );
      $form['thresholds']['warning_high'] = array(
        '#type' => 'textfield',
        '#title' => t('Warning high'),
        '#default_value' => $this->info
          ->getThresholdValue('warning_high'),
        '#element_validate' => array(
          'element_validate_number',
        ),
      );
      $form['thresholds']['critical_low'] = array(
        '#type' => 'textfield',
        '#title' => t('Critical low'),
        '#default_value' => $this->info
          ->getThresholdValue('critical_low'),
        '#element_validate' => array(
          'element_validate_number',
        ),
      );
      $form['thresholds']['critical_high'] = array(
        '#type' => 'textfield',
        '#title' => t('Critical high'),
        '#default_value' => $this->info
          ->getThresholdValue('critical_high'),
        '#element_validate' => array(
          'element_validate_number',
        ),
      );
      break;
  }
  return $form;
}