Hi Tim,
Didn't even realize it - looks like you got quite hooked up and start to monitor out of the box - very nice!
Since the log you posted first is different from the real log - there of course was a mistake in the script - so I had to account for the differences and adjusted the script a bit...
Dim sReturnValue
sReturnValue = -2222222 '-2222222 = generic error / high value cause the datediff could give you negative values in theory
Dim sFile
sFile = WScript.Arguments.Item(0)
Dim bolFileExists
bolFileExists = False
Dim strLine1
Dim strLine2
Dim objFS
Set objFS = CreateObject("Scripting.FileSystemObject")
If objFS.FileExists(sFile) Then
bolFileExists = True
Dim strLine
Dim intLineCount
Dim objTS
Set objTS = objFS.OpenTextFile(sFile, 1)
intLineCount = 0
Do While Not objTS.AtEndOfStream
strLine = objTS.ReadLine()
If InStr(1, strLine, "First File:", 1) > 0 Then
intLineCount = intLineCount + 1
strLine1 = strLine
ElseIf InStr(1, strLine, "Last File:", 1) > 0 Then
intLineCount = intLineCount + 1
strLine2 = strLine
End if
If intLineCount = 2 Then
Exit Do 'ignore everything after linecount = 2 - meaning both lines have been found
End If
Loop
objTS.Close
Set objTS = Nothing
End If
Set objFS = Nothing
If bolFileExists Then
If Len(strLine1) > 0 And Len(strLine2) > 0 Then
strLine1 = Replace(strLine1, "First File:", "", 1, -1, 1)
strLine2 = Replace(strLine2, "Last File:", "", 1, -1, 1)
If UBound(Split(strLine1, "-")) = 1 And UBound(Split(strLine2, "-")) = 1 Then
strLine1 = Trim(Split(strLine1,"-")(1)) & " " & Trim(Split(strLine1,"-")(0)) 'first date then time
strLine2 = Trim(Split(strLine2,"-")(1)) & " " & Trim(Split(strLine2,"-")(0)) 'first date then time
If Len(strLine1) > 0 And Len(strLine2) > 0 Then
If IsDate(strLine1) And IsDate(strLine2) Then
sReturnValue = DateDiff("h", strLine1, strLine2) 'h = hourly / n = Minute
Else
sReturnValue = -5555555 '-5555555 = File Content Error - no date value! / high value cause the datediff could give you negative values in theory
End If
Else
sReturnValue = -4444444 '-4444444 = File Content Error in regards to the date/time values / high value cause the datediff could give you negative values in theory
End If
Else
sReturnValue = -6666666 '-6666666 = File Content Error - no time - date value found / high value cause the datediff could give you negative values in theory
End If
Else
sReturnValue = -3333333 '-3333333 = File Content Error / high value cause the datediff could give you negative values in theory
End If
Else
sReturnValue = -1111111 '-1111111 = File not found error / high value cause the datediff could give you negative values in theory
End If
WScript.echo "<prtg>"
WScript.echo "<result>"
WScript.echo "<channel>DateDiffFromLog</channel><value>" & sReturnValue & "</value>"
WScript.echo "</result>"
WScript.echo "</prtg>"
As you can see - now I search in the whole output file for the FIRST FILE and LAST FILE till I found both then I exit the loop and close the file.
Further is there an unexpected value "N / A" in your log file (not available) - this was not accounted for and is another reason you got an error - I changed this and make sure the FIRST FILE and LAST FILE value include a "-" so the error that was raised there is obsolete as well - but it added an error -6666666 - what means that the script found a not valid output format - you might wanna change the error number or play further with it...
Alternative you could adjust the output area starting at line 66 like this:
Dim strChannelTwo
WScript.echo "<prtg>"
WScript.echo "<result>"
WScript.echo "<channel>DateDiffFromLog</channel><value>" & sReturnValue & "</value>"
strChannelTwo = "<channel>InvalidTimeDateValue</channel><value>"
If sReturnValue = -6666666 Then
strChannelTwo = strChannelTwo & 1 '1 = in error / true state - use channel limits in PRTG and raise error if not 0 so you know more...
Else
strChannelTwo = strChannelTwo & 0 '0 = no error
End If
strChannelTwo = strChannelTwo & "</value>"
WScript.echo strChannelTwo
WScript.echo "</result>"
WScript.echo "</prtg>"
This would specifically catch the not a time-date value error - and determine it a bit more...
Theoretically you could add a TEXT output as well and show it in the status for the sensor in PRTG assuming it helps...
'Dim strChannelTwo
Dim strText
WScript.echo "<prtg>"
WScript.echo "<result>"
WScript.echo "<channel>DateDiffFromLog</channel><value>" & sReturnValue & "</value>"
' strChannelTwo = "<channel>InvalidTimeDateValue</channel><value>"
' If sReturnValue = -6666666 Then
' strChannelTwo = strChannelTwo & 1 '1 = in error / true state - use channel limits in PRTG and raise error if not 0 so you know more...
' Else
' strChannelTwo = strChannelTwo & 0 '0 = no error
' End If
' strChannelTwo = strChannelTwo & "</value>"
' WScript.echo strChannelTwo
WScript.echo "</result>"
strText = "<text>"
Select Case sReturnValue
Case -1111111
strText = strText & "File not found error"
Case -2222222
strText = strText & "script - generic error"
Case -3333333
strText = strText & "File Content Error"
Case -4444444
strText = strText & "File Content Error in regards to the date/time values"
Case -5555555
strText = strText & "File Content Error - no date value!"
Case -6666666
strText = strText & "File Content Error - no time - date value found"
Case Else
strText = strText & "valid date values found"
End Select
strText = strText & "</text>"
Wscript.Echo strText
WScript.echo "</prtg>"
Hope this helps :-)
Regards
Florian Rossmark
www.it-admins.com
Add comment