You are here

function hook_nagios in Nagios Monitoring 8

Same name and namespace in other branches
  1. 7 nagios.api.php \hook_nagios()

Does the actual work of checking something.

Parameters

string $id: Optional, an identifier which is the 2nd argument passed via the URL. this is useful when you just want nagios to check a single function. example: http://mysite.com/nagios/mymodule/myId.

"myId" would be send to mymodule_nagios.

http://mysite.com/nagios/mymodule would not send any id, but would not run hook_nagios for any other modules.

Return value

array The data returned is an associative array as follows:

array( 'key' => 'IDENTIFIER', 'data' => array( 'status' => STATUS_CODE, 'type => 'state', // Can be a 'state' for OK, Warning, Critical, Unknown) or can be 'perf', which does // Cause an alert, but can be processed later by custom programs 'text' => 'Text description for the problem', ), );

STATUS_CODE must be one of the following, defined in nagios.module:

NAGIOS_STATUS_OK NAGIOS_STATUS_UNKNOWN NAGIOS_STATUS_WARNING NAGIOS_STATUS_CRITICAL

Here is an example:

array

2 functions implement hook_nagios()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

nagios_hook_test_module_nagios in tests/modules/nagios_hook_test_module/nagios_hook_test_module.module
Implements hook_nagios().
nagios_nagios in ./nagios.module
Implements hook_nagios().
2 invocations of hook_nagios()
NagiosCommands::nagios in src/Commands/NagiosCommands.php
Allows querying Drupal's health. Useful for NRPE.
NagiosCommands::nagios_list in src/Commands/NagiosCommands.php
Prints valid checks for `drush nagios`.

File

./nagios.api.php, line 58
Document hooks provided by the Nagios Monitoring module.

Code

function hook_nagios(string $id) {

  // Check something ...
  $count = 10;
  if (!$count) {
    $data = [
      'status' => NAGIOS_STATUS_WARNING,
      'type' => 'state',
      'text' => t('A very brief description of the warning'),
    ];
  }
  else {
    $data = [
      'status' => NAGIOS_STATUS_OK,
      'type' => 'state',
      'text' => '',
    ];
  }
  return [
    'key' => 'IDENTIFIER',
    // This identifier will appear on Nagios' monitoring pages and alerts.
    'data' => $data,
  ];
}