Nagios Plugin to Check Files Are Created Within X Minutes

Find command to check no files is created within x minutes

You could try combining this
run a unix shell command if the output doesn't have a specific number of lines

With

vagrant@puppet ~]$ find . -name '*.ts' -mmin -1 | wc -l
0
[vagrant@puppet ~]$ touch blah.ts
[vagrant@puppet ~]$ find . -name '*.ts' -mmin -1 | wc -l
1

So:

[vagrant@puppet ~]$ ./alert.sh
No new files
[vagrant@puppet ~]$ echo >> blah.ts
[vagrant@puppet ~]$ ./alert.sh
[vagrant@puppet ~]$ cat alert.sh
#!/bin/sh

newfiles=$(find . -name '*.ts' -mmin -1 | wc -l)

if [[ $newfiles -eq 0 ]] ; then
echo "No new files"
fi
[vagrant@puppet ~]$

Is Nagios the appropriate tool for monitoring based upon file dates?

I don't think there is a suitable out-of-the-box plugin for that, but writing your own Nagios plugins is really easy - the API is in its simplest form that your program (written in anything that can execute on the Nagios host) has to do this:

* Exit with one of several possible return values
* Return at least one line of text output to STDOUT

If your Nagios administrator don't want custom plugins, you aren't out of options. If you can publish the current state of the process you want to monitor on a web server, the standard plugin check_http can be configured to look for certain strings on a web page.

You could also make use of passive checks, having your program feed the Nagios machine with test results either directly via the external_command_file or via a HTTP POST in the web interface.

How do I use Nagios to monitor a log file

As there are many ways to achieve a goal, there is also a nice plugin from Consol available:
https://labs.consol.de/lang/en/nagios/check_logfiles/

  • supports regex
  • supports log rotation

To use it, you need a cfg file, this is an example for oracle databases

@searches = ({
tag => 'oraalerts',
options => 'sticky=28800',
logfile => '/u01/app/oracle/diag/rdbms/davmdkp/DAVMDKP1/trace/alert_DAVMDKP1.log',
criticalpatterns => [
'ORA\-0*204[^\d]', # error in reading control file
'ORA\-0*206[^\d]', # error in writing control file
'ORA\-0*210[^\d]', # cannot open control file
'ORA\-0*257[^\d]', # archiver is stuck
'ORA\-0*333[^\d]', # redo log read error
'ORA\-0*345[^\d]', # redo log write error
'ORA\-0*4[4-7][0-9][^\d]',# ORA-0440 - ORA-0485 background process failure
'ORA\-0*48[0-5][^\d]',
'ORA\-0*6[0-3][0-9][^\d]',# ORA-6000 - ORA-0639 internal errors
'ORA\-0*1114[^\d]', # datafile I/O write error
'ORA\-0*1115[^\d]', # datafile I/O read error
'ORA\-0*1116[^\d]', # cannot open datafile
'ORA\-0*1118[^\d]', # cannot add a data file
'ORA\-0*1122[^\d]', # database file 16 failed verification check
'ORA\-0*1171[^\d]', # datafile 16 going offline due to error advancing checkpoint
'ORA\-0*1201[^\d]', # file 16 header failed to write correctly
'ORA\-0*1208[^\d]', # data file is an old version - not accessing current version
'ORA\-0*1578[^\d]', # data block corruption
'ORA\-0*1135[^\d]', # file accessed for query is offline
'ORA\-0*1547[^\d]', # tablespace is full
'ORA\-0*1555[^\d]', # snapshot too old
'ORA\-0*1562[^\d]', # failed to extend rollback segment
'ORA\-0*162[89][^\d]', # ORA-1628 - ORA-1632 maximum extents exceeded
'ORA\-0*163[0-2][^\d]',
'ORA\-0*165[0-6][^\d]', # ORA-1650 - ORA-1656 tablespace is full
'ORA\-16014[^\d]', # log cannot be archived, no available destinations
'ORA\-16038[^\d]', # log cannot be archived
'ORA\-19502[^\d]', # write error on datafile
'ORA\-27063[^\d]', # number of bytes read/written is incorrect
'ORA\-0*4031[^\d]', # out of shared memory.
'No space left on device',
'Archival Error',
],
warningpatterns => [
'ORA\-0*3113[^\d]', # end of file on communication channel
'ORA\-0*6501[^\d]', # PL/SQL internal error
'ORA\-0*1140[^\d]', # follows WARNING: datafile #20 was not in online backup mode
'Archival stopped, error occurred. Will continue retrying',
]
});

Nagios won't create performace-data for plugin

Have a look at the development guidelines: https://nagios-plugins.org/doc/guidelines.html#AEN200

The expected format for perfdata is 'label'=value[UOM];[warn];[crit];[min];[max] which can look something like this:

PING ok - Packet loss = 0%, RTA = 0.80 ms | percent_packet_loss=0, rta=0.80

The pipe (|) character tells Nagios that the plugin output has ended and performance data starts.

Note that the above example does not specify UOM (unit of measurement, like percent), nor does it specify any warn/crit thresholds for the data, or min/max values for the graphs. These are all optional.



Related Topics



Leave a reply



Submit