I use vbscript and my code is that:
strComputer = "127.0.0.1"
' Leave User and Password blank for local machine
strUser = ""
strPassword = ""
strNamespace = "root/cimv2"
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objLocator.ConnectServer(strComputer,strNamespace,strUser,strPassword)
Set objTimeZone = objWMIService.ExecQuery ("SELECT * FROM Win32_TimeZone")
For Each colTimeZone in objTimeZone
strBias = colTimeZone.Bias
strStandardname = colTimeZone.Standardname
Next
wscript.echo "<?xml version=""1.0"" encoding=""UTF-8"" ?>"
wscript.echo "<prtg>"
wscript.echo "<result>"
wscript.echo "<channle>" & strBias & "</channel>"
wscript.echo "<value>test123</value>"
wscript.echo "</result>"
wscript.echo "<result>"
wscript.echo "<channle>" & strStandardname & "</channel>"
wscript.echo "<value>test234</value>"
wscript.echo "</result></prtg>"
wscript.quit("0")
but it return error, the error message is
| "Response not wellformed: "(<?xml version="1.0" encoding="UTF-8" ?> <prtg> <result> <channle>-480</channel> <value>test123</value> </result> <result> <channle>Pacific Standard Time</channel> <value>test234</value> </result></prtg> )" (code: PE132)" |
what wrong with my code?
Article Comments
Alternative you could use the WMI sensors with custom strings or custom numeric values to accomplish the same and not having a specific VBscript wrapped around it.
If you want to have text in your output, there is a <text> tag available for XML - but be aware - the text is not per result, it is a per script tag - so only one text-output in your whole XML response.
You further have some kind of a flaw in your VBscript here:
For Each colTimeZone in objTimeZone strBias = colTimeZone.Bias strStandardname = colTimeZone.Standardname Next
This will run through all objTimeZone objects / I am not clear if there is a possible collection - but if there is - so more then one "row" in your WMI query, you would only see the final result / row data.
Depending on what you want to accomplish, you might need to adjust this - cause every colTimeZone will overwrite your values in strBias and strStandardname.
Regards
Florian Rossmark
Jul, 2018 - Permalink
Hello a23554,
thank you for your Knowledge base Post.
There are two issues in the output of your script, please check (I've formatted the output accordingly for increased legibility):
For more information, see PRTG Manual: Custom Sensors
Best Regards,
Luciano Lingnau [Paessler Support]
Jul, 2016 - Permalink