lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
305 stars 38 forks source link

Depenencies configuration with PrtgAPI in Powershell #148

Closed fabianadam closed 4 years ago

fabianadam commented 4 years ago

The target I would like to configure ping sensor as "master sensor for parent" with PrtgAPI in Powershell. Having made the modification in prtg UI the following two properties were changed: scheduledependency and dependencytype, the changes can be traced with

$devicename = "<my device name>"
get-device $devicename | get-sensor ping | get-objectproperty -Raw

The issue When I tried to set "Master sensor for parent" (dependencytype_ = 2) with

get-device $devicename | get-sensor ping | set-objectproperty -rawproperty dependencytype_ -rawvalue 2

or with

get-device $devicename | get-sensor ping | set-objectproperty -rawparameters @{
        "scheduledependency_" = 0
        "dependencytype_" = 2
}

it does not work. No error message appears, but the value has not been changed. The only thing that works for me is to change the settings from any value to "Use parent" (dependencytype = 0) with

get-device $devicename | get-sensor ping | set-objectProperty -rawproperty dependencytype_ -rawvalue 0

Any idea what should be done differently?

Additional context When I tried to get the property values one by one it worked for the dependencytype only, for the scheduledependency it drops an error:

S C:\users\user\> get-device $devicename | get-sensor ping | get-objectproperty -rawproperty scheduledependency_
get-objectproperty : PRTG was unable to complete the request. A value for property 'scheduledependency' could not be found.
At line:1 char:41
+ ...  get-sensor ping | get-objectproperty -rawproperty scheduledependency_
+                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-ObjectProperty], PrtgRequestException
    + FullyQualifiedErrorId : PrtgRequestException,PrtgAPI.PowerShell.Cmdlets.GetObjectProperty
lordmilko commented 4 years ago

Hi @fabianadam,

Your Set-ObjectProperty attempt with -RawParameters is close, however your scheduledependency_ property should in fact be called scheduledependency

As per #18 and #133, you can achieve this as follows

$sensor | Set-ObjectProperty -RawParameters @{
    scheduledependency = 0
    dependencytype_ = 2
} -Force

The "inheritance" property in PRTG is always written without an underscore. And as per the wiki

PRTG does not support the retrieval of individual inheritance properties; as such, these properties must be retrieved via Get-ObjectProperty / Get-ObjectProperty -Raw (for supported and unsupported properties, respectively)

Regards, lordmilko