You are here

function nagios_status_page in Nagios Monitoring 6

Same name and namespace in other branches
  1. 5 nagios.module \nagios_status_page()
  2. 7 nagios.module \nagios_status_page()

Callback for the nagios status page

1 string reference to 'nagios_status_page'
nagios_menu in ./nagios.module
Implementation of hook_menu

File

./nagios.module, line 172

Code

function nagios_status_page() {
  $args = func_get_args();

  // Module to run checks for.
  $module = array_shift($args);

  // ID to run checks for.
  $id = array_shift($args);
  drupal_set_header('Cache-Control: no-cache');
  drupal_set_header('Pragma: no-cache');
  drupal_set_header('Expires: -1');
  $codes = nagios_status();

  // Check the unique ID string and access permissions first
  $ua = variable_get('nagios_ua', '');
  if (user_access('administer site configuration') || $_SERVER['HTTP_USER_AGENT'] == $ua) {

    // Authorized so calling other modules
    if ($module) {

      // A specific module has been requested.
      $nagios_data = array();
      $nagios_data[$module] = module_invoke($module, 'nagios', $id);
    }
    else {
      $nagios_data = nagios_invoke_all('nagios');
    }
  }
  else {

    // This is not an authorized unique id or uer, so just return this default status.
    $nagios_data = array(
      'nagios' => array(
        'DRUPAL' => array(
          'status' => NAGIOS_STATUS_UNKNOWN,
          'type' => 'state',
          'text' => t('Unauthorized'),
        ),
      ),
    );
  }

  // Find the highest level to be the overall status
  $severity = NAGIOS_STATUS_OK;
  $min_severity = variable_get('nagios_min_report_severity', NAGIOS_STATUS_WARNING);
  foreach ($nagios_data as $module_name => $module_data) {
    foreach ($module_data as $key => $value) {
      if ($value['status'] >= $min_severity) {
        $severity = max($severity, $value['status']);
      }
    }
  }

  // Identifier that we check on the other side
  $output = "\n" . 'nagios=' . $codes[$severity] . ', ';
  $output_state = array();
  $output_perf = array();
  foreach ($nagios_data as $module_name => $module_data) {
    foreach ($module_data as $key => $value) {
      switch ($value['type']) {
        case 'state':

          // If status is larger then minimum severity
          if ($value['status'] >= $min_severity) {
            $tmp_state = $key . ':' . $codes[$value['status']];
          }
          else {
            $tmp_state = $key . ':' . $codes[NAGIOS_STATUS_OK];
          }
          if (!empty($value['text'])) {
            $tmp_state .= '=' . $value['text'];
          }
          if (variable_get('nagios_show_outdated_names', TRUE) && $key == 'ADMIN' && $value['text'] == 'Module and theme update status') {
            module_load_include('inc', 'update', 'update.compare');
            $tmp_projects = update_calculate_project_data(update_get_projects());
            $nagios_ignored_modules = variable_get('nagios_ignored_modules', array());
            $nagios_ignored_themes = variable_get('nagios_ignored_themes', array());
            $nagios_ignored_projects = $nagios_ignored_modules + $nagios_ignored_themes;
            $outdated_count = 0;
            $tmp_modules = '';
            foreach ($tmp_projects as $projkey => $projval) {
              if (!isset($nagios_ignored_projects[$projkey])) {
                if ($projval['status'] < UPDATE_CURRENT && $projval['status'] >= UPDATE_NOT_SECURE) {
                  switch ($projval['status']) {
                    case UPDATE_NOT_SECURE:
                      $tmp_projstatus = t('NOT SECURE');
                      break;
                    case UPDATE_REVOKED:
                      $tmp_projstatus = t('REVOKED');
                      break;
                    case UPDATE_NOT_SUPPORTED:
                      $tmp_projstatus = t('NOT SUPPORTED');
                      break;
                    case UPDATE_NOT_CURRENT:
                      $tmp_projstatus = t('NOT CURRENT');
                      break;
                    default:
                      $tmp_projstatus = $projval['status'];
                  }
                  $tmp_modules .= ' ' . $projkey . ':' . $tmp_projstatus;
                  $outdated_count++;
                }
              }
            }
            if ($outdated_count > 0) {
              $tmp_modules = trim($tmp_modules);
              $tmp_state .= " ({$tmp_modules})";
            }
          }
          $output_state[] = $tmp_state;
          break;
        case 'perf':
          $output_perf[] = $key . '=' . $value['text'];
          break;
      }
    }
  }
  $output .= implode(', ', $output_state) . ' | ' . implode(';', $output_perf) . "\n";

  // Output the status page directly with no theming for speed.
  // If people want a themed status page they can write their own and alter the callback in admin.
  echo $output;

  // Exit early so we do not cache the data, nor do we wrap the result in a theme
  exit;
}