Comments are stored in /usr/local/nagios/var/status.dat
You can view it (non-intrusively) by doing cat /usr/local/nagios/var/status.dat
An example of one of the comment entries is:
hostcomment {
host_name=Customer ABC
entry_type=4
comment_id=27065
source=0
persistent=0
entry_time=1283883777
expires=0
expire_time=0
author=Nagios Admin
comment_data=Checking now (Rich)
}
Before you get too excited it’s not as easy as just editing that file. This file is locked while nagios is running so you can’t edit anything.
If you stop nagios, however, the contents of status.dat are written to:
/usr/local/nagios/var/retention.dat
And this is where you can have fun!
While nagios is stopped you can edit the data in retention.dat, but I would recommend only using the following to avoid causing ownership problems:
/usr/local/nagios/var$ sudo -u nagios pico retention.dat
or
/usr/local/nagios/var$ sudo -u nagios gedit retention.dat
should also work but i don’t have a GUI on my servers here at home so can’t test it.
The key is the name. You can move a comment to another entry by just changing the ‘host_name’ to another valid host.
It appears on each start of nagios any comments with invalid hosts are deleted. So the only way you could change a hostname and retain comments would be to stop nagios – change the host-name in customers.cfg and then also find and replace in retention.dat for the same hostname-change. And restart nagios. (Remember to make sure you don’t fudge up the ownership/permissions)
If you just change the hostname in customers.cfg and restart nagios all old comments are wiped.
Other thoughts:
Entry Type:
entry_type=1 = User Comment
entry_type=2 = System Comments (flapping)
entry_type=4 = Acknowledgements
Fun with linux:
- if you wanted to see just the user comments for hosts:
grep -B2 -A9 entry_type.1 retention.dat - if you wanted to find all comments that contain Flubber you first search for retention (and get the 2 lines before and 9 lines after) then grep THOSE results for Flubber (-i = not-case-sensitive):
grep -B2 -A9 entry_type.1 retention.dat | grep -B1 -A10 -i Flubber - To replace the text ‘John’ with ‘John Doe’ you could:
- cat retention.dat | sed “s/John/John Doe/g” >retention1.dat
- the changed file will be at retention1.dat
- To do it inline:
- sed -i “s/John/John Doe/g” retention.dat
- cat retention.dat | sed “s/John/John Doe/g” >retention1.dat