Hello, I'd like to desable all schedules by script in order to check if we will have sensors down after our maintenance. And once all is good, we'd like to enable all schedules again.

Regards Jeff


Article Comments

Hi Jeff,

I am afraid this is not possible.


Kind regards
Andreas Günther, Technical Support


Apr, 2018 - Permalink

Hello Andreas, What about antoher way ?

Export in CSV or XML all sensors with schedule, by script modify their sensors to delete schedule.

After our maintenance, restore all schedules on every sensor.

Regards.


Apr, 2018 - Permalink

Hi Jeff,

Actually there is no dedicated API call to disable schedules. In addition to that you would loose the connection between sensor and the specific schedule.

I am afraid I'm not able to provide you with a workaround for your plans.


Kind regards
Andreas Günther, Technical Support


Apr, 2018 - Permalink

Hi Jeff,

This can be achieved with PrtgAPI. Whiile manipulation of schedule properties is not fully supported, this can still be achieved by combining a bit of PowerShell with the library's underlying C# API

As you've indicated, by enabling inheritance of schedule settings from the parent object, you will have effectively "disabled" the schedule for that object. The schedules can (theoretically) be re-added by disabling schedule inheritance again. The major challenge however (as Andreas alludes to) is that when you enable inheritance of schedule settings the original schedule will actually have been deleted!

The solution to this, therefore, is to perform the following

1. Save the original schedule of the object (if applicable)

2. Enable schedule inheritance (removing the schedule)

3. Disable schedule inheritance, re-adding the previously saved schedule

The following gives an example of how to do this to a single sensor (ID 7816)

$sensor = Get-Sensor -Id 7816

$schedule = ($sensor | Get-ObjectProperty).Schedule

$sensor | Set-ObjectProperty -RawProperty scheduledependency -RawValue 1

$p1 = New-Object PrtgAPI.Parameters.CustomParameter -ArgumentList @("schedule_", $schedule)
$p2 = New-Object PrtgAPI.Parameters.CustomParameter -ArgumentList @("scheduledependency", 0)

$ps = $p1,$p2

(Get-PrtgClient).SetObjectPropertyRaw($sensor.Id, $ps)

In your scenario, I would recommend building up a Dictionary mapping objects to schedules. Abstract the code out into two functions: one that gets rid of a schedule and one that restores it. When you are ready to re-enable your schedules again, you can simply iterate over the Dictionary, re-adding the specific schedule that belonged to each object.

Regards,

lordmilko


Apr, 2018 - Permalink