AIX Check for New Files

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
User avatar
costanza2k1
Posts: 197
Joined: Fri Aug 09, 2013 12:19 pm

AIX Check for New Files

Post by costanza2k1 »

Hi all,

I want to be able to see if there are any news files within a specific directory:

Directory:
/usr/IBM/WebSphere7.0/profiles/AppSrv01

Files:
If any new files show up in this directory named: *.txt, *.phd, *.trc


If there are any files with those extensions then I need a critical alert...any suggestions?
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: AIX Check for New Files

Post by tmcdonald »

Now there's an important distinction to make: Do you want to alert crit if there are *new* files or *any* files with those extensions?

I ask because the former will be a bit more complicated than the latter.
Former Nagios employee
User avatar
costanza2k1
Posts: 197
Joined: Fri Aug 09, 2013 12:19 pm

Re: AIX Check for New Files

Post by costanza2k1 »

tmcdonald wrote:Now there's an important distinction to make: Do you want to alert crit if there are *new* files or *any* files with those extensions?

I ask because the former will be a bit more complicated than the latter.
The requirement is if there are any files with those extensions.
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: AIX Check for New Files

Post by sreinhardt »

Here is a very basic check for what you are looking for. This will check the path given as the first argument for any comma separated list of extensions(without spaces). Such that a directory listing of

Code: Select all

-rw------- 1 nagios users       303 Mar  7 13:30 checkjSpv6v
-rw------- 1 nagios nagios      257 Mar  4 14:58 checkpSs3D9
-rw-r--r-- 1 root   root          0 Feb 28 10:05 FLAG
drwxr-xr-x 6 root   nagcmd     4096 Nov  7 16:35 Getopt-Long-2.38
drwxr-xr-x 9 root   root       4096 Mar  4 15:02 nagiosxi
drwxr-xr-x 9 root   root       4096 Oct 21 17:53 vmware-vsphere-cli-distrib
-rw-r--r-- 1 root   root   38424689 Feb 11 14:11 xi-latest.tar.gz
Will return the following results:

Code: Select all

./check_files.sh ./ check
Critical - Found files with bad extensions.

./check_files.sh ./ abcd
OK - No files with bad extensions found.

./check_files.sh ./ abcd,check
Critical - Found files with bad extensions.
Plugin:

Code: Select all

#!/bin/bash

# check if certain types of files exist.

IFS=","     # set separator for for loop

for ext in $2; do     # check for each file extension in given arg
        if [[ $(ls -lva $1 | grep -i $ext | wc -l) -gt 0 ]]; then     # if any files are found with this ext, will be greater than 0, exists on first find.
                echo Critical - Found files with bad extensions.
                exit 2
        fi
done

# if we get here, there have been no files found with those names.
echo OK - No files with bad extensions found.
exit 0
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
User avatar
costanza2k1
Posts: 197
Joined: Fri Aug 09, 2013 12:19 pm

Re: AIX Check for New Files

Post by costanza2k1 »

Thank you! I'll try this now.
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: AIX Check for New Files

Post by sreinhardt »

You're welcome, let us know how it works for you. You are of course welcome to modify as needed, like if you would like to know how many of a given file type there were... However I don't want to get too deep into custom development.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
Locked