Recently I had to monitor a backup log file. If the modification time stamp of the log file was later than at a certain time then SCOM should fire a warning. In my case if the file was modified later than at 05:00 o’clock (24-hour time notation) an alert should occur. There was no characteristic inside the file to determine the state of the backup nor should it be to complex to fulfill this task.
My approach was to create a timed two state monitor using a vbscript.
Give this monitor an appropriate name and target. Don’t enable the monitor yet.
Run every 15 minutes or even less
Here you insert the script
Script:
**********************************
Dim oArgs
Set oArgs = WScript.Arguments
Dim oAPI
Set oAPI = CreateObject(“MOM.ScriptAPI”)
Dim objFile
Dim ValueToReturn
Dim oFso
Dim oFile
Dim oBag
Dim Filename
Dim DateLastModified
Set oFso = CreateObject(“Scripting.FileSystemObject”)
‘Path to the log file
Filename = “C:\1\log.txt”
If (oFso.FileExists(Filename)) Then
Set objFile = oFso.GetFile(Filename)
DateLastModified= objFile.DateLastModified
‘Here we just pick the hours of the time stamp. Since we are having 24-hour time notation it is easy to pick the hour-part e.g. 05:00 it would pick the “5” or in 16:00 it would pick the “16”.
If DatePart(“h”,objFile.DateLastModified) < 5 Then
ValueToReturn = “OK”
Else
ValueToReturn = “FAILED”
End If
Else
‘Here you just could pick the return value 9999 if an error occurs e.g. for use in an three state monitor
ValueToReturn = 9999
End If
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue(“Status”,ValueToReturn)
Call oBag.AddValue(“Filename”,Filename)
Call oBag.AddValue(“DateLastModified”,DateLastModified)
Call oAPI.Return(oBag)
**********************************
Next build the unhealthy expression
Then build the healthy expression
Configure the health status of the object
Finally configure the alert here I just put the variables inside. of course you could add some more text into the alert description š
Now as a last step you just have to set an override for the server object or group
Set the status enabled to true
Hi,
Is there a way I could use this script to monitor a file that should be modified every five minutes?
Thanks in advance
Steve.
Hi Steve
As I understand you want to raise an alert if the file has not been modified for more than 5 minutes. You just need to change the if condition to…
If DateDiff(“n”, objFile.DateLastModified, Now) < 5 then
OK?
Regards,
Stefan
Hi Stefan,
I thought so but if I remove the bottom section:
End If
Else
ValueToReturn = 9999
The script then errors, sorry to be a noob!
Regards
Stephen Turner
Hi Stephen
Ok if you want to remove the ValueToReturn=9999 part and just use “OK” and “FAILED”…
Here the part you are asking:
…
If (oFso.FileExists(Filename)) Then
Set objFile = oFso.GetFile(Filename)
DateLastModified = objFile.DateLastModified
If DateDiff(“n”, objFile.DateLastModified, Now) < 5 Then
ValueToReturn = "OK"
Else
ValueToReturn = "FAILED"
End If
End If
…
Ok?
Regards,
Stefan
Awesome, Thank you very much.
Must learn some VB skills!
Regards
Stephen Turner
IT Systems Engineer
Interserve PLC
Services, maintenance and building
Website: http://www.interserve.com
Tel: 0121 524 8917
Mob: 07990 800099
Fax: 0845 838 5998
Email: Stephen.turner@interserve.com
Hi
Great. You are very welcome!
Regards,
Stefan
Hi,
Sorry to be a pain (again) but the script isn’t working as intended. It’s saying the monitor is critical when the minutes in the hour are less than 5 rather that if the file was modified less than 5 minutes ago.
Any help would be appreciated.
Hi Stephen
I am a bit confused what your requirements are but you could try to change the operator “<" on the line here "If DateDiff(ānā, objFile.DateLastModified, Now) < 5 Then” to “>” (greather than). And see if it is o.k.
Regards,
Stefan
Hi,
The Query is comparing the time stamp from file last modified date and today’s date, so it would always raise false alaram where file is not modified for days.
Can you please provide the script where it stores last modified date always and compare it with current time stamp of the file, if there is any change in the time stamp of the file current time stamp with last modified stamp.It should raise alert.
Regards,
Kiran Kumar
HI Stefan,
I need to monitor an xml file to alert only if the file was not modifies in last 24 hours.
This file gets modified a couple of times in a day, but if it not modified for more than 24 hours , i wish to get alerted for that.
Any advice on how i can accomplish that.
I hope you are doing well.. Still looking to find a way around this request
Hi Stefan
I have a service that creates multiple log files in a folder. Sometimes the service crashes, but you can’t realy see if it’s working ore not. The only way is to check the logfiles.
Is it possible to do a script, witch generates an alert, when the modified date of a folder is older than 2 hours?
Thanks in advance
This script is really excellent and it is the first step to locate the files modified. Now is it possible to locate the modification itself within the file?
Thanks,
DOm
What is the Parameter Name : and why you put that name in it
Hi
Not sure what you mean, sorry.
Cheers,
Stefan
This was exactly what I needed, thank you.
Hi Stefan,
My requirement is to monitor the log file for a servers; trigger an alert when any modification occurs on the file.
Could you please help on that
Thanks in advance.