1

I have Nagios/NSCA setup for a perl custom script that runs on the nagioshost.
I have it configured like:

echo "myhost;myservice;1;Message"|/usr/local/nagios/libexec/send_nsca -to 10 -d ';' -c /etc/send_nsca.cfg -H localhost

It works flawlessly..

So my query, is there a way in Nagios or NSCA to count the passive checks?
i.e. the no of times Nagios receives a alert for myservice on myhost
Note: the custom script never sends 'OK' for a service

Vishnu Kumar
  • 131
  • 5

1 Answers1

1

You could configure nsca (daemon) to output debugging to syslog by setting the debug = 1 in nsca.cfg. Make sure the debug option doesn't appear multiple times with different values in the config file, or it could be overridden. Happened to me :).

nsca.cfg:

# LOG FACILITY
# The syslog facility that should be used for logging purposes.

log_facility=daemon

# DEBUGGING OPTION
# This option determines whether or not debugging
# messages are logged to the syslog facility. 
# Values: 0 = debugging off, 1 = debugging on

debug=1

Example output in /var/log/messages on CentOS 7:

Sep 23 10:53:14 centos nsca[4504]: Starting up daemon
Sep 23 10:53:19 centos nsca[4504]: Handling the connection...
Sep 23 10:53:19 centos nsca[4504]: Time difference in packet: 0 seconds for host myhost
Sep 23 10:53:19 centos nsca[4504]: SERVICE CHECK -> Host Name: 'myhost', Service Description: 'myservice', Return Code: '1', Output: 'Message'
Sep 23 10:53:19 centos nsca[4504]: Attempting to write to nagios command pipe
Sep 23 10:53:19 centos nsca[4504]: Command file '/var/spool/nagios/cmd/nagios.cmd' does not exist, attempting to use alternate dump file '/var/spool/nagios/cmd/nsca.dump' for output
Sep 23 10:53:19 centos nsca[4504]: End of connection...

The next step is to process the logs to get the info/numbers you want. There are lots of ways to do that...

Example as you requested: the no of times Nagios receives a alert for myservice on myhost

grep "SERVICE CHECK -> Host Name: 'myhost', Service Description: 'myservice'" /var/log/messages | wc -l
1

Here you see processing the log show there is 1 entry that matches your criteria.

If you can script or program, you can probably write something that will work quite well even for many client hosts submitting passive checks once you have this data in your logs.

Ryan Babchishin
  • 6,160
  • 2
  • 16
  • 36
  • Thats an excellent approach!! But any idea how I can club this count into the nsca output? – Vishnu Kumar Sep 26 '16 at 09:04
  • @vishnukumar would wrapping send_nsca with a script that keeps a counter work? You could then send it as part of the message. It wouldn't be the number of messages received though rather the number of messages sent. If you're interested I could post a sample script in my answer. – Ryan Babchishin Sep 26 '16 at 15:36
  • yeah that would seem good, but you said the reason why we dont want that counter...BTW can Attempts value be used for this?? – Vishnu Kumar Sep 27 '16 at 12:54
  • @Vishnu sorry I'm not familiar. I don't have nagios running. – Ryan Babchishin Sep 27 '16 at 14:22