Monitor nagios configuration files

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Monitor nagios configuration files

Postby vusaravi » Thu Oct 05, 2017 12:06 am

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

Re: Monitor nagios configuration files

Postby rhassing » Thu Oct 05, 2017 3:38 am

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
Have I been helpful? Nominate me for a Nagios MVP award!
User avatar
rhassing
 
Posts: 350
Joined: Sat Oct 05, 2013 10:29 pm
Location: Netherlands

Re: Monitor nagios configuration files

Postby kyang » Thu Oct 05, 2017 2:45 pm

Thanks @rhassing!!

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

But the post before this is an excellent option.
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
kyang
 
Posts: 366
Joined: Tue Jul 25, 2017 3:35 pm

Re: Monitor nagios configuration files

Postby bolson » Thu Oct 05, 2017 2:50 pm

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.
Brian Olson
Nagios Support Team
---
Nagios Enterprises, LLC
Email: customersupport@nagios.com
Web: https://www.nagios.com/
User avatar
bolson
Support Tech
 
Posts: 595
Joined: Tue Jul 11, 2017 10:34 am

Re: Monitor nagios configuration files

Postby vusaravi » Sun Oct 08, 2017 11:13 pm

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

Re: Monitor nagios configuration files

Postby mcapra » Mon Oct 09, 2017 7:33 am

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
http://www.mcapra.com/
User avatar
mcapra
 
Posts: 2829
Joined: Thu May 05, 2016 3:54 pm

Re: Monitor nagios configuration files

Postby scottwilkerson » Mon Oct 09, 2017 11:46 am

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.
User avatar
scottwilkerson
CTO
 
Posts: 7904
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: Monitor nagios configuration files

Postby vusaravi » Wed Oct 11, 2017 11:10 pm

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

Re: Monitor nagios configuration files

Postby npolovenko » Thu Oct 12, 2017 4:39 pm

@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.
User avatar
npolovenko
 
Posts: 117
Joined: Mon May 15, 2017 5:00 pm


Return to Nagios Core

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 18 guests