Page 1 of 1

Monitor nagios configuration files

Posted: Thu Oct 05, 2017 12:06 am
by vusaravi
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.

Re: Monitor nagios configuration files

Posted: Thu Oct 05, 2017 3:38 am
by rhassing
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:

Code: Select all

exec filedate /usr/local/bin/check_file-date.sh
Restart the snmpd process

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 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):

Code: Select all

snmpwalk -v1 -c public 192.168.1.1 .1.3.6.1.4.1.2021.8
The output would be something like this:

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 = ""
In Nagios, you could use the check_snmp plugin:

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"

Re: Monitor nagios configuration files

Posted: Thu Oct 05, 2017 2:45 pm
by kyang
Thanks @rhassing!!

@vusaravi, Let us know if you have any more questions.

But the post before this is an excellent option.

Re: Monitor nagios configuration files

Posted: Thu Oct 05, 2017 2:50 pm
by bolson
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

Posted: Sun Oct 08, 2017 11:13 pm
by vusaravi
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.

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'
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.

Re: Monitor nagios configuration files

Posted: Mon Oct 09, 2017 7:33 am
by mcapra
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.

Re: Monitor nagios configuration files

Posted: Mon Oct 09, 2017 11:46 am
by scottwilkerson
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
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

Posted: Wed Oct 11, 2017 11:10 pm
by vusaravi
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.

Re: Monitor nagios configuration files

Posted: Thu Oct 12, 2017 4:39 pm
by npolovenko
@vusaravi, You could revert a couple lines in this plugin and it'll do what you want.
The line where it says

Code: Select all

$opt_w = 240;
$opt_c = 600;
$opt_w is your warning threshold and $opt_c is the critical threshold.

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';
	}
to

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';
	}
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.