lordmilko / PrtgAPI

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

Dependency Property not #311

Closed shane5557 closed 1 year ago

shane5557 commented 1 year ago

Describe the bug

We are using the API to try and turn off Inherited triggers. I wanted to assign only one notification trigger and to ingore the parents to prevent two templates from happening. Each time I run the command below it says it worked but no actual change is made to the device in the gui or in the API. (inherittriggers=0)

$child_id = 12345

        # Dependency set to "Master Object For Parent" 
        $dependency = @{
            scheduledependency = 0
            dependencytype_ = 1
            DependentObjectId = "70253"
            DependencyDelay = 0
        }

        $child = Get-Sensor -ID $child_id.ID
        $child | Set-ObjectProperty -RawParameters $dependency -Force -Verbose

https://xxxxxx.xxx.com/editsettings?id=86622&scheduledependency=0&dependencytype_=1&dependencydelay=0&Dependentobjectid=70253&

######################################################## The second part of this is similar as one of the sensor ObejectProperty wont change. In this case im trying to toggle the inherrittriggers so it doesnt choose to use the Parent Notification Template & the new template i just created. I only want the sensor to use the newly defined template specific to it.

$dependency = @{ inherittriggers = 0 }

get-sensor $s

              $params = New-TriggerParameters -Id $s.Id -Type "State"
              $params.OnNotificationAction = Get-NotificationAction $template_name
              $params.OffNotificationAction = Get-NotificationAction $template_name            
              $params | Add-Trigger

Invoke-WebRequest -uri "[https://xxxxxxxxxx.com/editsettings?id=83052&inherittriggers=0&username=xx$pas] RawContent : HTTP/1.1 200 OK Connection: close

Steps to reproduce

Invoke-WebRequest -uri

$child_id = 12345

            # Dependency set to "Master Object For Parent" 
            $dependency = @{
                scheduledependency = 0
                dependencytype_ = 1
                DependentObjectId = "70253"
                DependencyDelay = 0
            }

            $child = Get-Sensor -ID $child_id.ID
            $child | Set-ObjectProperty -RawParameters $dependency -Force -Verbose

#####################################
$dependency = @{
    inherittriggers = 0
}

get-sensor $s 

                  $params = New-TriggerParameters -Id $s.Id -Type "State"
                  $params.OnNotificationAction = Get-NotificationAction $template_name
                  $params.OffNotificationAction = Get-NotificationAction $template_name            
                  $params | Add-Trigger

What is the output of 'Get-PrtgClient -Diagnostic'?

PS C:\Windows\system32> Get-PrtgClient -Diagnostic

PSVersion      : 5.1.19041.1682
PSEdition      : Desktop
OS             : Microsoft Windows 10 Enterprise
PrtgAPIVersion : 0.9.17
Culture        : en-US
CLRVersion     : 528372
PrtgVersion    : 22.3.79.2108
PrtgLanguage   : english.lng

Additional context

No response

lordmilko commented 1 year ago

Hi @shane5557,

The "dependency" of an object B is the object A, that when down, causes the object B to go down. i.e. Devices typically depend on Ping sensors

In order to disable trigger inheritance you need to set the -InheritTriggers property to $false

Get-Device -Id 1001 | Set-ObjectProperty -InheritTriggers $false
shane5557 commented 1 year ago

Thank you I've spent days trying to get this to work! Calling it that way using $false solved the issue for me.

The second part I'm still struggling with the Dependency of a sensor (DependentObjectID) I can't seem to find a way to make it change to another value without manually selecting it in the GUI.

Dependency set to "Select a sensor"

        $dependency = @{
            scheduledependency = 0
            dependencytype_ = 1  ***This changes the Dependency Type to "Select a Sensor" as expected

---->>>> DependentObjectId = "70253" <<<<<<-------- Won't pass this value...

dependencyvalue = $id

            DependencyDelay = 0 
        }

        $child = Get-Sensor -ID xxxx
        $child | Set-ObjectProperty -RawParameters $dependency -Force -Verbose

############# OUTPUT ###################### VERBOSE: Performing the operation "Set-ObjectProperty scheduledependency = '0', dependencytype = '1', DependencyDelay = '0', DependentObjectId = '70253'" on target "'Access Point / xxx-xxx-xxx (xxxxxxxxxxxxx)' (ID: 86622)". VERBOSE: Set-ObjectProperty: Synchronously executing request https://xxxxxxxx.com/editsettings?id=86622&scheduledependency=0&dependencytype=1&dependencydelay=0&dependentobjectid=70253

lordmilko commented 1 year ago

As per #18 you need to set the dependency_ field to the ID of the object to be dependent on, as seen in the following example

# Create a device named "dc-1" and set its dependency to the object with ID 40
Get-Probe | Add-Device dc-1 | Set-ObjectProperty -RawParameters @{
    scheduledependency=0
    dependencytype_=1
    dependency_=40
} -Force

The names of these parameters can be derived either by tracing with Fiddler or by inspecting the HTML on the PRTG webpage (use the Chrome Inspector to select the textbox on the page to navigate straight to the surrounding source code)

shane5557 commented 1 year ago

Thanks again. This is working as you described and I learned something along the way. Hope this helps someone else moving forward and truly appreciate your response and time.