If you missed the pre-registration for NetApp MS Azure AD B2C, the new login prompt will offer the option to register. Please note that access to your NetApp data may take up to 1 hour.
To learn more, read the FAQ and watch the video.
Need assistance? Complete this form and select “Registration Issue” as the Feedback Category.

Active IQ Unified Manager Discussions

Slack Integration from WFA

FRAZERBRADBURN

Hi, I am looking at sending notifications from WFA into slack channels. So rather than using the current mail code I'll be looking at trying to write something to hit a slack channel. 

 

I'm wondering before I begin if anyone has something written already? I have an easy enough powershell script which does that but I'm learning how to invoke these in WFA atm. 

 

 

1 REPLY 1

mbeattie

Hi Frazer,

 

It's possible in PowerShell (like this example) so it should be possible in WFA.

I would "guess" it's something like this (though I've not tested it):

 

Param(
   [Parameter(Mandatory=$True, HelpMessage="The slack URI")] 
   [String]$Uri,
   [Parameter(Mandatory=$True, HelpMessage="The slack hostname, FQDN or IP address for authentication")] 
   [String]$HostName,
   [Parameter(Mandatory=$True, HelpMessage="The slack channel name")] 
   [String]$ChannelName,
   [Parameter(Mandatory=$True, HelpMessage="The slack channel message")] 
   [String]$Message,
   [Parameter(Mandatory=$True, HelpMessage="The slack channel icon")] 
   [String]$Icon
)
#'------------------------------------------------------------------------------
#'Enumerate the slack credentials from the WFA credential cache.
#'------------------------------------------------------------------------------
$Credentials = Get-WFACredentials $HostName
[String]$userName = $Credentials.GetNetworkCredential().Username
$BodyTemplate = @"
   {
      "channel": "$ChannelName",
      "username": "$userName",
      "text": "$Message. \nTime: DATETIME.",
      "icon_emoji":":$Icon:"
   }
"@
#'------------------------------------------------------------------------------
#'Send the message to the slack channel.
#'------------------------------------------------------------------------------
Try{
   Invoke-RestMethod -uri $Uri -Method Post -body $body -ContentType "application/json" -Credential $Credentials -ErrorAction Stop
   Get-WFALogger -Info -Message "Sent message ""$Message"" to slack channel ""$ChannelName"" using URI ""$Uri"""
}Catch{
   Get-WFALogger -Error -Message $("Failed invoking URI ""$Uri"". Error " + $_.Exception.Message)
   Throw "Failed sending message ""$Message"" to slack channel ""$ChannelName"" using URI ""$Uri"""
}
#'------------------------------------------------------------------------------

In addition to the PowerShell code link, I would assume the REST POST method would require authentication hence i added the $HostName parameter which is used to retrieve a WFA credential object for invoking the REST API.

EG add a WFA credential using 'hooks.slack.com' and the username (EG #wfaslackbot)

 

Hope that helps

 

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.
Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

Public