You are here

function _prod_check_dblog_php in Production check & Production monitor 7

Same name and namespace in other branches
  1. 6 prod_check.module \_prod_check_dblog_php()

File

./prod_check.module, line 899

Code

function _prod_check_dblog_php($caller = 'internal') {
  if (!module_exists('dblog')) {
    return;
  }
  $check = array();
  $title = 'PHP errors';
  $path = 'admin/reports/dblog';
  if ($caller != 'internal') {
    $path = PRODCHECK_BASEURL . $path;
  }
  $error = FALSE;
  $error_level = variable_get('prod_check_dblog_php', WATCHDOG_WARNING);
  $threshold = variable_get('prod_check_dblog_php_threshold', 1);
  $result = db_query('SELECT COUNT(*) FROM (SELECT count(wid) FROM {watchdog} WHERE type = :type AND severity <= :severity GROUP BY variables HAVING COUNT(wid) >= :threshold) subquery', array(
    ':type' => 'php',
    ':severity' => $error_level,
    ':threshold' => $threshold,
  ))
    ->fetchField();
  if ($result) {
    $error = TRUE;
  }
  $check['prod_check_dblog_php'] = array(
    '#title' => t($title),
    '#state' => !$error,
    '#severity' => $caller == 'nagios' ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING,
    '#value_ok' => t('No PHP errors reported.'),
    '#value_nok' => t('PHP errors reported!'),
    '#description_ok' => t('Status is OK for production use.'),
    '#description_nok' => format_plural($result, '@count PHP error occuring more than !threshold time(s) has been reported! Check the !link for details!', '@count PHP errors occuring more than !threshold time(s) have been reported! Check the !link for details!', array(
      '!link' => implode(prod_check_link_array($title, $path)),
      '!threshold' => $threshold,
    )),
    '#nagios_key' => 'PHP',
    '#nagios_type' => 'state',
  );
  return prod_check_execute_check($check, $caller);
}