A user asked about creating a trigger file that notifies an email if a log file is not changed for two days. Solutions proposed include making a custom event log entry and using the System.IO.FileSystemWatcher class. The user found a potential solution and will update the discussion with their results.
Read the entire ‘Creating a Trigger File to Check if Log File is Changed’ thread below:
I’m trying to create a trigger for a file, specifically if a log file doesn’t change in two days, we will get an email. I can see the folder alert, but nothing for files. does this exist? The application in question does not write to the Windows log or stop the service if it stops working, it only stops writing to the log file. Dumb, I know, but, you know…
The folder advanced trigger is for folder level columns in the console. https://support.controlup.com/docs/folders-view-actions
For triggering on a file you would need to think outside the box. Something to check the file via scripts and then use a scheduled trigger (limited to as low as 5 minutes) to check the log and write an event to the event log if something is found wrong.You can then create a second trigger to alert on this windows event you created if needed.That is a very interesting take. I’ll be researching this. Thanks!
Creating a custom event log entry is very easy.
“`New-EventLog –LogName Application –Source "APPLICATION ACTING A FOOL"
Write-EventLog –LogName Application –Source "APPLICATION ACTING A FOOL" –EntryType Error –EventID 999 –Message "APPLICATION ACTING A FOOL and its log file unchanged for three days. Restart the service. If this doesn’t work, perform the steps in KB 150: https://LINK_TO_HELPDESK_SOLUTIONS"“`Getting the modified date of the log file & triggering the creation of said event log entry has proven to be more difficult.I’m a VB.net guy myself so I can’t help much with the PowerShell stuff. I have used a file system watcher in VB before. Its just a .net component so you should be able to consume it with powershell. Maybe it will help? https://devblogs.microsoft.com/powershell-community/a-reusable-file-system-event-watcher-for-powershell/
You could use a Scheduled Trigger that runs every five minutes, as Landon suggested. Checking the file’s LastWriteTimeproperty would be a simple approach.
Something like this
$filePath = C:\myLog.txt
$lastWriteTime = (Get-Item $filePath).LastWriteTime
$currentDateTime = Get-Date
$timeDif = $currentDateTime – $lastWriteTime
if ($timeDif -ge [TimeSpan] "48:00:00") {
Send-MailMessage ….
}
Other approaches would be
- You could easily parse the timestamps from the log file if it saves timestamps
- Use the System.IO.FileSystemWatcher class in your script. You can use events such as "Changed", "Created", "Deleted", etc.
Thanks for the response.
I think I have this figured out.
I will update this with my findings and commands/configs.
Continue reading and comment on the thread ‘Creating a ControlUp Trigger to Check if Log File is Changed’. Not a member? Join Here!
Categories: All Archives, ControlUp Scripts & Triggers