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

Next revision
Previous revision
docs:tips_n_tricks:nagios:using_http_for_passive_checks [22.10.2012 16:18 CEST] – created peterdocs:tips_n_tricks:nagios:using_http_for_passive_checks [23.10.2012 10:54 CEST] (current) peter
Line 1: Line 1:
 ====== Using HTTP for passive checks ====== ====== Using HTTP for passive checks ======
  
-This description is valid for //Nagios 3// and sketches a quick-and-dirty approach.+===== Using cmd.cgi ===== 
 +This description is valid for //Nagios 3//.
  
 In situations, where you cannot use ''send_nsca'' for submitting passive check results over the network, you can use the Nagios web interface. You need an http account In situations, where you cannot use ''send_nsca'' for submitting passive check results over the network, you can use the Nagios web interface. You need an http account
  
   * Allowed to access nagios by your webserver, normally accomplished with //Basic Auth// and //htpasswd//.   * Allowed to access nagios by your webserver, normally accomplished with //Basic Auth// and //htpasswd//.
-  * Allowed to view all services/hosts((pick the one you need)) via ''/etc/nagios3/cgi.cfg'' +  * Allowed to submit passive check results via cgi, this can be done either by 
-  * Allowed to submit commands for all services/hosts((pick the one you need) via ''/etc/nagios3/cgi.cfg''+    * via dedicated permissions on the host(s) and service(s) in question\\  
 +    or 
 +    * Allowed to view all services/hosts((pick the one you need)) via ''/etc/nagios3/cgi.cfg'' 
 +    * Allowed to submit commands for all services/hosts((pick the one you need)) via ''/etc/nagios3/cgi.cfg''
  
-Assuming you have your credetionals for the account //http_remote// saved in either ''~/.wgetrc'' or ''~/.netrc''this example will submit passive check result for the service //TEST// on host //localhost// in status //UNKNOWN//((which is numerically 3))+At least if you are going to use dedicated permissionsyou need to define nagios contact, that might look like:
  
-  wget -O - --user=http_remote +  define contact{ 
-  --auth-no-challenge \ +          contact_name                    passive_via_http 
-  --no-check-cert \+          alias                           passive_via_http 
 +          service_notification_period     never 
 +          host_notification_period        never 
 +          service_notification_options    n 
 +          host_notification_options       n 
 +          service_notification_commands   notify-service-by-email 
 +          host_notification_commands      notify-host-by-email 
 +        } 
 + 
 +Assuming you have your credentionals for the account //http_remote// saved in either ''~/.wgetrc'' or ''~/.netrc'', this example will submit a passive check result for the service //TEST// on host //localhost// in status //UNKNOWN//((which is numerically 3)): 
 + 
 +  wget -O - 
 +       --user=passive_via_http 
 +       --auth-no-challenge \ 
 +       --no-check-cert \
   'https://<nagios-server>/cgi-bin/nagios3/cmd.cgi'\   'https://<nagios-server>/cgi-bin/nagios3/cmd.cgi'\
   '?cmd_typ=30'\   '?cmd_typ=30'\
Line 23: Line 41:
   '&btnSubmit=Commit'   '&btnSubmit=Commit'
  
-Of course, in a large environment with appropriate security needs, you would write a php script that is restricted to write passive checks.+Of course, in a large environment with appropriate security needs, you would write a PHP script that is restricted to write passive checks. 
 + 
 +===== Using PHP ===== 
 +If you prefer a separate PHP script, this may serve as a skeleton: 
 + 
 +  <?php 
 +  $state_str=array( 0 => 'OK'     ,  
 +                    1 => 'WARN'   , 
 +                    2 => 'CRIT'   , 
 +                    3 => 'UNKNOWN') ; 
 +  $nsca_host="localhost"
 +  $send_nsca="/usr/sbin/send_nsca"
 +  ?> 
 +  <HTML> 
 +  <HEAD> 
 +  <TITLE>http nsca reciever</TITLE> 
 +  </HEAD> 
 +  <BODY> 
 +  <?php 
 +  $log_fh=fopen("/tmp/nsca.php.log","a") ; 
 +  fwrite($log_fh,'========= BEGIN ============'."\n"); 
 +  ?><H2>Input</H2><?php 
 +  while (list ($key, $val) = each ($_REQUEST)) { 
 +   print htmlentities("$key = '$val'")."<BR>\n"; 
 +   fwrite($log_fh,"$key = '$val'\n"); 
 +   } 
 +   
 +  $host    = $_REQUEST['host'] ; 
 +  $service = $_REQUEST['service'] ; 
 +  $state   = $_REQUEST['state'] ; 
 +  $msg     = $_REQUEST['msg'] ; 
 +  ?><H2>Output</H2><?php 
 +  $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($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); 
 +   
 +  fwrite($log_fh,'========= END ============'."\n"); 
 +  fclose($log_fh); 
 +  ?> 
 +  </BODY> 
 +  </HTML> 
 + 
 + 
 + 
 +{{tag>Nagios Monitoring}} 
 +{{entry>Nagios}} 
 +{{entry>Monitoring}}
docs/tips_n_tricks/nagios/using_http_for_passive_checks.1350915490.txt.gz · Last modified: 22.10.2012 16:18 CEST by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki