Hey,

We were wondering if it is possible (in the future?) to be able to automatically resume all pauzed sensors on a weekly/monthly basis.

We have some employees who forget they paused a sensor permanently instead of for x hours or using the 'until..' option.

We got rid of some of the permanent pause buttons by altering the webpages but couldn't get rid of all of them.

Thank you.

Kind regards, Wim


Article Comments

That's easy and can be done with a PowerShell script and a scheduled task:

$prtghost="<enter-your-prtg-host>"
$username="<your-prtg-user>";
$passhash="<the-users-passhash-from-the-account-settings>"
$Sensors = ((Invoke-WebRequest -URI "http://$($prtghost)/api/table.json?content=sensors&output=json&columns=objid,device,sensor&filter_status=7&username=$($username)&passhash=$($passhash)").Content | ConvertFrom-Json)


Foreach($Sensor in $Sensors.sensors){
    Write-Host "Resuming $($Sensor.sensor) on $($Sensor.device)..." -NoNewline
    Invoke-WebRequest -Uri "http://$($prtghost)/api/pause.htm?id=$($Sensor.objid)&action=1&username=$($username)&passhash=$($passhash)" | Out-Null
    Write-Host "done." -NoNewline -ForegroundColor Green
    Write-Host "`r"
}

Output will look like this: Output

Simply set the scheduled task to run once a day or hour or minute (so you won't miss any precious metrics).


Jul, 2015 - Permalink

Thank you. The script works great!

I tried to extend the script so devices that are paused will also be resumed but I'm having some issues with it. I'm not able to get back a list with paused devices. (using &filter_status=7) Even though I'm sure there is at least one device with this raw status value because I get the following results without the filter.

{"status":"Up","status_raw":3,"device":"VIRUSWALL"}, {"status":"Up","status_raw":3,"device":"BESMVVP"}, {"status":"Up","status_raw":3,"device":"SQLMVVP"}, {"status":"Paused (paused)","status_raw":7,"device":"PH2-TEST"}]}

The URI I'm using is: https://*redacted*/api/table.json?content=devices&output=json&columns=objid,status,device&filter_status=7


Jul, 2015 - Permalink

A bit ugly, but it works:

$Sensors = ((Invoke-WebRequest -URI "http://$($prtghost)/api/table.json?content=sensors&output=json&columns=objid,device,sensor&filter_status=7&username=$($username)&passhash=$($passhash)").Content | ConvertFrom-Json)
$Devices = ((Invoke-WebRequest -URI "http://$($prtghost)/api/table.json?content=devices&output=json&columns=objid,device&filter_status=7&username=$($username)&passhash=$($passhash)").Content | ConvertFrom-Json)
$Groups = ((Invoke-WebRequest -URI "http://$($prtghost)/api/table.json?content=groups&output=json&columns=objid,device,group&filter_status=7&username=$($username)&passhash=$($passhash)").Content | ConvertFrom-Json)

Write-Host "[Unpausing groups]"
Foreach($Group in $Groups.groups){
    Write-Host "Resuming $($Group.group)..." -NoNewline
    Invoke-WebRequest -Uri "http://$($prtghost)/api/pause.htm?id=$($Group.objid)&action=1&username=$($username)&passhash=$($passhash)" | Out-Null
    Write-Host "done." -NoNewline -ForegroundColor Green
    Write-Host "`r"
}

Write-Host "[Unpausing devices]"
Foreach($Device in $Devices.devices){
    Write-Host "Resuming $($Device.device)..." -NoNewline
    Invoke-WebRequest -Uri "http://$($prtghost)/api/pause.htm?id=$($Device.objid)&action=1&username=$($username)&passhash=$($passhash)" | Out-Null
    Write-Host "done." -NoNewline -ForegroundColor Green
    Write-Host "`r"
}
Write-Host "[Unpausing sensors]"
Foreach($Sensor in $Sensors.sensors){
    Write-Host "Resuming $($Sensor.sensor) on $($Sensor.device)..." -NoNewline
    Invoke-WebRequest -Uri "http://$($prtghost)/api/pause.htm?id=$($Sensor.objid)&action=1&username=$($username)&passhash=$($passhash)" | Out-Null
    Write-Host "done." -NoNewline -ForegroundColor Green
    Write-Host "`r"
}

Outputs something like this:

[Unpausing groups]
Resuming Miscellaneous...done.
Resuming Plants...done.
[Unpausing devices]
Resuming Palm Tree...done.
[Unpausing sensors]
Resuming Status on Palm Tree...done.

I know, could be done in a foreach loop, but I don't have the time to fiddle around with it :)

edit fixed copy pasta


Jul, 2015 - Permalink

Thanks.

Hmm, weird, still no devices that are being resumed. For some reason it just doesn't find them.

Now all the paused sensors are resumed, except the ones that are paused by parent(device) that's paused.

PS C:\Users\Wim\Desktop> .\resumeall.ps1 [Unpausing groups] [Unpausing devices] [Unpausing sensors] Resuming Ping on PH2-TEST (no action necessary)...done. Resuming CPU Load 66 on PH2-TEST (no action necessary)...done. Resuming Memory 71 on PH2-TEST (no action necessary)...done. Resuming Disk Free 69 on PH2-TEST (no action necessary)...done. Resuming vmxnet3 Ethernet Adapter _2 on PH2-TEST (no action necessary)...done.


Jul, 2015 - Permalink

When you paste the device URL into the browser, do you get any results for that? (remember to add the variables, username etc.)


Jul, 2015 - Permalink

I get an empty list in the file I get back if I put the filter in the query. (Via browser) Without the filter I get all our devices it seems.


Aug, 2015 - Permalink

To Start, Resume or CheckNow any object from the command line see also

KB: start or pause sensor from command line


Aug, 2015 - Permalink