Regex query - todays date?

What would be the way to configure a text log file with the condition using regex for only monitoring todays dates log file?

Such as 20211216.log

Or can we say only look at any log files from today and not from before?

Can you please describe what exactly you are trying to achieve in a bit more detail?

Regex itself does not know what the current date is, so matching the current date can’t be done in regex alone. If you were to write a bash script as a local check however, you could use a different approach. Or maybe for your specific case, a completely different approach would be better, that’s hard to say without knowing what you’re trying to do.

1 Like

I’m trying to monitor log files in a directory on a server when specific text appears. I’ve used the ‘Text LogFiles’ rule before baked into the agent and then forwarded these to event console.
However because these files are named with todays date each day I don’t know how to do this, with the current rule.
It would be good if there was an option to select the date modified on the file or something etc


The first thing that comes to my mind would be a cron job that


  • either runs shortly after midnight (if that’s when the new log is being generated) and does something like ln -fs /logdir/$(date +%Y%m%d).log /logdir/latest.log
  • or runs periodically (e.g. */5) and does something like ln -fs $(ls -1t /logdir/2*.log | head -n 1) /logdir/latest.log


to make a symlink called latest.log pointing to today’s log file. You can then use the symlink’s name for monitoring.
These examples assume your server runs linux, but the same idea can probably also be realized on windows.

2 Likes

You can use glob “/
/*.log” or the regex argument`regex='\d\d\d\d\d\d\d\d.log$``

https://ideas.checkmk.com/suggestions/349647/improve-handling-of-files-with-date-or-numbers-in-logwatch-event-console-forward

Why did you paste this when it wasn’t accepted into planning?

I don’t understand how you’re example works. The date changes every day, I need to monitor only the log file that relates to each new day.

For as far as i have looked into this matter:

What you are after (if i interpret your desire correctly) is some sort of ability in the config file of logwatch (logwatch.cfg) to allow macro’s like $DATE$ to facilitate your wish.

Unfortunately there is no such code in the plugin.

Next to if it were there the difficulty in this is that date formats can vary a lot, so the resulting filename could have a format not supported by a macro (and there is a lot of formats possible!)

To get around this the suggestion made by @Jay2k1 seems (to me) the most logical approach.

  • Glowsome

Monitoring the log file on the server and forwarding the events to Checkmk is not the problem. As soon as a new log file with a new date appears, it is automatically monitored.

The problems start on the Checkmk side, depending on how you want to handle the events. When using the default log check or the Logwatch Event Console Forwarding Rule with the ‘Monitor forwarded log files’ option enabled, Checkmk creates a new service for each log file, because each file is a different log file from Checkmk’s point of view.

If you use Logwatch Event Console Forwarding without the Monitor option, Checkmk will simply forward all events of all Logs to the EC, where they can be processed accordingly.

Not planned only means that it is not currently being considered. If the idea gets enough votes, it shows that customers need thes Feature and Checkmk maybe reconsiders its decision. That’s the reason why I’ve linked it here. Unfortunately, Checkmk prefers to focus on new features rather than solving such old and long-standing problem.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.