--- nagios.module.original	2012-02-14 15:39:20.000000000 -0600
+++ nagios.module	2012-03-14 12:03:43.000000000 -0500
@@ -38,6 +38,7 @@
 function nagios_functions() {
   return array(
     'requirements' => t('Checking of hook_requirements. This includes the following: module updates, database schema, files directory writability, update.php protected, Lots of other good stuff ...'),
+    'watchdog' => t('Check recent watchdog entries'),
 
     'cron' => t('Check whether cron has been running regularly'),
 
@@ -246,33 +247,33 @@
             $key == 'ADMIN' &&
             $value['text'] == 'Module and theme update status'
             ) {
-          	$tmp_projects = update_calculate_project_data(update_get_projects());
-          	$outdated_count = 0;
-          	foreach ($tmp_projects as $projkey => $projval) {
-  	          if ($projval['status'] < UPDATE_CURRENT && $projval['status'] >= UPDATE_NOT_SECURE) {
-  	          	switch ($projval['status']) {
-  	          	  case UPDATE_NOT_SECURE:
-  	          	    $tmp_projstatus = t('NOT SECURE');
-  	          	    break;
-  	          	  case UPDATE_REVOKED:
-  	          	    $tmp_projstatus = t('REVOKED');
-  	          	    break;
-  	          	  case UPDATE_NOT_SUPPORTED:
-  	          	    $tmp_projstatus = t('NOT SUPPORTED');
-  	          	    break;
-  	          	  case UPDATE_NOT_CURRENT:
-  	          	    $tmp_projstatus = t('NOT CURRENT');
-  	          	    break;
-  	          	  default:
-  	          	    $tmp_projstatus = $projval['status'];
-  	            }
-
-          	    $tmp_modules .= ' ' . $projkey . ':' . $tmp_projstatus;
-          	    $outdated_count++;
-          	  }
-          	}
-          	if ($outdated_count > 0) {
-          	  $tmp_modules = trim($tmp_modules);
+            $tmp_projects = update_calculate_project_data(update_get_projects());
+            $outdated_count = 0;
+            foreach ($tmp_projects as $projkey => $projval) {
+              if ($projval['status'] < UPDATE_CURRENT && $projval['status'] >= UPDATE_NOT_SECURE) {
+                switch ($projval['status']) {
+                  case UPDATE_NOT_SECURE:
+                    $tmp_projstatus = t('NOT SECURE');
+                    break;
+                  case UPDATE_REVOKED:
+                    $tmp_projstatus = t('REVOKED');
+                    break;
+                  case UPDATE_NOT_SUPPORTED:
+                    $tmp_projstatus = t('NOT SUPPORTED');
+                    break;
+                  case UPDATE_NOT_CURRENT:
+                    $tmp_projstatus = t('NOT CURRENT');
+                    break;
+                  default:
+                    $tmp_projstatus = $projval['status'];
+                }
+
+                $tmp_modules .= ' ' . $projkey . ':' . $tmp_projstatus;
+                $outdated_count++;
+              }
+            }
+            if ($outdated_count > 0) {
+              $tmp_modules = trim($tmp_modules);
               $tmp_state .= " ($tmp_modules)";
             }
           }
@@ -462,6 +463,73 @@
 }
 
 /**
+ * Check Drupal {watchdog} table recent entries
+ *
+ * @return Array
+ */
+function nagios_check_watchdog() {
+  //@TODO Allow LIMIT and OFFSET to be passed in or configurable, or use existing Drupal settings
+  //@TODO Manually count the rows on admin/reports/dblog and match that if nothing else
+  //@TODO Do this more the Drupal Way, whatever that might be
+  //@TODO Allow multi-value 'type' and/or 'severity' inputs for filtering
+  //@TODO Allow datetime ranges
+  $limit = 50;
+  $offset = 0;
+  $query = "SELECT wid, uid, type, severity, message, variables, link, location, hostname, timestamp FROM {watchdog} ORDER BY timestamp DESC LIMIT %d OFFSET %d";
+  $result = db_query($query, $limit, $offset);
+  if (!$result){
+    return array(
+      'status' => NAGIOS_STATUS_UNKNOWN,
+      'type' => 'state',
+      'text' => t('Unable to SELECT FROM {watchdog}')
+    );
+  }
+  //RFC3164/Watchdog has 8 levels. Nagios module has 3 (plus UNKNOWN). This maps one to the other.
+  $severity_translation = array(
+    //watchdog => nagios
+    WATCHDOG_DEBUG => NAGIOS_STATUS_OK,
+    WATCHDOG_INFO => NAGIOS_STATUS_OK,
+    WATCHDOG_NOTICE => NAGIOS_STATUS_OK,
+    WATCHDOG_WARNING => NAGIOS_STATUS_WARNING,
+    WATCHDOG_ERROR => NAGIOS_STATUS_ERROR,
+    WATCHDOG_CRITICAL => NAGIOS_STATUS_ERROR,
+    WATCHDOG_ALERT => NAGIOS_STATUS_ERROR,
+    WATCHDOG_EMERG => NAGIOS_STATUS_ERROR
+  );
+  $severity = NAGIOS_STATUS_OK; //max this across the result set
+  $min_severity = variable_get('nagios_min_report_severity', NAGIOS_STATUS_WARNING);
+  $descriptions = array();
+  while ($row = db_fetch_array($result)){
+    $nagios_severity = $severity_translation[ $row['severity'] ];
+    if ($nagios_severity < $min_severity){
+      continue;
+    }
+    if ($nagios_severity > $severity) $severity = $nagios_severity;
+    $message = "type: $row[type] $row[message]";
+    
+    //@TODO Untangle l(truncate_utf8(_dblog_format_message($dblog), 56, TRUE, TRUE), 'admin/reports/event/'. $dblog->wid, array('html' => TRUE)) and use it here
+    $variables = unserialize($row['variables']);
+    foreach($variables as $key => $value){
+      $message = str_replace("%$key", $value, $message);
+    }
+    
+    $descriptions[] = $message;
+    
+  }
+  $desc = join(', ', $descriptions);
+  
+  //why is an extra array wrapped around here?
+  return array(
+    'key' => 'ADMIN',
+    'data' => array(
+      'status' => $severity,
+      'type' => 'state',
+      'text' => t('@desc', array('@desc' => $desc)) //These watchdog message have translations? Really???
+    )
+  );
+}
+
+/**
  * Check when the Drupal cron system was last invoked.
  *
  * @return Array

