Hi there,
I'm struggling with the NagiosAppender log4j (latest download version) and running out of ideas. I have configured the Nagios server for passive checks using send_nsca successfully. I can verify that by sending checks to the same service/virtualhost using the command line send_nsca utility from the same remote host where I'm setting up the appender. Unfortunately when I try to do this with the NagiosAppender log4j I can not send any messages to the Nagios server. To simplify things I'm trying it with a HelloWorld-type java app that does nothing else but sending an error message. I can log the message to console but not to Nagios. I do not see any errors whatsoever. Any help would be trully appreciated. Attaching the config files.
log4j.properties
Here are some suggestions.
1. Confirm you are reading the log4j.properties file by adding a file appender and verify that the file gets created and is written to. The log4j.properties file needs to be on your classpath
2. turn on debug on the nsca server, and tail /var/log/messages when you run HelloWorld
3. Consider starting with the log4j.properties file that comes with the download as a starting point, and make incremental changes to get it where you want it.
4. make sure that your encryption choice between nsca server and HelloWorld client match (BTW ... the only choices the appender supports is 0 (NONE) and 1 (XOR)
PS I believe the version checked in does not require layout .... not sure why but this only appears to affect log4j.properties configured apps ..... You can simply recompile it with the method ... layoutRequired ... set it to return true.
Thank you for your timely feedback. Here are the findings based on your suggestions:
1. Confirmed. To make sure this was the case I tried it with a CONSOLE and FILE appenders and it does read the file in question.
2. Confirmed. Here's the output that I get in syslog:
Jun 29 17:24:57 dc2vplnag01 xinetd[3459]: START: nsca pid=13903 from=10.2.12.221
Jun 29 17:24:57 dc2vplnag01 nsca[13903]: Received invalid packet type/version from client - possibly due to client using wrong password or crypto algorithm?
Jun 29 17:24:57 dc2vplnag01 xinetd[3459]: EXIT: nsca status=0 pid=13903 duration=0(sec)
Which is puzzling to say the least since I have configured log4j.properties to use the same (stock) send_nsca.cfg file that if I use with the send_nsca utility from the command line it works fine..
3. Confirmed. This is why I got this far.. If it will help you troubleshoot it I can start from scratch (will not the first time this week)
4. Confirmed. They match and are both using 1 (XOR). Here's even more puzzling info (hopefully not a red herring). I tried changing the encryption to 0 on both - client and server, then restarted the server deamon. Afterwords even the send_nsca command line utility starts bombing with the same error message as mentioned in the answer to your suggestion 2...
I am not sure what do you mean by your final comment.. When I comment this in log4j.properties:
log4j.appender.NAGIOS.layout=org.apache.log4j.PatternLayout
I get this:
log4j:ERROR Could not find value for key log4j.appender.NAGIOS.layout.
Could you please advise on this a bit futher..
Thank you very much for your help!
I made some progress.
After experimenting with the send_nsca.cfg encryption methods on the Nagios client and server I realized that the log4.properties does not adhere to the settings in /etc/nagios/send_nsca.cfg. It is simply using encryption 0. Once I corrected that on the Nagios server things started to work. I would still like to find out why does the follwoing entry in log4j
log4j.appender.NAGIOS.ConfigFile=/etc/nagios/send_nsca.cfg
doesn't overwrite the default settings or why it is not reading this file but still happier that things started moving in the right direction.
I have a question about this setup. After I download and unzip the files it is my understanding that all I need to do is:
1. Put the NagiosAppender-1.5.1.jar, log4j-1.2.9.jar adn log4.properties in the $CLASSPATH
2. Modify the log4.properties as described in the supplied documentation.
Am I missing a step?