Hi All,
I'm playing with event handlers, but I'd like to write back to the Nagios log file from the scripts. I'm comfortable with echo >> but I'm unsure of the actual format. Is this specified somewhere? I think its just: [TIMESTAMP] [MESSAGE]
I'm also not sure how I generate the timestamp, but this seems to do the trick assuming that the timestamp nagios uses is epoch: date +":%s"
I'm running on CentOS 7
Cheers,
Scott
How to write to Nagios log file from eventhandler script
Re: How to write to Nagios log file from eventhandler script
You might want to use a dedicated log file for the eventhandler's outputs if possible. Writing directly to the nagios.log file with 3rd party components can interfere with some things that Nagios XI does on the back-end (mostly with reporting).
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
Re: How to write to Nagios log file from eventhandler script
Thanks for your reply mcapra. I wanted to use the Nagios log so that its available in the event log in the web interface mostly for people that aren't me (I'm the only one here with any linux skills). I'm not savvy enough in the webspace to change the web interface to pick that up. We don't currently have any plans to upgrade to Nagios XI as we are a not for profit and budget is always an issue. Is there a way to add another log file to the interface with configuration rather than changing the web interface code? On your comment I'll have a look at the reports in the core deployment I have and see if there's any issues.mcapra wrote:You might want to use a dedicated log file for the eventhandler's outputs if possible. Writing directly to the nagios.log file with 3rd party components can interfere with some things that Nagios XI does on the back-end (mostly with reporting).
I did actually figure this out in the end. For anyone else that may be interested, first see mcapra's response - what I'm suggesting may well be a bad idea!!!
After a bit of testing and playing around I found that this command worked nicely:
echo [`date +"%s"`] rest of the message you wanted to enter >>/path/to/nagios.log
Leaving out the [] on the time stamp will have some funky results. I passed in the path to the script using the $LOGFILE$ Nagios variable.
Cheers,
Scott.
Re: How to write to Nagios log file from eventhandler script
Thanks for sharing. One way around this, would be to log to a file that is publically available in the HTTP directory. On my system, this happens to be /usr/local/nagios/var/share/ and I created a file called log.txt
From here, modify side.php and add the link -
Add this below the Documentation link -
Final result being this -
(modify 192.168.3.115 to your IP/FQDN)
From here, modify side.php and add the link -
Code: Select all
<ul class="navsectionlinks">
<li><a href="main.php" target="<?php echo $link_target;?>">Home</a></li>
<li><a href="https://go.nagios.com/nagioscore/docs" target="_blank">Documentation</a></li>
</ul>
Code: Select all
<li><a href="http://192.168.3.115/nagios/log.txt" target="_blank">Event Log</a></li>
Code: Select all
<ul class="navsectionlinks">
<li><a href="main.php" target="<?php echo $link_target;?>">Home</a></li>
<li><a href="https://go.nagios.com/nagioscore/docs" target="_blank">Documentation</a></li>
<li><a href="http://192.168.3.115/nagios/log.txt" target="_blank">Event Log</a></li>
</ul>
Former Nagios Employee
Re: How to write to Nagios log file from eventhandler script
That's awesome rkennedy! Thanks for sharing.rkennedy wrote: One way around this, would be to log to a file that is publically available in the HTTP directory
-
- Former Nagios Staff
- Posts: 4583
- Joined: Wed Sep 21, 2016 10:29 am
- Location: NoLo, Minneapolis, MN
- Contact:
Re: How to write to Nagios log file from eventhandler script
@OzGobo, are we ready to lock this up?
Re: How to write to Nagios log file from eventhandler script
Hi there,
Yep, lock it up. Thanks so much for the help.
Cheers,
Scott.
Yep, lock it up. Thanks so much for the help.
Cheers,
Scott.