Monitor nagios configuration files

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
vusaravi
Posts: 23
Joined: Fri Mar 13, 2015 7:41 am

Monitor nagios configuration files

Post 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.
User avatar
rhassing
Posts: 412
Joined: Sat Oct 05, 2013 10:29 pm
Location: Netherlands

Re: Monitor nagios configuration files

Post 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"
Rob Hassing
Image
kyang

Re: Monitor nagios configuration files

Post by kyang »

Thanks @rhassing!!

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

But the post before this is an excellent option.
bolson

Re: Monitor nagios configuration files

Post 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.
vusaravi
Posts: 23
Joined: Fri Mar 13, 2015 7:41 am

Re: Monitor nagios configuration files

Post 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.
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Monitor nagios configuration files

Post 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.
Former Nagios employee
https://www.mcapra.com/
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Monitor nagios configuration files

Post 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.
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
vusaravi
Posts: 23
Joined: Fri Mar 13, 2015 7:41 am

Re: Monitor nagios configuration files

Post 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.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Monitor nagios configuration files

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked