cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 13

Alert Action Updating via the API

Jump to solution

Hi, I only found one other post ​about this, but I'm still not sure how to do this exactly. 

I'm trying to write a PowerShell script that will bulk Enable/Disable Alert Actions.  I see there is an UpdateAction verb and an UpdateActionProperties verb for the Orion.Actions entity, but I'm not sure how to use them to just enable/disable an action.  The one post I found about this shows him putting in a bunch of XML including all of the Alert Actions properties.  Do I need to provide the full XML, or is there just a way to send Enable/Disable to it without having to populate the full XML?  My guess is I'll need the knowledge of tdanner or dan jagnow to answer this.

0 Kudos
1 Solution
Level 13

Happily, you don't have to provide the full XML.  You can just update the Enabled property like the script below.  This example is for updating a single action, but you could adapt it to handle multiple actions for a bulk update.

Import-Module SwisPowerShell


# Connect to SWIS.

$hostname = "myserver"

$username = "muser"

$password = "superSecretPassword"

$swis = Connect-Swis -host $hostname -Username $Username -Password $Password


# Get the URI of an action associated with an alert configuration.

# Tweak this query to find the alert action you care about.

$alertName = "Alert me when an application goes down"

$actionTypeID = "Email"

$query = "SELECT TOP 1 a.Uri

    FROM Orion.AlertConfigurations ac

    INNER JOIN Orion.ActionsAssignments aa ON ac.AlertID = aa.ParentID

    INNER JOIN Orion.Actions a ON aa.ActionAssignmentID = a.ActionID

    WHERE ac.Name = @alertName AND a.ActionTypeID = @actionTypeID"

$actionUri = Get-SwisData -SwisConnection $swis -Query $query -Parameters @{alertName = $alertName; actionTypeID = $actionTypeID}


# Do this...

# Disable the alert action.

$enabledProps = @{

    Enabled = $false;

}

Set-SwisObject -SwisConnection $swis -Uri $actionUri -Properties $enabledProps | Out-Null


# ... Or do this...

# Enable the alert action.

$enabledProps = @{

    Enabled = $true;

}

Set-SwisObject -SwisConnection $swis -Uri $actionUri -Properties $enabledProps | Out-Null

View solution in original post

2 Replies
Level 13

Happily, you don't have to provide the full XML.  You can just update the Enabled property like the script below.  This example is for updating a single action, but you could adapt it to handle multiple actions for a bulk update.

Import-Module SwisPowerShell


# Connect to SWIS.

$hostname = "myserver"

$username = "muser"

$password = "superSecretPassword"

$swis = Connect-Swis -host $hostname -Username $Username -Password $Password


# Get the URI of an action associated with an alert configuration.

# Tweak this query to find the alert action you care about.

$alertName = "Alert me when an application goes down"

$actionTypeID = "Email"

$query = "SELECT TOP 1 a.Uri

    FROM Orion.AlertConfigurations ac

    INNER JOIN Orion.ActionsAssignments aa ON ac.AlertID = aa.ParentID

    INNER JOIN Orion.Actions a ON aa.ActionAssignmentID = a.ActionID

    WHERE ac.Name = @alertName AND a.ActionTypeID = @actionTypeID"

$actionUri = Get-SwisData -SwisConnection $swis -Query $query -Parameters @{alertName = $alertName; actionTypeID = $actionTypeID}


# Do this...

# Disable the alert action.

$enabledProps = @{

    Enabled = $false;

}

Set-SwisObject -SwisConnection $swis -Uri $actionUri -Properties $enabledProps | Out-Null


# ... Or do this...

# Enable the alert action.

$enabledProps = @{

    Enabled = $true;

}

Set-SwisObject -SwisConnection $swis -Uri $actionUri -Properties $enabledProps | Out-Null

View solution in original post

Perfect Dan, thanks!  I didn't know I could still just use the Set-SwisObject cmdlet.  Since there was a verb just for updating Alert Actions I thought that I had to use that.

0 Kudos