You are here

function nagios_check_cron in Nagios Monitoring 8

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

Check when the Drupal cron system was last invoked.

Return value

array Array containing state data

1 call to nagios_check_cron()
NagiosCheckTest::testCronCheck in tests/src/Kernel/NagiosCheckTest.php

File

./nagios.module, line 597
Main file for Nagios service monitoring.

Code

function nagios_check_cron() {
  $config = Drupal::config('nagios.settings');

  // Determine when cron last ran.
  $cron_last = Drupal::state()
    ->get('system.cron_last');
  if (!is_numeric($cron_last)) {
    $cron_last = Drupal::state()
      ->get('install_time', 0);
  }
  $mins = $config
    ->get('nagios.cron_duration') ?: 60;
  $next_expected_cron_run = $cron_last + $mins * 60;
  $request_time = Drupal::time()
    ->getRequestTime();
  if ($request_time > $next_expected_cron_run) {
    $data = [
      'status' => NAGIOS_STATUS_CRITICAL,
      'type' => 'state',
      'text' => t('cron not running @mins mins', [
        '@mins' => $mins,
      ]),
    ];
  }
  else {
    $data = [
      'status' => NAGIOS_STATUS_OK,
      'type' => 'state',
      'text' => '',
    ];
  }
  return [
    'key' => 'CRON',
    'data' => $data,
  ];
}