Lampros - Weird Bricks

Nagios script that checks permissions for a file

12 March, 2017 | Nagios

A few days ago I run into a situation where the ownership of a file would change unexpectedly.

Fearing the worse, I looked around for a Nagios check to ensure that I get alerted if that were to happen but I couldn't find one so I wrote my own.

The code is here:

It's usage is very simple:

1. Download the script, copy paste it or whatever works for you. On CentOS you most likely want this under /usr/lib64/nagios/plugins/ or /usr/local/bin/.

2. Make it executable:

chmod +x

3. Try it out:

./ /etc/passwd root root 644
OK - all permissions match

4. Try it again, but this time tell it that the expected permissions are 777 (hur hur hur):

./ /etc/passwd root root 777
CRITICAL - the octal permissions do not match - expected: 777, found: 644

5. One more time - this time tell it that it belongs to the user goatlord:

./ /etc/passwd goatlord root 644
CRITICAL - the users do not match - expected: goatlord, found: root

6. Let's check the groups too!

./ /etc/passwd root goats 644
CRITICAL - the groups do not match - expected: goats, found: root

Have fun!