cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 9

Variables in File Age Monitor Path

Jump to solution

Hi all,

We are trying to set up a file age monitor for a log file generated by an application. The log file is date-stamped (DDMMMYYYY), and so we need the file age monitor to contain variables in the file path string. I know that it accepts ${IP}, but when I try to use any of the date part variables (${DD}, ${MMM}, ${Year}) it doesn't appear to parse them.

Anyone had any luck with this, or know if there is a list of acceptable variables for the file path?

Many thanks,

   Richard

Labels (1)
0 Kudos
1 Solution

There are no variables available for date time parts, I always have had to use powershell script monitors to do dynamic file paths.

- Marc Netterfield, Github

View solution in original post

6 Replies

Not sure if this is useful but I published a simple powershell solution for creating alerts on various things including file age which I called Folder Statistics (as this is why I created it initially but can also be used for alerting). You could modify it to accept different date formats if needed: Folder Statistics

Product Manager
Product Manager

paget76  wrote:

Hi all,

We are trying to set up a file age monitor for a log file generated by an application. The log file is date-stamped (DDMMMYYYY), and so we need the file age monitor to contain variables in the file path string. I know that it accepts ${IP}, but when I try to use any of the date part variables (${DD}, ${MMM}, ${Year}) it doesn't appear to parse them.

Anyone had any luck with this, or know if there is a list of acceptable variables for the file path?

Many thanks,

   Richard

Also, have you seen Chad's variation on the file age monitor? File Age Monitor (Wildcard)

There are no variables available for date time parts, I always have had to use powershell script monitors to do dynamic file paths.

- Marc Netterfield, Github

View solution in original post

That's a right pain! I'll have to dust off the Powershell...

Thanks for the resonse, though!

Richard

0 Kudos

paget76  wrote:

That's a right pain! I'll have to dust off the Powershell...

Thanks for the resonse, though!

Richard

Do you mind sharing your powershell script here? Request to both you and mesverrum please. I'm filing an improvement request internally and would love to see what you actually end up doing here. Tracking under SAM-10075

Sure:

Script accepts parameter like: C:\Log\[dd][MMM][yyyy]_fix_*.log,5

-------------------------------------------------

param([string]$path, [int]$minutes)

# Example, change this path to the folder/file type you wish to monitor.

# Insert date replacement veriables in [].

#$path="c:\temp\Log_[yyyy][MM][dd]*.txt"

#$minutes = 15

$stat=0

$msg=""

$now = Get-Date

$path = $path.Replace('[dd]',$now.ToString('dd'))

$path = $path.Replace('[MM]',$now.ToString('MM'))

$path = $path.Replace('[Mmm]',$now.ToString('MMM'))

$path = $path.Replace('[MMM]',$now.ToString('MMM').ToUpper())

$path = $path.Replace('[yyyy]',$now.ToString('yyyy'))

try

{   

    $testTime = $(Get-Date).AddMinutes(-$minutes)

   

    $FileArray = $(Get-ChildItem $path | Where-Object { !$_.PSIsContainer -and $_.LastWriteTime -lt $testTime })

    if (($FileArray | Measure-Object).count = 0)

    {

         $stat= ($FileArray | Measure-Object).count

         $msg = "No file found over $minutes minutes old"

        foreach ($file in $FileArray)

        {

            $msg+=" " + $file + ","

        }

    }

    else

    {

        $stat= ($FileArray | Measure-Object).count

        $msg = "$stat files found older than $minutes minutes: "

        foreach ($file in $FileArray)

        {

            $msg+=" " + $file + ","

        }

    }

}

catch

{

    $stat=1

    $msg=$_.Exception.Message

}

Write-Host "Statistic: $stat"

Write-Host "Message: $msg"

exit 0