File monitoring

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

File monitoring

Post by RebeccaIlene »

Hi Team,

We are looking to monitor the contents of a file which arrives once a day.

The file name will have the date in between "yyyymmdd.hhmm".

I have been looking for a batch file to help generate this patter so that we can add it to our existing check_logfiles plugin but haven't been successful.

Can someone please help with this?
User avatar
jbrunkow
Posts: 441
Joined: Fri Mar 13, 2020 10:45 am

Re: File monitoring

Post by jbrunkow »

This might actually be easier with bash than with batch...

Code: Select all

#!/bin/bash
file_name=$(date +%Y%m%d.%H%M)
if [ -f $file_name ]; then
  echo "$file_name exists!"
else
  echo "$file_name does not exist..."
fi
This is because the date command native to Unix derived systems have a built in formatting function, and that of Windows does not.

If you wanted to write the equivalent of that script for Windows, you would probably have to set each part of that date as a variable, and then reconstitute it as a new one to get it in that exact format.
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: File monitoring

Post by RebeccaIlene »

Yes, I am looking to monitor this on Windows. Is there a powershell script that can help?
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: File monitoring

Post by lmiltchev »

Writing custom scripts is out of scope of Nagios support. Having said that, you could probably use something like this:

Code: Select all

$myfile = get-date -format "yyyymmdd.hhmm"
New-Item -Path "c:\TEMP" -Name "$myfile" -ItemType "file" -Value "This is a test."
This is just to get you started. Adjust the path, and the value to your liking. You could use parameters instead of hard-coded values, etc. Again, this is out of scope of support.

For more information on adding new items via PS, review Microsoft documentation here:

https://docs.microsoft.com/en-us/powers ... wershell-7
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked