lordmilko / PrtgAPI

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

Get-NotificationTrigger is returning an error #314

Closed rsaddlerx closed 1 year ago

rsaddlerx commented 1 year ago

Describe the bug

I've been using a script to manage notification triggers in bulk. The last time it worked, I was running PRTG version 22.2.76.1705. I'm now running PRTG version 22.3.78.1873. The script imports a CSV containing the triggers to be set, connects to the PRTG server, finds the appropriate devices, removes any trigger currently set on the devices and then loops through adding the new triggers within the CSV.

The script now errors when it tries to execute Get-NotificationTrigger.

prtgapi-error

Steps to reproduce

# get PRTG account credentials from Azure Key Vault
$KeyVaultServer = "PRTGRP07P"
$PRTGCreds = Retrieve-PRTGKeyVault-PRTG -KeyVaultServer $KeyVaultServer

# triggers for nutanix servers
$TriggersNutanix = Import-Csv -Path "C:\PRTG\Triggers\nutanix.csv"
$DeviceNameNutanix = "*ahv2*"

# config triggers on prtgdev
$PRTGServer = "prtgdev"
Connect-PrtgServer -Server $PRTGServer -Credential $PRTGCreds -force

# replace notification triggers for nutanix servers
$FindDeviceNameNutanix = @()
$FindDeviceNameNutanix = Get-Device -Name $DeviceNameNutanix
if ($FindDeviceNameNutanix.Count -ne 0) {
    Write-Host "Replacing notifications triggers for Nutanix devices." -ForegroundColor Yellow
    Get-Device -Name $DeviceNameNutanix | Get-Sensor | Get-NotificationTrigger | Remove-Trigger -Force
    foreach ($Trigger in $TriggersNutanix) {
        if ($Trigger.OffNotificationAction) {
            Get-Device -Name $DeviceNameNutanix | Get-Sensor -Name $Trigger.Sensor | New-Trigger -Type $Trigger.Type -State $Trigger.State -Latency $Trigger.Latency -EscalationLatency $Trigger.EscalationLatency -OnNotificationAction $Trigger.OnNotificationAction -OffNotificationAction $Trigger.OffNotificationAction
            }
        else {
            Get-Device -Name $DeviceNameNutanix | Get-Sensor -Name $Trigger.Sensor | New-Trigger -Type $Trigger.Type -State $Trigger.State -Latency $Trigger.Latency -EscalationLatency $Trigger.EscalationLatency -OnNotificationAction $Trigger.OnNotificationAction
            }
        }
    }
else {
    Write-Host "No Nutanix devices found." -ForegroundColor Cyan
    }

Disconnect-PrtgServer

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

Get-PrtgClient -Diagnostic
Get-PrtgClient : Response status code does not indicate success: 403 (Forbidden).
At line:1 char:1
+ Get-PrtgClient -Diagnostic
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-PrtgClient], HttpRequestException
    + FullyQualifiedErrorId : System.Net.Http.HttpRequestException,PrtgAPI.PowerShell.Cmdlets.GetPrtgClient

PrtgAPI = 0.9.17
PRTG Server = 22.3.78.1873+
OS script is running from = Windows 2019 & Windows 2022

Additional context

No response

lordmilko commented 1 year ago

Duplicate of #308

Please follow the instructions in #308 to install the latest preview release