Monitor nagios configuration files
Monitor nagios configuration files
Hi Folks
I would like to monitor nagios configuration files i.e. services.cfg, hosts.cfg, contacts.cfg, .
Is there any custom/inbuilt plugin to monitor the files modified date.?
Kindly help me.
I would like to monitor nagios configuration files i.e. services.cfg, hosts.cfg, contacts.cfg, .
Is there any custom/inbuilt plugin to monitor the files modified date.?
Kindly help me.
Re: Monitor nagios configuration files
In NET-SNMP it is easy to create options in the snmpd.conf file which will execute scripts.
This way it is easy to execute scripts from a remote server without the need to log in, or have another daemon running.
On the host, where the script should be executed, runs the snmp daemon that comes with the NET-SNMP package. In de file snmpd.conf we add the following line:
Restart the snmpd process
On this host we also create these script:
The oid which can be used to execute the scripts is: .1.3.6.1.4.1.2021.8
The next command can be executed on any remote host (which has the rights):
The output would be something like this:
In Nagios, you could use the check_snmp plugin:
This way it is easy to execute scripts from a remote server without the need to log in, or have another daemon running.
On the host, where the script should be executed, runs the snmp daemon that comes with the NET-SNMP package. In de file snmpd.conf we add the following line:
Code: Select all
exec filedate /usr/local/bin/check_file-date.sh
On this host we also create these script:
Code: Select all
check_file-date.sh:
#!/bin/bash
ls -l /etc/nagios/nagios.cfg | awk '{print $6,$7,$8}'
exit 0
The next command can be executed on any remote host (which has the rights):
Code: Select all
snmpwalk -v1 -c public 192.168.1.1 .1.3.6.1.4.1.2021.8
Code: Select all
iso.3.6.1.4.1.2021.8.1.1.1 = INTEGER: 1
iso.3.6.1.4.1.2021.8.1.2.1 = STRING: "filedate"
iso.3.6.1.4.1.2021.8.1.3.1 = STRING: "/usr/local/bin/check_file-date.sh"
iso.3.6.1.4.1.2021.8.1.100.1 = INTEGER: 0
iso.3.6.1.4.1.2021.8.1.101.1 = STRING: "Dec 17 2015"
iso.3.6.1.4.1.2021.8.1.102.1 = INTEGER: 0
iso.3.6.1.4.1.2021.8.1.103.1 = ""
Code: Select all
check_snmp -H 1927.168.1.1 -o 1.3.6.1.4.1.2021.8.1.101.1 -C public -s "\"Dec 17 2015\""
SNMP OK - "Dec 17 2015"
Rob Hassing
Re: Monitor nagios configuration files
It's worth noting that the ls -l command is not consistent in terms of how it displays file timestamps. Probably better to use ls --time-style=long_iso and modify the script and command appropriately.
Re: Monitor nagios configuration files
Hi All
Currently i am monitoring some configuration files on windows, the below check will alert me whenever the specific pattern files are modified within given time period.
It will monitor *.js files in the specified folder and if the files are modified within last hour, then it will trigger notification.
The same is not working for Linux environment.
Could you please suggest me a similar plugin which works as above.
Currently i am monitoring some configuration files on windows, the below check will alert me whenever the specific pattern files are modified within given time period.
Code: Select all
check_nrpe!check_files!path='C:\F1\F2\PROD\webroot\shared\insurance\app' pattern=*.js "filter=written> -60m and file ne 'TreeData.js' " "max-depth=3" empty-state=ok "detail-syntax=%(filename)" warn='count=1' crit='count>=1'
The same is not working for Linux environment.
Could you please suggest me a similar plugin which works as above.
Re: Monitor nagios configuration files
If you wanted to use the same check_files command you have above, you might be able to build NSClient++ on your Linux machine but it's probably more trouble than it's worth:
https://docs.nsclient.org/about/build/
I can't guarantee the commands work the same between Linux and Windows environments though. You'd have better luck on the NSClient++ forums regarding those questions.
A more Linux-friendly solution might be to use the check_file_age plugin included with nagios-plugins. The solution provided by @rhassing is also still valid.
https://docs.nsclient.org/about/build/
I can't guarantee the commands work the same between Linux and Windows environments though. You'd have better luck on the NSClient++ forums regarding those questions.
A more Linux-friendly solution might be to use the check_file_age plugin included with nagios-plugins. The solution provided by @rhassing is also still valid.
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Monitor nagios configuration files
I'll concur with @mcapra that building NSClient++ on your Linux machine but it's probably more trouble than it's worth
also sage advice
also sage advice
mcapra wrote:A more Linux-friendly solution might be to use the check_file_age plugin included with nagios-plugins. The solution provided by @rhassing is also still valid.
Re: Monitor nagios configuration files
Thank you @scottwilkerson
I had a look at check_file_age plugin.
It is not useful in my case, it is just returning the file age i.e. No of seconds since the file modified.
This plugin will be useful when there is a requirement to monitor the files that will get updated on daily basis.
But my case is quite opposite, i have to monitor the files, when there is no update, then it should be OK and when there is an update of files, it should return Warn/Critical based on the threshold.
Kindly let me know if there is an NRPE plugin to monitor the same.
Thanks in advance.
Regards,
Ravi Kumar Vusa.
I had a look at check_file_age plugin.
It is not useful in my case, it is just returning the file age i.e. No of seconds since the file modified.
This plugin will be useful when there is a requirement to monitor the files that will get updated on daily basis.
But my case is quite opposite, i have to monitor the files, when there is no update, then it should be OK and when there is an update of files, it should return Warn/Critical based on the threshold.
Kindly let me know if there is an NRPE plugin to monitor the same.
Thanks in advance.
Regards,
Ravi Kumar Vusa.
-
- Support Tech
- Posts: 3457
- Joined: Mon May 15, 2017 5:00 pm
Re: Monitor nagios configuration files
@vusaravi, You could revert a couple lines in this plugin and it'll do what you want.
The line where it says $opt_w is your warning threshold and $opt_c is the critical threshold.
Then modify this two lines to
Now if the file HASN'T been modified it will return OK, but if it has it will return a warning or critical based on your thresholds.
The line where it says
Code: Select all
$opt_w = 240;
$opt_c = 600;
Then modify this two lines
Code: Select all
if (($opt_c and $age > $opt_c) or ($opt_C and $size < $opt_C)) {
$result = 'CRITICAL';
}
elsif (($opt_w and $age > $opt_w) or ($opt_W and $size < $opt_W)) {
$result = 'WARNING';
}
Code: Select all
if (($opt_c and $age < $opt_c) or ($opt_C and $size < $opt_C)) {
$result = 'CRITICAL';
}
elsif (($opt_w and $age < $opt_w) or ($opt_W and $size < $opt_W)) {
$result = 'WARNING';
}
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.