User Tools

Site Tools


docs:tips_n_tricks:nagios:using_http_for_passive_checks

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
docs:tips_n_tricks:nagios:using_http_for_passive_checks [23.10.2012 10:44 CEST] peterdocs:tips_n_tricks:nagios:using_http_for_passive_checks [23.10.2012 10:54 CEST] (current) peter
Line 47: Line 47:
  
   <?php   <?php
 +  $state_str=array( 0 => 'OK'     , 
 +                    1 => 'WARN'   ,
 +                    2 => 'CRIT'   ,
 +                    3 => 'UNKNOWN') ;
   $nsca_host="localhost" ;   $nsca_host="localhost" ;
   $send_nsca="/usr/sbin/send_nsca" ;   $send_nsca="/usr/sbin/send_nsca" ;
Line 58: Line 62:
   $log_fh=fopen("/tmp/nsca.php.log","a") ;   $log_fh=fopen("/tmp/nsca.php.log","a") ;
   fwrite($log_fh,'========= BEGIN ============'."\n");   fwrite($log_fh,'========= BEGIN ============'."\n");
 +  ?><H2>Input</H2><?php
   while (list ($key, $val) = each ($_REQUEST)) {   while (list ($key, $val) = each ($_REQUEST)) {
    print htmlentities("$key = '$val'")."<BR>\n";    print htmlentities("$key = '$val'")."<BR>\n";
Line 67: Line 72:
   $state   = $_REQUEST['state'] ;   $state   = $_REQUEST['state'] ;
   $msg     = $_REQUEST['msg'] ;   $msg     = $_REQUEST['msg'] ;
-  +  ?><H2>Output</H2><?php
   $nsca_fh=popen($send_nsca.' -H '.$nsca_host,"w") ;   $nsca_fh=popen($send_nsca.' -H '.$nsca_host,"w") ;
   fwrite($nsca_fh,sprintf("%s\t%s\t%s\t%s\n",$host,$service,$state,$msg));   fwrite($nsca_fh,sprintf("%s\t%s\t%s\t%s\n",$host,$service,$state,$msg));
-  fwrite($log_fh,sprintf("%s<T>%s<T>%s<T>%s\n",$host,$service,$state,$msg));+  fwrite($log_fh,sprintf("%s<T>%s<T>%s<T>%s\n",$host,$service,$state.' ('.$state_str[$state].')',$msg)); 
 +  printf("<TABLE BORDER=1><TR><TD>Host</TD><TD>Service</TD><TD>State</TD><TD>Message</TD></TR>"
 +         "<TR><TD>%s</TD><TD>%s</TD><TD>%s</TD><TD>%s</TD></TR></TABLE>\n",$host,$service,$state.' ('.$state_str[$state].')',$msg);
   pclose($nsca_fh);   pclose($nsca_fh);
      
Line 78: Line 85:
   </BODY>   </BODY>
   </HTML>   </HTML>
 +
  
  
docs/tips_n_tricks/nagios/using_http_for_passive_checks.1350981868.txt.gz · Last modified: 23.10.2012 10:44 CEST by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki