stephanlinke

[PRTG] Get Limits

Aug 17th, 2015
528
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $prtghost="<your-prtg-host>"
  2. $username="<your-prtg-user>";
  3. $passhash="<your-prtg-users-passhash>" # can be obtained from the accoutn configuration
  4. $Sensors = ((Invoke-WebRequest -URI "http://$($prtghost)/api/table.json?content=sensors&output=json&columns=objid,device,sensor&username=$($username)&passhash=$($passhash)").Content | ConvertFrom-Json)
  5. $Devices = ((Invoke-WebRequest -URI "http://$($prtghost)/api/table.json?content=devices&output=json&columns=objid,device&username=$($username)&passhash=$($passhash)").Content | ConvertFrom-Json)
  6.  
  7. Write-Output "sep=;"
  8. Write-Output "DeviceID;Device;Sensor;SensorID;Channel;ChannelID;LowerWarningLimit;LowerErrorLimit;UpperWarningLimit;UpperErrorLimit"
  9. Foreach($Device in $Devices.devices){
  10.  
  11.     $Sensors = ((Invoke-WebRequest -URI "http://$($prtghost)/api/table.json?content=sensors&output=json&id=$($Device.objid)&columns=objid,device,sensor&username=$($username)&passhash=$($passhash)").Content | ConvertFrom-Json)
  12.  
  13.     Foreach($Sensor in $Sensors.sensors){
  14.  
  15.         $Channels = ((Invoke-WebRequest -URI "http://$($prtghost)/api/table.json?content=channels&output=json&columns=name,lastvalue_,objid&id=$($sensor.objid)&username=$($username)&passhash=$($passhash)").Content | ConvertFrom-Json);
  16.  
  17.         Foreach($Channel in $Channels.channels){
  18.             $ChannelSettings = (Invoke-WebRequest -Uri "http://$($prtghost)/controls/channeledit.htm?_hjax=true&id=$($Sensor.objid)&username=$($username)&passhash=$($passhash)&channel=$($Channel.objid)");
  19.             if(($channel.objid -eq -4) -or $Channel.name -eq "Execution Time"){ continue;}
  20.             $LowerWarningLimit = $ChannelSettings.InputFields.FindById("limitminwarning_$($Channel.objid)").value
  21.             $LowerErrorLimit = $ChannelSettings.InputFields.FindById("limitminerror_$($Channel.objid)").value
  22.             $UpperWarningLimit = $ChannelSettings.InputFields.FindById("limitmaxwarning_$($Channel.objid)").value
  23.             $UpperErrorLimit = $ChannelSettings.InputFields.FindById("limitmaxerror_$($Channel.objid)").value
  24.  
  25.             Write-Output ("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9}" -f $Device.device,$Device.objid,$Sensor.sensor,$Sensor.objid,$Channel.name,$Channel.objid,$LowerWarningLimit,$LowerErrorLimit,$UpperWarningLimit,$UpperErrorLimit)
  26.         }
  27.     }
  28. }
RAW Paste Data