-
-
Notifications
You must be signed in to change notification settings - Fork 38
Notification Actions
Notification Actions supported by PRTG can be retrieved via the GetNotificationActions
method
var actions = client.GetNotificationActions();
Settings specific to each notification type (i.e. Email, SMS, etc) are grouped under corresponding sub-properties of the NotificationAction
object
foreach (var action in actions)
{
if(action.Email.Enabled)
{
Console.WriteLine($"Emails are sent to {action.Email.Address} with subject {action.Email.Subject}");
}
}
When retrieving Notification Actions, one or more SearchFilter
objects can be specified to limit the returned results. Note however that not all Property
values supported by PRTG are compatible with notification action queries. As such, if you find your specified filter does not work, you may want to filter within your application instead of within PRTG.
//Get the notification action with ID 301
var action = client.GetNotificationActions(Property.Id, 301).FirstOrDefault();
When retrieving a particular notification action you insist should exist, it is possible to use the singular GetNotificationAction
method, returning a single NotificationAction
rather than a List<NotificationAction>
as with GetNotificationActions
.
GetNotificationAction
supports filtering by either the object name or object ID
var action = client.GetNotificationAction(300);
var action = client.GetNotificationAction("Ticket Notification");
If exactly one notification action with the specified ID or name is not returned, GetNotificationAction
will throw an InvalidOperationException
. If you are not sure whether exactly one notification action with the specified ID or name exists, you should use GetNotificationActions
instead and check for the presence of any results.
var action = client.GetNotificationActions(Property.Id, 300).SingleOrDefault();
if (action != null)
Console.WriteLine($"Found exactly one action: '{action}'!");
When synchronously retrieving NotificationAction
objects via the GetNotificationActions
method, PrtgAPI will automatically populate all enhanced object properties (including the details of each notification type - i.e. Email
, SMS
, Ticket
, etc). When retrieving actions via any other method (for example GetNotificationTriggers
) PrtgAPI will defer loading these properties (and invoking a web request) until these properties are actually accessed.
NotificationAction
objects retrieved via asynchronous requests (including GetNotificationActionsAsync
/ GetNotificationTriggersAsync
) are always loaded immediately so that any secondary requests can be executed in parallel for multiple objects.
Note that if you are currently authenticated with a read only PRTG user, you may not be able to view all notification actions or notification action properties.
Notification Actions supported by PRTG can be retrieved via the Get-NotificationAction
cmdlet
C:\> Get-NotificationAction
Name Id Active Email
---- -- ------ -----
Ticket Notification 302 True None (Disabled)
Email to all members of group PRTG Users Group 301 True PRTG Users Group
Email and push notification to admin 300 True PRTG System Administrator
By default, Get-NotificationAction
will display all contacts of the Email
notification action. Additional actions can be viewed by inspecting a specific object
C:\> Get-NotificationAction ticket*
Name : Ticket Notification
Id : 302
Ticket : PRTG System Administrator, PRTG Administrators
Email : None (Disabled)
Push : None (Disabled)
SMS : None (Disabled)
...
Individual action properties can be inspected to gain a bigger picture of that action's configuration
C:\> (Get-NotificationAction ticket*).ticket
IsUserGroup : True
UserAccount : PRTG System Administrator
UserGroup : PRTG Administrators
Subject : %device %name %status %down (%message)
Message : Sensor: %name went down!
Crisis alert!
AutoClose : True
Enabled : True
Get-NotificationAction
allows filtering by -Name
, -Id
and -Tags
. While Get-NotificationAction
also supports the use of advanced Filters, note however that not all Property
values supported by PRTG are compatible with notification action queries. As such, if you find your specified filter does not work, you may want to filter within your script instead of within PRTG.
When retrieving NotificationAction
objects via the Get-NotificationAction
cmdlet, PrtgAPI will automatically populate all enhanced object properties (including the details of each notification type - i.e. Email
, SMS
, Ticket
, etc). When retrieving actions via any other cmdlet (for example Get-NotificationTrigger
) PrtgAPI will defer loading these properties (and invoking a web request) until these properties are actually accessed.
Note that if you are currently authenticated with a read only PRTG user, you may not be able to view all notification actions or notification action properties.