Plugin check existing log and date check

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
welbp00
Posts: 50
Joined: Fri Mar 08, 2019 5:48 am

Plugin check existing log and date check

Post 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.
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: Plugin check existing log and date check

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked