# PRTG Custom Sensor to read AVm Frit Box using TG-ß64 # # 20150323 Ver 1.0 Initial Version # # param ( [string]$fritzip="fritz.box", # IP-Address [string]$fritzpass = "" # Password ) #set-psdebug -strict # enforce strict variable checking write-host "Start prtg-fritz" (get-date).tostring() write-host "Initializing PRTG Result variable" [string]$prtgresult="" $prtgresult+="`r`n" $prtgresult+="`r`n" [bool]$errorfound = $false write-host ("Parametercheck: fritzIP :" + $fritzip) $webclient=New-Object System.Net.WebClient $webclient.Encoding=[System.Text.Encoding]::UTF8 try { write-host (" Loading TR064 from:" + $fritzip) $webclient.Headers.Set("Content-Type", 'text/xml; charset="utf-8"') $webclient.Headers.Set("SOAPACTION", 'urn:dslforum-org:service:DeviceInfo:1#GetSecurityPort') $query=' ' $webresult = [xml]$webclient.UploadString("http://"+$fritzip+":49000/upnp/control/deviceinfo",$query) $port=$webresult.Envelope.Body.GetSecurityPortResponse.NewSecurityPort write-host "Found TR-064 Port:" $port } catch { write-host "Error using HTTP: unable to get TR-064 Port" $prtgresult+=" 2`r`n" $prtgresult+=" Unable to get TR-064 Port`r`n" $errorfound = $true } if (!$errorfound) { try { $webclient.Headers.Set("Content-Type", 'text/xml; charset="utf-8"') $webclient.Headers.Set("SOAPACTION", 'urn:dslforum-org:service:WANDSLInterfaceConfig:1#GetInfo') $query=' ' $webclient.Credentials=New-Object System.Net.NetworkCredential("dslf-config",$fritzpass) [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} $webresult = [xml]$webclient.UploadString("https://"+$fritzip+":"+$port+"/upnp/control/wandslifconfig1",$query) $webresult.Envelope.Body.GetInfoResponse } catch { write-host "Error getting GetInfo" $prtgresult+=" 2`r`n" $prtgresult+=" Error getting GetInfo`r`n" $errorfound = $true } } if (!$errorfound) { write-host "Parsing webresult" $properties = ($webresult.Envelope.Body.GetInfoResponse | gm -MemberType Property) foreach ($property in $properties) { write-host " Processing Datapoint :" $property.name $prtgresult+=" `r`n" $prtgresult+=" "+$property.name+"`r`n" #$prtgresult+=" "+$datapoint.Einheit+"`r`n" $prtgresult+=" "+$webresult.Envelope.Body.GetInfoResponse.($property.name)+"`r`n" $prtgresult+=" 0`r`n" $prtgresult+=" Absolute`r`n" $prtgresult+=" `r`n" } } if (!$errorfound) { try { $webclient.Headers.Set("Content-Type", 'text/xml; charset="utf-8"') $webclient.Headers.Set("SOAPACTION", 'urn:dslforum-org:service:WANDSLInterfaceConfig:1#GetStatisticsTotal') $query=' ' $webclient.Credentials=New-Object System.Net.NetworkCredential("dslf-config",$fritzpass) [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} $webresult = [xml]$webclient.UploadString("https://"+$fritzip+":"+$port+"/upnp/control/wandslifconfig1",$query) $webresult.Envelope.Body.GetStatisticsTotalResponse } catch { write-host "Error getting GetStatisticsTotal" $prtgresult+=" 2`r`n" $prtgresult+=" Error getting GetStatisticsTotal`r`n" $errorfound = $true } } if (!$errorfound) { write-host "Parsing webresult" $properties = ($webresult.Envelope.Body.GetStatisticsTotalResponse | gm -MemberType Property) foreach ($property in $properties) { write-host " Processing Datapoint :" $property.name $prtgresult+=" `r`n" $prtgresult+=" "+$property.name+"`r`n" #$prtgresult+=" "+$datapoint.Einheit+"`r`n" $prtgresult+=" "+$webresult.Envelope.Body.GetStatisticsTotalResponse.($property.name)+"`r`n" $prtgresult+=" 0`r`n" $prtgresult+=" Difference`r`n" $prtgresult+=" `r`n" } } $prtgresult+="" if ($errorfound) { write-host "Error Found. Ending with EXIT Code" ([xml]$prtgresult).prtg.error } write-host "Sending PRTGRESULT to STDOUT" $prtgresult if ($errorfound) { exit ([xml]$prtgresult).prtg.error }