You are here

function nagios_check in Nagios Monitoring 8

Same name and namespace in other branches
  1. 6 nagios.drush.inc \nagios_check()
  2. 7 nagios.drush.inc \nagios_check()

Helper function for drush_nagios_check().

Parameters

string $module: Module machine name.

string $check: Function name to execute.

1 call to nagios_check()
drush_nagios_check in ./nagios.drush.inc
Drush command callback: nagios-check.

File

./nagios.drush.inc, line 86
Provides drush integration for the Nagios module.

Code

function nagios_check($module, $check) {
  $function = $module . '_nagios_check_' . $check;
  if (function_exists($function)) {
    $nagios_data = $function();
  }
  else {
    $function = $module . '_nagios_check';
    $nagios_data = $function($check);
  }
  $key = key($nagios_data);
  $status = nagios_status();
  $exit_status = $nagios_data[$key]['status'];
  $message = $key . ' ' . $status[$exit_status] . ' - ' . $nagios_data[$key]['text'];
  if ($nagios_data[$key]['type'] == 'perf') {
    $message .= '|' . $key . '=' . $nagios_data[$key]['text'];
  }

  // We want to exit with the correct exit status so Nagios knows the outcome
  // of our drush nagios check so set DRUSH_EXECUTION_COMPLETED to true.
  drush_set_context('DRUSH_EXECUTION_COMPLETED', TRUE);
  drush_print($message);
  $users = array_unique(_nagios_update_os_user());
  if (count($users) > 1 && $exit_status != NAGIOS_STATUS_OK) {
    $warning = dt('Warning') . ': ';
    $warning .= dt('All nagios checks should be executed as the same user as the web page.') . "\n";
    $warning .= dt('This is important when modules confirm file system permissions are correct.') . "\n";
    $warning .= dt('You can use `sudo -u` to run drush under a different user.') . "\n";
    drush_print($warning);
    $rows = drush_key_value_to_array_table($users);
    array_unshift($rows, [
      'PHP_SAPI',
      '',
      strtoupper(dt('Operating system user')),
    ]);
    drush_print_table($rows, TRUE);
  }
  exit($exit_status);
}