Hi JSwitlinski,
You can programmatically toggle the Status of a notification trigger using PowerShell by combining the C# and PowerShell interfaces of PrtgAPI
The following demonstrates the principles you can employ to achieve this functionality
function ToggleNotificationActions($name)
{
# Connect to your PRTG Server. As a scheduled task, you should create a dedicated API user
Connect-PrtgServer https://prtg.example.com (New-Credential prtgadmin prtgadmin) -Force
# Construct a list each engineer's notification actions
$actions = Get-NotificationAction "Ticket Notification","Email and push notification to admin"
# Loop over each engineer and decide whether their action should be enabled or disabled
foreach($action in $actions)
{
if($action.Name -like $name)
{
# Engineer is on call. Enable
Write-Host "Enabling notification action $($action.Name)"
(Get-PrtgClient).SetObjectProperty($action.Id, [PrtgAPI.ObjectProperty]::Active, $true)
}
else
{
# Engineer is off call. Disable
Write-Host "Disabling notification action $($action.Name)"
(Get-PrtgClient).SetObjectProperty($action.Id, [PrtgAPI.ObjectProperty]::Active, $false)
}
}
}
ToggleNotificationActions "*ticket*"
We can check whether the command worked - only disabling the "Email and push notification to admin" notification by executing Get-NotificationAction
C:\> Get-NotificationAction
Name Id Active Email
---- -- ------ -----
Email and push notification to admin 300 False PRTG System Administrator
Email to all members of group PRTG Users G... 301 True PRTG Users Group
Ticket Notification 302 True None (Disabled)
Email to all members of group PRTG Domain ... 7597 True PRTG Domain Administrators
Of course, in your script you will likely want to toggle the active engineer based on some kind of specified date range. A good solution would be to define a PSCustomObject that maps each engineer to the days they are on call; if the script detects the current day of the week is part of their roster, their notification action is enabled. Otherwise, it is disabled
Regards,
lordmilko
Add comment