]> arthur.barton.de Git - nagcollect.git/blobdiff - server/web/nagcollect.php
Service update: log the IP address of the peer in the host status field
[nagcollect.git] / server / web / nagcollect.php
index 29da2cd0dac179d230cb702d091e4989d4a1ff65..9b5637b2e66144f8cea0694c23b44e6ca5e6c113 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  * NagCollect -- Nagios Data Collector for Passive Checks
- * Copyright (c)2009 Alexander Barton, alex@barton.de
+ * Copyright (c)2009-2010 Alexander Barton, alex@barton.de
  */
 
 function nagiosSubmitHost($host, $status, $text = null)
@@ -51,7 +51,6 @@ function checkKey($key, $host)
                }
        }
        fclose($fh);
-       error_log("NagCollect: received invalid key \"$key\"!");
        return false;
 }
 
@@ -77,7 +76,9 @@ function processRequest($args)
                        return 500;
        } else {
                // Service Update
-               if (!nagiosSubmitHost($host, 0, 'Received passive service check'))
+               $hostStatus = 'Received passive service check from '
+                                       . '"' . $_SERVER['REMOTE_ADDR'] . '"';
+               if (!nagiosSubmitHost($host, 0, $hostStatus))
                        return 500;
                if (!nagiosSubmitService($host, $service, $status, $text))
                        return 500;
@@ -96,12 +97,21 @@ function getHttpStatusText($status)
        }
 }
 
+openlog("NagCollect", LOG_ODELAY, LOG_DAEMON);
+
 $httpStatus = processRequest($_POST);
 $httpStatusText = getHttpStatusText($httpStatus);
 
 $statusText = $httpStatus . ' - ' . $httpStatusText;
 
-header("HTTP/1.0 $httpStatus $ttpStatusText");
+if ($httpStatus != 200) {
+       syslog(LOG_WARNING, "Warning: $httpStatusText ($httpStatus) from "
+                  . "\"{$_SERVER['REMOTE_ADDR']}\" ({$_SERVER['HTTP_USER_AGENT']})");
+}
+
+closelog();
+
+header("HTTP/1.0 $httpStatus $httpStatusText");
 
 ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">