Wildcard file name for checking log files

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
RebeccaIlene
Posts: 164
Joined: Tue Apr 02, 2019 8:38 pm

Wildcard file name for checking log files

Post by RebeccaIlene »

Hi team,

We have a requirement to check logs from a file where the file name changes based on the date of generation.

We have a plugin check_logfiles.exe which reads the log file to find if any error messages exit.

However, this only supports files with a definite name.

Can you please help or suggest a better plugin or what can we change in the current plugin to get it to pickup files with wildcard in the name?

Regards,
Rebecca Murray
RebeccaIlene
Posts: 164
Joined: Tue Apr 02, 2019 8:38 pm

Re: Wildcard file name for checking log files

Post by RebeccaIlene »

Hi Team,

have attached the plugin that we are currently using.
Please suggest on this.

Regards,
Rebecca
You do not have the required permissions to view the files attached to this post.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Wildcard file name for checking log files

Post by scottwilkerson »

This is not our plugin but the help can be found here
https://labs.consol.de/nagios/check_logfiles/

I think the only way to di it is with a configfile option, we had a thread similar about 6 years ago where something similar was able to be accomplished in a config file
https://support.nagios.com/forum/viewto ... =7&t=29193
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
User avatar
jdunitz
Posts: 235
Joined: Wed Feb 05, 2020 2:50 pm

Re: Wildcard file name for checking log files

Post by jdunitz »

Hello Rebecca!

What might work for you is to write a batch script on your Windows server that wraps the check_logfiles.exe program and passes the current filename to it, kind of like so:

Code: Select all

set  /a DT = 20200212
echo date is %DT%
c:\Users\Rebecca\check_logfiles.exe --logfile logfile%DT%.txt
In my example, I'm just hardcoding today's date, but of course in your environment, you'll need to calculate the date and put it into the format your logfiles are actually in.

This page might have some good info on how to wrangle date formats in batch files:
https://www.tutorialspoint.com/batch_sc ... e_time.htm

Once you've written a batch script that does the right thing, have your plugin call that instead of the check_logfiles command directly.


Hope that helps!
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
RebeccaIlene
Posts: 164
Joined: Tue Apr 02, 2019 8:38 pm

Re: Wildcard file name for checking log files

Post by RebeccaIlene »

Thank you so much for the suggestions! :)

unfortunately, this does not solve the entire problem.

The file names comes with a set of random five digits with an underscore before and after the date format.

For example: 768902_14022020_86720_test.txt

In this case as the numbers do not have a pattern we would still need to use a wildcard name.

Can you please suggest what we can do in this case?

Regards,

Rebecca Murray
User avatar
jdunitz
Posts: 235
Joined: Wed Feb 05, 2020 2:50 pm

Re: Wildcard file name for checking log files

Post by jdunitz »

In that case, you're going to need to write a slightly more complicated script in a language that can handle two wildcards, because I don't think a bat file can do that. Cygwin or powershell should be able to handle that. The idea is the same, you're just writing a wrapper script that can figure out the filename and call your log checker program against it.

You might be able to get what you want in a bat file by trying to pass the filename in with

Code: Select all

dir /b | find "20200214"
...but someone with more expertise in bat files than I have would have to chime in here with the specifics.

As a shell script in cygwin, it's super simple:

Code: Select all

#!/bin/sh

DT=`date +%Y%m%d`
LOGFILE=`ls logfile_*_*_*.log | grep $DT`
/cygdrive/c/Users/Rebecca/check_logfiles.exe --logfile $LOGFILE

This is a bit beyond the scope of a Nagios-specific question, but I hope I've helped anyway.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked