Hi, I have a problem with some Custom EXE/XML sensor. I need to measure load time and bytes received for some web page, but the trick is, that every day I need to use other URL - so I can't just use typical HTTP Advanced Sensor and I wrote some custom sensor in Powershell that should return data I need. The code is as follow:
First I build the proper URL:
[string]$IP = "x.x.x.x" [string]$Data = [string]((Get-Date).AddDays(-1)).Year+"-"+[string]((Get-Date).AddDays(-1)).Month+"-"+[string]((Get-Date).AddDays(-1)).Day $URL = "http://$IP/...........&UpdateDate=$Data" Then I run commands to get page load time, status and data size: $ResponseTime = Measure-Command {$WebParam = Invoke-WebRequest -Uri $URL -DisableKeepAlive | Select StatusCode, RawContentLength} $ResponseTimeMS = [math]::Round($ResponseTime.TotalMilliseconds) $BytesReceived = $WebParam.RawContentLength $StatusCode = $WebParam.StatusCode And finally I build output for PRTG: Write-Host "<prtg>" "<result>" "<channel>Response Time</channel>" "<value>$ResponseTimeMS</value>" "<Unit>miliseconds</Unit>" "<LimitMode>0</LimitMode>" "<LimitMaxError>0</LimitMaxError>" "<ShowChart>1</ShowChart>" "<ShowTable>1</ShowTable>" "</result>" "<result>" "<channel>Bytes Received</channel>" "<value>$BytesReceived</value>" "<Unit>bytes</Unit>" "<LimitMode>0</LimitMode>" "<LimitMaxError>0</LimitMaxError>" "<ShowChart>1</ShowChart>" "<ShowTable>1</ShowTable>" "</result>" "<result>" "<channel>Status Code</channel>" "<value>$StatusCode</value>" "<Unit>status</Unit>" "<LimitMode>0</LimitMode>" "<LimitMaxError>0</LimitMaxError>" "<ShowChart>1</ShowChart>" "<ShowTable>1</ShowTable>" "</result>" "</prtg>"
Everything works perfect when I run sensor directly from the server - it shows proper values, etc. But when I run it from the sensor, it shows strange things - for example StatusCode and BytesReceived are always 0, ResponseTime is definitiv wrong as well. It looks like it actually doesn't ask proper URL, but I have no idea what can be wrong - it's simple code, without remoting, variables in awkward format, etc. Could you take a look and help me with it? Custom EXE sensors are very powerful but because of such problems are sometimes very unintuitive :(
Thanks Marcin
Add comment