lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
301 stars 37 forks source link

Problem when updating the schedule #164

Closed mrpowershell closed 4 years ago

mrpowershell commented 4 years ago

Dear team,

I'm currently working on a program that uses the API here to automatically adjust the schedules according to holidays and special days which can be controlled in a GUI. The logic of the program is finished so far, but I fail at this point to pass the data to PRTG:

For example: According to the userinput, i generate a variable $schedulevalues with the content, 14,13,25,26,60

$schedulevalues is in powershell per definition a STRING

When i know try to run this code:

Get-PrtgSchedule -Id $id | Set-ObjectProperty -Force -RawParameters @{ timetable = $schedulevalues timetable_ = "" }

i get the following error:

Set-ObjectProperty : PRTG was unable to complete the request. The server responded with the following error: Interner Fehler:

'13,14,18,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,61,62,66,85,86,90,109,110,114,132,133,134,135,138,139,156,157,158,159,162,163' is not a valid integer value. In C:\Users\Administrator\Documents\PRTGSCHEDULER\Source\prtg_scheduler_runner.ps1:248 Zeichen:29

  • ... t-PrtgSchedule -Id 2226 | Set-ObjectProperty -Force -RawParameters @{
  • 
    + CategoryInfo          : InvalidOperation: (:) [Set-ObjectProperty], PrtgRequestException
    + FullyQualifiedErrorId : PrtgRequestException,PrtgAPI.PowerShell.Cmdlets.SetObjectProperty

do you have any idea how to solve this?

lordmilko commented 4 years ago

Hi @mrpowershell,

The issue is that the timetable variable is not supposed to be a string, but rather a list of integers

On the wiki there is the following example on how to do this

# Enable monitoring across all hours of the week
Get-PrtgSchedule -Id 620 | Set-ObjectProperty -RawParameters @{
    timetable = 0..167
    timetable_ = ""
}

In the code timetable = 0..167, 0..167 uses range syntax to specify "all the integers between 0 and 167"

As such, in your scenario you should be able to set the timetable of the object as follows

$schedulevalues = 13,14,18,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,61,62,66,85,86,90,109,110,114,132,133,134,135,138,139,156,157,158,159,162,163
Get-PrtgSchedule -Id $id | Set-ObjectProperty -Force -RawParameters @{ timetable = $schedulevalues timetable_ = "" }

Regards, lordmilko