Hi Tim,
Your issue remains the period vs. the comma. Imperial vs. metric if you want so...
What you want to do is adjust the script so it replaces the period (.) with a comma (,).
Look at the adjusted script below, this should help you
'Execute:
'Argument 0 = File-Path
'LegacyDiskSizeSensor.vbs "C:\path\file.txt" - alternative with UNC path: "\\server\share\path\file.txt"
Dim strPath
If WScript.Arguments.Count = 1 Then
strPath = WScript.Arguments.Item(0)
Else
Wscript.Echo "Usage: cscript LegacyDiskSizeSensor.vbs ""C:\path\file.txt"""
Wscript.Quit
End If
Dim strCapacity, strUsed
Dim objFile
Set objFile = CreateObject("Scripting.FileSystemObject").OpenTextFile(strPath,1)
Dim strLine
Do While Not objFile.AtEndOfStream
strLine = Trim(objFile.ReadLine())
If LCase(Left(strLine,Len("Capacity:"))) = LCase("Capacity:") Then
strCapacity = Trim(Replace(Replace(strLine, "Capacity:", "", 1, -1, 1), "GB", "", 1, -1, 1))
ElseIf LCase(Left(strLine,Len("Used:"))) = LCase("Used:") Then
strUsed = Trim(Replace(Replace(strLine, "Used:", "", 1, -1, 1), "%", "", 1, -1, 1))
End If
Loop
objFile.Close
Set objFile = Nothing
strCapacity = Trim(Replace(strCapacity, ".", ",", 1, -1, 1))
strUsed = Trim(Replace(strUsed, ".", ",", 1, -1, 1))
Dim strCalculatedFree
strCalculatedFree = -1 'default is -1 - this would indicate the calculation wasn't possilble due to non numeric values
If IsNumeric(strCapacity) And IsNumeric(strUsed) Then
If strUsed <= 0 Then 'avoiding multiplaction with 0
strCalculatedFree = strCapacity
Else
strCalculatedFree = strCapacity * (strUsed / 100)
End If
strCalculatedFree = Round(strCalculatedFree,0)
End If
WScript.echo "<prtg>"
WScript.echo "<result>"
WScript.echo "<channel>Capacity</channel><value>" & strCapacity & "</value>"
WScript.echo "</result>"
WScript.echo "<result>"
WScript.echo "<channel>Used</channel><value>" & strUsed & "</value>"
WScript.echo "</result>"
WScript.echo "<result>"
WScript.echo "<channel>Calculated free</channel><value>" & strCalculatedFree & "</value>"
WScript.echo "</result>"
WScript.echo "</prtg>"
What I changed is the blog starting at line 30 (I highly recommend using Notepad++ to edit those scripts, it has a pretty good syntax highlighting feature).
If Instr(1, strCapacity, ".", 1) Then
strCapacity = Left(strCapacity,Instr(1, strCapacity, ".", 1)-1)
End If
If Instr(1, strCapacity, ",", 1) Then
strCapacity = Left(strCapacity,Instr(1, strCapacity, ",", 1)-1)
End If
If Instr(1, strUsed, ".", 1) Then
strUsed = Left(strUsed,Instr(1, strUsed, ".", 1)-1)
End If
If Instr(1, strUsed, ",", 1) Then
strUsed = Left(strUsed,Instr(1, strUsed, ",", 1)-1)
End If
was replaced with
strCapacity = Trim(Replace(strCapacity, ".", ",", 1, -1, 1))
strUsed = Trim(Replace(strUsed, ".", ",", 1, -1, 1))
This will actually replace the period with a comma - so that it matches the number settings of your local system. This is a pretty common issue. I grew up in Germany with a comma on my number block and had to adjust while living in the USA to the period. The advantage over here is that I can type e.g. IP addresses way quicker and a lot of coding on the US keyboard is easier due to less key strokes needed - in any case - those are the quirks of IT, lol.
Hope this helps you :-)
Florian Rossmark
www.it-admins.com
Add comment