You are here

function nagios_status_page in Nagios Monitoring 7

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

Callback for the nagios status page

2 string references to 'nagios_status_page'
nagios_menu in ./nagios.module
Implements hook_menu().
nagios_settings in ./nagios.module
Callback for the settings page

File

./nagios.module, line 250

Code

function nagios_status_page() {

  // Make sure this page is not cached.
  drupal_page_is_cacheable(FALSE);
  _nagios_update_os_user();
  $args = func_get_args();

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

  // ID to run checks for.
  $id = array_shift($args);
  header("Pragma: no-cache");
  header("Expires: 0");
  $codes = nagios_status();

  // Check the unique ID string and access permissions first.
  $ua = variable_get('nagios_ua', '');
  $request_code = $_SERVER['HTTP_USER_AGENT'];

  // Check if HTTP GET variable "unique_id" is used and the usage is allowed.
  if (isset($_GET['unique_id'])) {
    if (variable_get('nagios_enable_status_page_get', FALSE) == TRUE) {
      $request_code = $_GET['unique_id'];
    }
  }
  if ($request_code == $ua || user_access('administer site configuration')) {

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

      // A specific module has been requested.
      $nagios_data = [];
      $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 = [
      'nagios' => [
        'DRUPAL' => [
          '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 (is_array($value) && array_key_exists('status', $value) && $value['status'] >= $min_severity) {
        $severity = max($severity, $value['status']);
      }
    }
  }

  // Identifier that we check on the other side
  $output = "\n" . 'nagios=' . $codes[$severity] . ', ';
  $output_state = [];
  $output_perf = [];
  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 ($key == 'ADMIN' && $value['text'] == 'Module and theme update status' && variable_get('nagios_show_outdated_names', TRUE)) {

            // Need to ensure the Update module was installed before continuing.
            if (db_table_exists('cache_update')) {
              $tmp_projects = update_calculate_project_data(_nagios_update_get_projects());
              $nagios_ignored_modules = variable_get('nagios_ignored_modules', []);
              $nagios_ignored_themes = variable_get('nagios_ignored_themes', []);
              $nagios_ignored_projects = $nagios_ignored_modules + $nagios_ignored_themes;
              $outdated_count = 0;
              $tmp_modules = '';
              foreach ($tmp_projects as $project_key => $project_val) {
                if (!isset($nagios_ignored_projects[$project_key])) {
                  if ($project_val['status'] < UPDATE_CURRENT && $project_val['status'] >= UPDATE_NOT_SECURE) {
                    switch ($project_val['status']) {
                      case UPDATE_NOT_SECURE:
                        $tmp_project_status = t('NOT SECURE');
                        break;
                      case UPDATE_REVOKED:
                        $tmp_project_status = t('REVOKED');
                        break;
                      case UPDATE_NOT_SUPPORTED:
                        $tmp_project_status = t('NOT SUPPORTED');
                        break;
                      case UPDATE_NOT_CURRENT:
                        $tmp_project_status = t('NOT CURRENT');
                        break;
                      default:
                        $tmp_project_status = $project_val['status'];
                    }
                    $tmp_modules .= ' ' . $project_key . ':' . $tmp_project_status;
                    $outdated_count++;
                  }
                }
              }
              if ($outdated_count > 0) {
                $tmp_modules = trim($tmp_modules);
                $tmp_state .= " ({$tmp_modules})";
              }
            }
            else {
              watchdog('nagios', t('The core update module was never installed so we cannot use update check features.'));
            }
          }
          $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
  drupal_exit();
}