We are using the Nagios module together with prod_check. I'm coding a prod_check_menu_alter() hook so that prod_check will allow you to customise the default /nagios callback to be whatever you like (e.g. /nas-nagios or whatever).

The reason for doing this is that we like to hide as much of this info as possible (see also #672264: No default "Unique ID" or make it unique), whether it's a big security risk or not. We just feel it's not 'clean' for all to be able to access the nagios page so easily.

Maybe it would be nice to have this config option in the Nagios module?

Comments

malc0mn’s picture

Code example from prod_check:

settings page:
<?php
    $form['prod_check_nagios']['nagios']['settings']['prod_check_nagios_takeover'] = array(
      '#type' => 'textfield',
      '#title' =>   t('Custom Nagios path'),
      '#description' => t('If you wish to use a different path than the default /nagios path enabled by the Nagios module, then enter the desired path here. Leave blank to do disable the takover.'),
      '#default_value' => variable_get('prod_check_nagios_takeover', ''),
      '#required' => FALSE,
    );

    $form['prod_check_nagios']['nagios']['settings']['prod_check_nagios_unique'] = array(
      '#type' => 'select',
      '#title' =>   t('When Nagios unique ID not recieved'),
      '#description' => t('Select what should happen when the Nagios unique ID is not recieved by the nagios page.'),
      '#options' => array(
        'default' => t('default Nagios module behavior'),
        '404' => t('throw a 404 error'),
        'home' => t('redirect to homepege'),
      ),
      '#default_value' => variable_get('prod_check_nagios_unique', 'default'),
      '#required' => FALSE,
    );
?>
callback override:
<?php
/**
 * Implementation of hook_menu()
 */
function prod_check_menu_alter(&$items) {
  if (variable_get('prod_check_enable_nagios', 0) && isset($items['nagios'])) {
    // Change callback.
    if (variable_get('prod_check_nagios_unique', 'default') != 'default') {
      $items['nagios']['page callback'] = 'prod_check_nagios_status_page';
    }
    // Change the path.
    $new_path = variable_get('prod_check_nagios_takeover', '');
    if (!empty($new_path)) {
      // Create custom Nagios path.
      $items[$new_path] = $items['nagios'];
      // Drop old Nagios path.
      unset($items['nagios']);
    }
  }
}

/**
 * Custom callback to override /nagios page.
 */
function prod_check_nagios_status_page() {
  if ($_SERVER['HTTP_USER_AGENT'] != variable_get('nagios_ua', 'Nagios')) {
    switch (variable_get('prod_check_nagios_unique', 'default')) {
      case '404': drupal_not_found();
        break;
      case 'home': drupal_goto('<front>');
        break;
      default: nagios_status_page();
    }
  }
  else {
    nagios_status_page();
  }
}
?>

I'm happy to make a patch if this functionality is wanted enough.

greg.harvey’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

Moving to D7. Sounds a sensible feature request to me.

greg.harvey’s picture

Status: Active » Needs review
StatusFileSize
new2.21 KB

Patch attached.

greg.harvey’s picture

Naughty patch! Bad mistake! Wrong default variable for callback. Whoops. Use this.

helmo’s picture

Not sure if it was accidental al, but this code is already in the 7.x-1.x branch. in commit e5cd4b7cf1847de7394cac59692cdfb0556e9f62

Changing the page path and callback both work as expected.

greg.harvey’s picture

Status: Needs review » Fixed

Oh crap, I thought I'd branched to make the patch! Thank God it works OK.

/me slaps his wrists and tells himself to be more careful...

This *might* be rolled back in favour or proper theming - see #1337954: Nagios reporting page using full page template?

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.