You are here

function monitoring_sensor_details in Monitoring 7

Services sensor details form.

1 string reference to 'monitoring_sensor_details'
monitoring_menu in ./monitoring.module
Implements hook_menu().

File

./monitoring.admin.inc, line 306
Admin page/form callbacks.

Code

function monitoring_sensor_details($form, &$form_state, SensorInfo $sensor_info) {
  $form_state['sensor_name'] = $sensor_info
    ->getName();
  try {
    $result = monitoring_sensor_run($sensor_info
      ->getName(), FALSE, TRUE);
  } catch (DisabledSensorException $e) {

    // Exception is thrown if the sensor is not enabled.
    // Display a page not found in that case.
    drupal_not_found();
    drupal_exit();
  }
  if ($sensor_info
    ->getDescription()) {
    $form['sensor_info']['description'] = array(
      '#type' => 'item',
      '#title' => t('Description'),
      '#markup' => $sensor_info
        ->getDescription(),
    );
  }
  if ($sensor_info
    ->getCategory()) {
    $form['sensor_info']['category'] = array(
      '#type' => 'item',
      '#title' => t('Category'),
      '#markup' => $sensor_info
        ->getCategory(),
    );
  }
  $form['sensor_result'] = array(
    '#type' => 'fieldset',
    '#title' => t('Result'),
  );
  $form['sensor_result']['status'] = array(
    '#type' => 'item',
    '#title' => t('Status'),
    '#markup' => $result
      ->getStatusLabel(),
  );
  $form['sensor_result']['message'] = array(
    '#type' => 'item',
    '#title' => t('Message'),
    '#markup' => $result
      ->getMessage(),
  );
  $form['sensor_result']['execution_time'] = array(
    '#type' => 'item',
    '#title' => t('Execution time'),
    '#markup' => $result
      ->getExecutionTime() . 'ms',
  );
  if ($result
    ->isCached()) {
    $form['sensor_result']['cached'] = array(
      '#type' => 'item',
      '#title' => t('Cache information'),
      '#markup' => t('Executed @interval ago, valid for @valid', array(
        '@interval' => format_interval(REQUEST_TIME - $result
          ->getTimestamp()),
        '@valid' => format_interval($sensor_info
          ->getCachingTime()),
      )),
    );
    $form['sensor_result']['force_run'] = array(
      '#type' => 'submit',
      '#value' => t('Run now'),
      '#access' => user_access('monitoring force run'),
    );
  }
  elseif ($sensor_info
    ->getCachingTime()) {
    $form['sensor_result']['cached'] = array(
      '#type' => 'item',
      '#title' => t('Cache information'),
      '#markup' => t('Executed now, valid for @valid', array(
        '@valid' => format_interval($sensor_info
          ->getCachingTime()),
      )),
    );
    $form['sensor_result']['force_run'] = array(
      '#type' => 'submit',
      '#value' => t('Run again'),
      '#access' => user_access('monitoring force run'),
    );
  }
  else {
    $form['sensor_result']['cached'] = array(
      '#type' => 'item',
      '#title' => t('Cache information'),
      '#markup' => t('Not cached'),
    );
  }
  if ($sensor_info
    ->isExtendedInfo()) {
    $form['sensor_result']['verbose'] = array(
      '#type' => 'fieldset',
      '#title' => t('Verbose'),
      '#access' => user_access('monitoring verbose'),
    );
    if ($result
      ->isCached()) {
      $form['sensor_result']['verbose']['output'] = array(
        '#type' => 'markup',
        '#markup' => '<p>' . t('Verbose output is not available for cached sensor results. Click force run to see verbose output.') . '</p>',
      );
    }
    elseif ($verbose_output = $result
      ->getVerboseOutput()) {
      if (is_array($verbose_output)) {
        $form['sensor_result']['verbose']['output'] = $verbose_output;
      }
      else {
        $form['sensor_result']['verbose']['output'] = array(
          '#type' => 'markup',
          '#markup' => '<pre>' . $verbose_output . '</pre>',
        );
      }
    }
    else {
      $form['sensor_result']['verbose']['output'] = array(
        '#type' => 'markup',
        '#markup' => '<p>' . t('No verbose output available for this sensor execution.') . '</p>',
      );
    }
  }
  $form['settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Settings'),
    '#description' => '<pre>' . var_export($sensor_info
      ->getSettings(), TRUE) . '</pre>',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $view = views_get_view('monitoring_sensor_results');
  if (!empty($view)) {
    $view
      ->init_display();
    $output = $view
      ->preview('detail_page_log', array(
      $sensor_info
        ->getName(),
    ));
    if (!empty($view->result)) {
      $form['sensor_log'] = array(
        '#type' => 'fieldset',
        '#title' => t('Log'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );
      $form['sensor_log']['view']['#markup'] = $output;
    }
  }
  return $form;
}