lordmilko / PrtgAPI

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

Adding a Schedule to a sensor #398

Closed zarat closed 2 months ago

zarat commented 2 months ago

What's going on?

I'm trying to add a new sensor using Add-Sensor and New-SensorParameters. Is there a way to add a schedule to a sensor using the API? I found this thread https://kb.paessler.com/en/topic/66047-use-api-to-assign-schedules-to-sensors but it changes the schedule of a device, not a sensor. Are the parameters used by New-SensorParameters all the available ones?

@{
        name_ = "My new sensor"
        tags_ = "xmlexesensor"
        priority_ = 3
        exefile_ = ""
        exeparams_ = ""
        environment_ = 1
        usewindowsauthentication_ = 1
        mutexname_ = "testMutex"
        timeout_ = 60
        writeresult_ = 0
        intervalgroup = 0
        interval_ = "60"
        errorintervalsdown_ = 2
        sensortype = "exexml"
}

Friendly regards

Due Dilligance

lordmilko commented 2 months ago

You can set the schedule using Set-ObjectProperty after the sensor has been created. See #155 for an example of how to do this

zarat commented 2 months ago

Hi and thank you for the quick response. Sorry for my bad english but i am asking for the schedule returned by Get-PRTGSchedule not the notifications returned by Get-NotificationAction. The time plan at which hours a sensor is scanned.

lordmilko commented 2 months ago

The first example in #155 shows how to do this

Get-Probe -Id 17834 | Set-ObjectProperty -RawParameters @{
    "scheduledependency" = 0
    "schedule_" = Get-PrtgSchedule "Alerting Hours 7am ~11pm"
} -Force

Substitute Get-Probe with Get-Sensor