Page 1 of 1

Plugin check existing log and date check

Posted: Tue Apr 16, 2019 3:16 am
by welbp00
Hello,
i am looking for a plugin wich checks the existing of a specifick log-fle (cp_init.20190414.log), and does a check if the date in the name of the file, is younger than a week from today.

Any help would be very nice. The servers are Linux redhat 7. Nagios core 4.

Thnx.

Regards Paul.

Re: Plugin check existing log and date check

Posted: Tue Apr 16, 2019 2:39 pm
by cdienger
I'm not aware of anything that will extract the date from filename and treat it as a date or number, so it looks like one would need to be created.

On a Linux system the date can be extracted with:

Code: Select all

ls cp_init.<filenamedate>.log | egrep [0-9]{8} -o
and then converted to epoch:

Code: Select all

date --date=<filenamedate> +%s
you'd then need to add 604800 seconds to the returned filenamedate and compare it to the system's current epoch time.

Here are some useful documents to help get you started on creating custom plugins:

https://assets.nagios.com/downloads/nag ... inapi.html
http://nagios-plugins.org/doc/guidelines.html
https://library.nagios.com/library/prod ... s-in-perl/
https://exchange.nagios.org/directory/T ... pt/details