├── .gitattributes ├── .gitignore └── PRTGAdminModule.psm1 /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /PRTGAdminModule.psm1: -------------------------------------------------------------------------------- 1 | ######ignore invalid SSL Certs########## 2 | add-type @" 3 | using System.Net; 4 | using System.Security.Cryptography.X509Certificates; 5 | public class TrustAllCertsPolicy : ICertificatePolicy { 6 | public bool CheckValidationResult( 7 | ServicePoint srvPoint, X509Certificate certificate, 8 | WebRequest request, int certificateProblem) { 9 | return true; 10 | } 11 | } 12 | "@ 13 | [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy 14 | 15 | ######setup details, access related. 16 | $auth = "username=api_access&passhash=1669687025" 17 | $PRTGHost = "192.168.0.89" 18 | 19 | 20 | 21 | ############################################## 22 | ############Get-prtgSensorInGroup############# 23 | ############################################## 24 | # will return ALL sensors listed in PRTG, for a given Group (via its ID) (limited to 2500) 25 | #default is the root (ID=0) 26 | #its important to remember that a "Group" is also a device, and probe etc. 27 | #eg 28 | #Get-prtgSensorInGroup 8011 29 | 30 | function Get-prtgSensorInGroup([string]$StartingID=0) 31 | { 32 | $url = "http://$PRTGHost/api/table.xml?content=sensors&output=csvtable&columns=objid,probe,group,device,sensor,status,message,lastvalue,priority,favorite,tags&id=$StartingID&count=2500&$auth" 33 | $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 34 | 35 | convertFrom-csv $request -WarningAction SilentlyContinue 36 | } # end function 37 | 38 | 39 | 40 | 41 | ############################################## 42 | ############Get-prtgDevicesInGroup#################### 43 | ############################################## 44 | # will return ALL Devices listed in PRTG, for a given Group (via its ID) (limited to 2500) 45 | #default is the root (ID=0) 46 | #if you want to find 1 device(ID=8011), then use: Get-prtgDevicesInGroup | where {$_.ID -eq 8011} 47 | #anther example, seaching for an IP 48 | #Get-prtgDevicesInGroup | where {$_.host -eq "10.81.8.36"} 49 | 50 | #you may also want to return many devices, eg 51 | #Get-prtgDevicesInGroup | where {$_.host -like "10.81.8.*"} 52 | 53 | function Get-prtgDevicesInGroup ([string]$StartingID=0) 54 | { 55 | #if ($script:devicesCached -eq $false){ 56 | $url = "http://$PRTGHost/api/table.xml?content=devices&output=csvtable&columns=objid,probe,groupid,device,host,downsens,partialdownsens,downacksens,upsens,warnsens,pausedsens,unusualsens,undefinedsens,tags,comments&id=$StartingID&count=2500&$auth" 57 | $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 58 | $getprtgDeviceRet = convertFrom-csv ($request.content) -WarningAction SilentlyContinue 59 | $getprtgDeviceRet 60 | # write-host "got devices from website..." 61 | # $script:devicesCached = $true 62 | #}else{ 63 | # write-host "got groups from cache..." 64 | # $getprtgDeviceRet 65 | #} 66 | } # end function 67 | 68 | 69 | ############################################## 70 | ############Get-prtgGroupsInGroup#################### 71 | ############################################## 72 | # will return ALL Groups listed in PRTG, for a given Group (via its ID) (limited to 2500) 73 | #default is the root (ID=0) 74 | 75 | #will will list all the group recurively under the listed group (ie, not JUST the children) 76 | 77 | #eg, return al lthe groups in the local probe 78 | # get-prtgGroupsInGroup 1 79 | 80 | function get-prtgGroupsInGroup ([string]$StartingID=0) 81 | { 82 | 83 | $url = "http://$PRTGHost/api/table.xml?content=groups&output=csvtable&columns=objid,probe,group,name,downsens,partialdownsens,downacksens,upsens,warnsens,pausedsens,unusualsens,undefinedsens&count=2500&id=$StartingID&$auth" 84 | $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 85 | $getprtgGroupret = convertFrom-csv ($request) -WarningAction SilentlyContinue 86 | #write-host "got groups from website..." 87 | $getprtgGroupret 88 | 89 | } # end function 90 | 91 | 92 | 93 | ############################################## 94 | ############Set-prtgDeviceProperty############ 95 | ############################################## 96 | # Sets a property of a device 97 | 98 | function Set-prtgDeviceProperty ([string]$DeviceID,[string]$PropertyName,[string]$Value) 99 | { 100 | $url = "http://$PRTGHost/api/setobjectproperty.htm?id=$DeviceID&name=$PropertyName&value=$Value&$auth" 101 | $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 102 | 103 | 104 | } # end function 105 | 106 | 107 | 108 | ############################################## 109 | ############Get-prtgSensorChannels############ 110 | ############################################## 111 | 112 | function Get-prtgSensorChannels ([string]$SensorID) 113 | { 114 | #this does not retuen the channelID - rather important for somethings. 115 | $url = "http://$PRTGHost/api/table.xml?content=channels&output=csvtable&columns=name,lastvalue_&id=$SensorID&$auth" 116 | $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 117 | convertFrom-csv ($request) -WarningAction SilentlyContinue 118 | 119 | 120 | } # end function 121 | 122 | function Get-prtgSensorChannelIDs ([string]$SensorID) 123 | { 124 | #this does retuen the channelID - but not the last value 125 | $url = "http://$PRTGHost/controls/channeledit.htm?_hjax=true&id=$SensorID&$auth" 126 | 127 | $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 128 | $ret = $request.AllElements.FindByName("channel") | select -ExpandProperty outerText 129 | $temp = ""|select ChannelID,ChannelName,LastValue 130 | $rets = $ret -split "\)" 131 | foreach ($ret3 in $rets) 132 | { 133 | $temp.ChannelName = $ret3 -split "ID"[0] 134 | $temp.ChannelID = $ret3 -split "ID"[1] 135 | $temp 136 | } 137 | 138 | 139 | 140 | 141 | } # end function 142 | 143 | 144 | 145 | ############################################## 146 | ##############Get-prtgSensorData############## 147 | ############################################## 148 | 149 | function Get-prtgSensorData ([string]$SensorID,[datetime]$StartDate,[datetime]$EndDate) 150 | { 151 | $StartDate2 = get-date $StartDate -format "yyyy-MM-dd-hh-mm-ss" 152 | $EndDate2 = get-date $EndDate -format "yyyy-MM-dd-hh-mm-ss" 153 | #/api/historicdata.csv?id=objectid&avg=0&sdate=2016-01-20-00-00-00&edate=2016-01-21-00-00-00 154 | $url = "http://$PRTGHost/api/historicdata.csv?id=$SensorID&avg=3600&sdate=$StartDate2&edate=$EndDate2&$auth" 155 | #$url 156 | $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 157 | convertFrom-csv ($request) -WarningAction SilentlyContinue 158 | 159 | } # end function 160 | 161 | 162 | ############################################## 163 | #######Get-prtgSensorChannelPrediction######## 164 | ############################################## 165 | 166 | function Get-prtgSensorChannelPrediction ($SensorID,$ChannelName,$AgeOfFirstSampleInDays,$Limit,[bool]$Debug) 167 | { 168 | $NewDate = [DateTime]::Now.Subtract([TimeSpan]::FromDays($AgeOfFirstSampleInDays)) 169 | $NewDate = get-date $NewDate -format "yyyy-MM-dd hh:mm:ss" 170 | if($debug){"Checking Historical Data from $NewDate"} 171 | 172 | $ChannelNameRaw = $ChannelName + "(RAW)" 173 | $OldData = [long](Get-prtgSensorData -SensorID $SensorID -StartDate $NewDate -EndDate $NewDate | where {$_.$ChannelNameRaw -like "*.*" } | select $ChannelNameRaw -first 1)."$ChannelNameRaw" 174 | if($debug){"Historical Data equals $OldData"} 175 | $CurrentDate = get-date -format "yyyy-MM-dd hh:mm:ss" 176 | if($debug){"Current Date equals $CurrentDate"} 177 | 178 | #I really have to change the line below to to use /10 but rather replace "0.","." - then test. 179 | $NewData = [long](Get-prtgSensorChannels -SensorID $SensorID | where {$_.channel -eq "$ChannelName"} | select "Last Value(RAW)")."last value(RAW)" /10 180 | if($debug){"Current Data equals $NewData"} 181 | if($debug){"Limit equals equals $Limit"} 182 | 183 | 184 | $r = 1 185 | if($Limit -gt $NewData) 186 | { #eg, 100 percent 187 | if($NewData -gt $OldData) 188 | { # its raising, eg disk space use is growing 189 | #=(limit-newdata)/((newdata-olddata)/timeunits) 190 | $ret = ($Limit-$NewData)/(($NewData-$OldData)/$AgeOfFirstSampleInDays) 191 | } 192 | else 193 | {# eg, we are freeing space up! this is good 194 | if($debug){"We will not hit the limit"} 195 | $ret = 999 196 | } 197 | } 198 | else 199 | { # its small, like zero 200 | if($NewData -gt $OldData) 201 | { # eg, we are freeing space up! this is good 202 | if($debug){"We will not hit the limit"} 203 | $ret = 999 204 | } 205 | else 206 | {# its falling, eg free disk space is gown down 207 | #=new/((old-new)/timeunits) 208 | $ret = $NewData / (($OldData-$NewData)/$AgeOfFirstSampleInDays) 209 | } 210 | } 211 | 212 | if($debug){"Days Till Limit is reached equals $ret"} 213 | [int]$ret = $ret 214 | "" + $ret + ":OK" 215 | } # end function 216 | 217 | 218 | 219 | 220 | ############################################## 221 | ############Get-prtgDeviceProperty############ 222 | ############################################## 223 | # Gets a property of a device 224 | 225 | function Get-prtgDeviceProperty ([string]$DeviceID,[string]$PropertyName) 226 | { 227 | $url = "http://$PRTGHost/api/getobjectproperty.htm?id=$DeviceID&name=$PropertyName&$auth" 228 | [xml]$request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 229 | $request.ChildNodes.result 230 | 231 | } # end function 232 | 233 | 234 | ############################################## 235 | ############Add-prtgSensorToDevice############ 236 | ############################################## 237 | # add's a sensor to a device (good for updating templates- adding a new sensor to 100's of devices) 238 | 239 | 240 | 241 | #eg add one sensor to a group of devices 242 | #add-prtgSensorToDevice -SensorScriptBlock {Get-prtgSensorInGroup | where {$_.id -eq 8328}} -DevicesScriptBlock {Get-prtgDevicesInGroup 7633} 243 | 244 | #eg, add sensor 5520 to device 6409 245 | #add-prtgSensorToDevice -SensorScriptBlock {Get-prtgSensorInGroup | where {$_.id -eq 5520}} -DevicesScriptBlock {Get-prtgDevicesInGroup | where {$_.id -eq 6409}} 246 | 247 | #eg add a pages_left sensor to all devices with a tag of "printer" 248 | #TODO 249 | 250 | function Add-prtgSensorToDevice 251 | { 252 | [CmdletBinding()] 253 | 254 | param( 255 | [Parameter(Mandatory=$False,ValueFromPipelineByPropertyName=$false)] 256 | [scriptblock]$DevicesScriptBlock, 257 | 258 | [Parameter(Mandatory=$False,ValueFromPipelineByPropertyName=$false)] 259 | [scriptblock]$SensorScriptBlock 260 | ) 261 | 262 | process 263 | { 264 | 265 | if ($SensorScriptBlock -ne $null -and $DevicesScriptBlock -ne $null) 266 | { 267 | ##loop thru all the devices. 268 | $Devices = &([scriptblock]::Create($DevicesScriptBlock)) 269 | 270 | foreach($Device in $Devices) 271 | { 272 | $DeviceID = $device.id 273 | "DeviceID=$DeviceID" 274 | 275 | ##Loop thru all the sensors. 276 | $Sensors = &([scriptblock]::Create($SensorScriptBlock)) 277 | 278 | foreach($Sensor in $Sensors) 279 | { 280 | $SensorID = $Sensor.id 281 | "SensorID=$SensorID" 282 | $NewName=$Sensor.Sensor 283 | $url = "http://$PRTGHost/api/duplicateobject.htm?id=$SensorID&Targetid=$DeviceID&name=$NewName&$auth" 284 | $url 285 | $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 286 | } # end foreach - Sensor 287 | } # end foreach - Device 288 | 289 | } # end if 290 | 291 | } # end process 292 | 293 | } # end function 294 | 295 | 296 | 297 | ############################################## 298 | ############Add-prtgSensorToDevice2########### 299 | ############################################## 300 | # add's a sensor to a device (good for updating templates- adding a new sensor to 100's of devices) 301 | 302 | #it also returns the ID's of what it added 303 | 304 | #eg add one sensor to a group of devices 305 | #add-prtgSensorToDevice -SensorScriptBlock {Get-prtgSensorInGroup | where {$_.id -eq 8328}} -DevicesScriptBlock {Get-prtgDevicesInGroup 7633} 306 | 307 | #eg, add sensor 5520 to device 6409 308 | #add-prtgSensorToDevice -SensorScriptBlock {Get-prtgSensorInGroup | where {$_.id -eq 5520}} -DevicesScriptBlock {Get-prtgDevicesInGroup | where {$_.id -eq 6409}} 309 | 310 | #eg add a pages_left sensor to all devices with a tag of "printer" 311 | #TODO 312 | 313 | function Add-prtgSensorToDevice2 314 | { 315 | [CmdletBinding()] 316 | 317 | param( 318 | [Parameter(Mandatory=$False,ValueFromPipelineByPropertyName=$false)] 319 | [scriptblock]$DevicesScriptBlock, 320 | 321 | [Parameter(Mandatory=$False,ValueFromPipelineByPropertyName=$false)] 322 | [scriptblock]$SensorScriptBlock 323 | ) 324 | 325 | process 326 | { 327 | 328 | if ($SensorScriptBlock -ne $null -and $DevicesScriptBlock -ne $null) 329 | { 330 | ##loop thru all the devices. 331 | $Devices = &([scriptblock]::Create($DevicesScriptBlock)) 332 | 333 | foreach($Device in $Devices) 334 | { 335 | $DeviceID = $device.id 336 | #"DeviceID=$DeviceID" 337 | 338 | ##Loop thru all the sensors. 339 | $Sensors = &([scriptblock]::Create($SensorScriptBlock)) 340 | 341 | foreach($Sensor in $Sensors) 342 | { 343 | $SensorID = $Sensor.id 344 | #"SensorID=$SensorID" 345 | $NewName=$Sensor.Sensor 346 | $url = "http://$PRTGHost/api/duplicateobject.htm?id=$SensorID&Targetid=$DeviceID&name=$NewName&$auth" 347 | #$url 348 | $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 349 | 350 | write-output $request.headers.location.split("=")[1] 351 | } # end foreach - Sensor 352 | } # end foreach - Device 353 | 354 | } # end if 355 | 356 | } # end process 357 | 358 | } # end function 359 | 360 | 361 | ############################################## 362 | ############Add-prtgDevice############ 363 | ############################################## 364 | # adds a new device in PRTG 365 | 366 | #example 367 | #Add-prtgDevice -NewIP "5.5.5.5" -TemplateID 5682 -DestGroupID 6408 -NewDeviceName "Hi_I_Am_New" 368 | 369 | #example, import from CSV. where the fields are newip, TemplateID, DestGroupID, NewDeviceName 370 | #Import-Csv -Delimiter "`t" -path c:\prtgimport.csv | Add-prtgDevice 371 | 372 | function Add-prtgDevice 373 | { 374 | 375 | [CmdletBinding()] 376 | 377 | param( 378 | [Parameter(Mandatory=$True,ValueFromPipelineByPropertyName=$true)] 379 | [string]$NewIP, 380 | 381 | [Parameter(Mandatory=$True,ValueFromPipelineByPropertyName=$true)] 382 | [string]$TemplateID, 383 | 384 | [Parameter(Mandatory=$True,ValueFromPipelineByPropertyName=$true)] 385 | [string]$DestGroupID, 386 | 387 | [Parameter(Mandatory=$True,ValueFromPipelineByPropertyName=$true)] 388 | [string]$NewDeviceName 389 | 390 | 391 | ) 392 | 393 | Process 394 | { 395 | #$NeWIP = "2.2.2.2" 396 | #$TemplateID = "5539" 397 | #$DestGroupID = "5538" 398 | #$NewDeviceName = "Server1" 399 | 400 | "" + "adding sensor$NewIP" 401 | #Duplicate the sensor (Server replies with a redirect to new objects webpage, e.g. /sensor.htm?id=10214, parse id 10214 from the URL): 402 | $url = "http://$PRTGHost/api/duplicateobject.htm?id=$TemplateID&name=$NewDeviceName&targetid=$DestGroupID&$auth" 403 | 404 | $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 405 | $newID = $request.Headers.Location.Split("=")[1] 406 | 407 | #add in the correct IP (host) the new sensor: 408 | $url = "http://$PRTGHost/api/setobjectproperty.htm?id=$newID&name=host&value=$newIP&$auth" 409 | $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 410 | 411 | #Resume monitoring for the new sensor: 412 | $url = "http://$PRTGHost/api/pause.htm?id=$newID&action=1&$auth" 413 | $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 414 | } #end process 415 | } # end function 416 | 417 | 418 | ############################################## 419 | #######Get-PRTGActiveAdvancedSchedule######### 420 | ############################################## 421 | #looks in the comments for a given sensor, and grabs what is between the "{AdvancedSchedule}" and "{/AdvancedSchedule}" tags. 422 | # eg: 423 | #{AdvancedSchedule} 424 | #Channel,Start,Stop,UpperWarn,UpperError,LowerWarn,LowerError 425 | #0,07:00,12:30,1,2,3,4 426 | #0,12:31,6:59,5,6,7,8 427 | #{/AdvancedSchedule} 428 | # 429 | 430 | Function Get-PRTGActiveAdvancedSchedule{ 431 | param 432 | ( 433 | $DeviceID 434 | ) 435 | 436 | ##get the comments 437 | [string]$ret = Get-prtgDeviceProperty -DeviceID $DeviceID -PropertyName comments 438 | 439 | #strip the headers 440 | $q1 = $ret.IndexOf("{AdvancedSchedule}") 441 | $q2 = $ret.IndexOf("{/AdvancedSchedule}") 442 | $ret = $ret.Substring($q1+18,($q2-$q1)-18) 443 | 444 | #$ret = $ret.Replace("{AdvancedSchedule}","") 445 | #$ret = $ret.Replace("{/AdvancedSchedule}","") 446 | 447 | #get rid of the blank lines 448 | $ret2 = $ret -creplace '(?m)^\s*\r?\n','' 449 | 450 | $ret3 = convertFrom-csv ($ret2) 451 | 452 | #return just the active entries 453 | $ret3 | where {$_.start -lt (get-date).TimeOfDay -and $_.stop -gt (get-date).TimeOfDay} 454 | 455 | 456 | } 457 | 458 | 459 | ############################################## 460 | ###########Set-PRTGChannelSettings############ 461 | ############################################## 462 | 463 | #warning: this is not part of the standard API - and might be removed at any time. 464 | #warning: this is really useful! 465 | #this lets you update channel properties. To get a list of properties you can change you will 466 | # need to examine the post data (using browser tools) when making changes to a channel via the PRTG web interface. 467 | 468 | function Set-PRTGChannelSettings{ 469 | param( 470 | $DeviceID, 471 | $ChannelID, 472 | $Property, 473 | $Value 474 | ) 475 | 476 | $url = "http://$PRTGHost/editsettings?$Property" + "_" + $ChannelID + "=" + "$value&id=$DeviceID&$auth" 477 | #$url 478 | $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 479 | } 480 | 481 | ############################################## 482 | ###########Get-PRTGChannelSettings############ 483 | ############################################## 484 | 485 | #warning: this is not part of the standard API - and might be removed at any time. 486 | #warning: this is really useful! 487 | #this lets you update channel properties. To get a list of properties you can change you will 488 | # need to examine the post data (using browser tools) when making changes to a channel via the PRTG web interface. 489 | 490 | function Get-PRTGChannelSettings{ 491 | param( 492 | $DeviceID, 493 | $ChannelID 494 | ) 495 | 496 | $url = "http://$PRTGHost/controls/channeledit.htm?_hjax=true&id=$DeviceID&channel=$ChannelID&$auth" 497 | 498 | $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 499 | $ret = $request.AllElements | select name,value | where {$_.name -like "*_*"} 500 | foreach ($line in $ret) 501 | { 502 | $line.name = $line.name -replace "_$ChannelID","" 503 | } 504 | $ret 505 | } 506 | 507 | 508 | 509 | function Set-PRTGAdvancedSchedules{ 510 | $DeviceswithAdvancedSchedules = Get-prtgSensorInGroup | where {$_.Tags -like "*AdvancedSchedule*"} 511 | Foreach ($Device in $DeviceswithAdvancedSchedules){ 512 | $Schedules = Get-PRTGActiveAdvancedSchedule -DeviceID $Device.ID 513 | Foreach ($Schedule in $Schedules){ 514 | If ($Schedule.UpperError -ne ""){ 515 | Set-PRTGChannelSettings -DeviceID $Device.ID -ChannelID $Schedule.channel -Property limitmaxerror -Value $Schedule.UpperError 516 | } 517 | If ($Schedule.LowerError -ne ""){ 518 | Set-PRTGChannelSettings -DeviceID $Device.ID -ChannelID $Schedule.channel -Property limitminerror -Value $Schedule.LowerError 519 | } 520 | If ($Schedule.UpperWarn -ne ""){ 521 | Set-PRTGChannelSettings -DeviceID $Device.ID -ChannelID $Schedule.channel -Property limitmaxwarning -Value $Schedule.UpperWarn 522 | } 523 | If ($Schedule.LowerWarn -ne ""){ 524 | Set-PRTGChannelSettings -DeviceID $Device.ID -ChannelID $Schedule.channel -Property limitminwarning -Value $Schedule.LowerWarn 525 | } 526 | } 527 | } 528 | 529 | } 530 | 531 | 532 | #example: 533 | #Set-PRTGObjectPause -ObjectID 2003 -Minutes 5 -Message "Please Wait - Server Rebooting" 534 | function Set-PRTGObjectPause{ 535 | param 536 | ( 537 | $ObjectID, 538 | $Message, 539 | $Minutes 540 | ) 541 | ##ObjectID can be a sensor, device or Group 542 | $url = "http://$PRTGHost/api/pauseobjectfor.htm?id=$ObjectID&duration=$minutes&pausemsg=$Message&$auth" 543 | $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 544 | 545 | } 546 | 547 | ############################################## 548 | ##############Set-PRTGObjectResume############ 549 | ############################################## 550 | 551 | ####unpause! 552 | function Set-PRTGObjectResume{ 553 | param 554 | ( 555 | $ObjectID 556 | ) 557 | #Resume monitoring for the new sensor: 558 | $url = "http://$PRTGHost/api/pause.htm?id=$ObjectID&action=1&$auth" 559 | $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 560 | 561 | } 562 | 563 | function Set-PRTGPauseThisServer{ 564 | param 565 | ( 566 | $Message, 567 | $Minutes 568 | ) 569 | $myIPs = Get-NetIPAddress -AddressFamily IPv4 | where { $_.InterfaceAlias -notmatch 'Loopback'} |Select IPAddress 570 | 571 | $t = "" | select ipaddress 572 | $t.ipaddress = hostname 573 | $myips += $t 574 | 575 | $t = "" | select ipaddress 576 | $t.ipaddress = "$env:computername.$env:userdnsdomain" 577 | $myips += $t 578 | 579 | 580 | #$myips 581 | foreach ($ip in $MYIPs){ 582 | $q = Get-prtgDevicesInGroup | where {$_.host -eq $IP.ipaddress} 583 | 584 | foreach ($x in $q){ 585 | Set-PRTGObjectPause -ObjectID $x.ID -Minutes $Minutes -Message "$Message" 586 | } 587 | } 588 | } 589 | 590 | 591 | function Set-PRTGResumeThisServer{ 592 | $myIPs = Get-NetIPAddress -AddressFamily IPv4 | where { $_.InterfaceAlias -notmatch 'Loopback'} |Select IPAddress 593 | 594 | $t = "" | select ipaddress 595 | $t.ipaddress = hostname 596 | $myips += $t 597 | 598 | $t = "" | select ipaddress 599 | $t.ipaddress = "$env:computername.$env:userdnsdomain" 600 | $myips += $t 601 | 602 | 603 | #$myips 604 | foreach ($ip in $MYIPs){ 605 | $q = Get-prtgDevicesInGroup | where {$_.host -eq $IP.ipaddress} 606 | 607 | foreach ($x in $q){ 608 | $url = "http://$PRTGHost/api/pause.htm?id=" + $x.ID + "&action=1&$auth" 609 | $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore 610 | } 611 | } 612 | } 613 | 614 | function Get-PRTGChannelDetailExportForDevices 615 | { 616 | param 617 | ( 618 | $ObjectID 619 | ) 620 | 621 | $Devices = Get-prtgDevicesInGroup -StartingID $ObjectID 622 | foreach ($Device in $Devices) 623 | { 624 | $Sensors = Get-prtgSensorInGroup -StartingID $Devices.id 625 | Foreach ($Sensor in $Sensors) 626 | { 627 | $Channels = Get-prtgSensorChannels -SensorID $Sensor.id 628 | Foreach ($Channel in $Channels) 629 | { 630 | $ret = Get-PRTGChannelSettings -DeviceID $Device.id -ChannelID $Channel.id 631 | $ret 632 | } 633 | } 634 | } 635 | 636 | 637 | 638 | } 639 | --------------------------------------------------------------------------------