RamblingCookieMonster / Psslack

Licence: mit
PowerShell module for simple Slack integration

Programming Languages

powershell
5483 projects

Projects that are alternatives of or similar to Psslack

Diun
Receive notifications when an image is updated on a Docker registry
Stars: ✭ 704 (+204.76%)
Mutual labels:  slack, notifications
Craft Brief
Quick, easy, and customizable user-group notifications for Craft CMS.
Stars: ✭ 47 (-79.65%)
Mutual labels:  slack, notifications
Notify
A dead simple Go library for sending notifications to various messaging services.
Stars: ✭ 727 (+214.72%)
Mutual labels:  slack, notifications
Chronos
📊 📊 📊 Monitors the health and web traffic of servers, microservices, and containers with real-time data monitoring and receive automated notifications over Slack or email.
Stars: ✭ 347 (+50.22%)
Mutual labels:  slack, notifications
Tfsnotificationrelay
An extensible plugin for TFS that sends notifications to Slack, HipChat and IRC
Stars: ✭ 120 (-48.05%)
Mutual labels:  slack, notifications
Alertmanager
Prometheus Alertmanager
Stars: ✭ 4,574 (+1880.09%)
Mutual labels:  slack, notifications
Synology Notifications
Synology notifications service
Stars: ✭ 47 (-79.65%)
Mutual labels:  slack, notifications
Yii2 Slack Log
Pretty Slack log target for Yii 2
Stars: ✭ 24 (-89.61%)
Mutual labels:  slack, notifications
Statusok
Monitor your Website and APIs from your Computer. Get Notified through Slack, E-mail when your server is down or response time is more than expected.
Stars: ✭ 1,522 (+558.87%)
Mutual labels:  slack, notifications
Ravenx
Notification dispatch library for Elixir applications
Stars: ✭ 100 (-56.71%)
Mutual labels:  slack, notifications
Laravel Slack Slash Command
Make a Laravel app respond to a slash command from Slack
Stars: ✭ 215 (-6.93%)
Mutual labels:  slack, notifications
Yfiton
Cross-platform CLI utility command for sending notifications using well-known or modern communication services
Stars: ✭ 142 (-38.53%)
Mutual labels:  slack, notifications
slack-texts
SMS notifications for Slack groups
Stars: ✭ 19 (-91.77%)
Mutual labels:  notifications, slack
Laravel Failed Job Monitor
Get notified when a queued job fails
Stars: ✭ 582 (+151.95%)
Mutual labels:  slack, notifications
Gocd Slack Build Notifier
GoCD (gocd.org) plugin to push build notifications to Slack
Stars: ✭ 96 (-58.44%)
Mutual labels:  slack, notifications
Server Monitor App
A PHP application to monitor the health of your servers
Stars: ✭ 141 (-38.96%)
Mutual labels:  slack, notifications
Uptime Monitor App
A PHP application to monitor uptime and ssl certificates
Stars: ✭ 205 (-11.26%)
Mutual labels:  slack, notifications
Rspec Nc
🚦 RSpec formatter for OS X's Notification Center
Stars: ✭ 223 (-3.46%)
Mutual labels:  notifications
Notica
Send browser notifications from your terminal. No installation. No registration.
Stars: ✭ 215 (-6.93%)
Mutual labels:  notifications
Sactive Bot
😈 An extensible chat bot framework. sactive-bot is an evolution of the open source hubot project. - https://www.shipengqi.top/sactive-bot .
Stars: ✭ 212 (-8.23%)
Mutual labels:  slack

Build status

PSSlack

This is a quick and dirty module to interact with the Slack API.

Pull requests and other contributions would be welcome!

Instructions

# One time setup
    # Download the repository
    # Unblock the zip
    # Extract the PSSlack folder to a module path (e.g. $env:USERPROFILE\Documents\WindowsPowerShell\Modules\)
# Or, with PowerShell 5 or later or PowerShellGet:
    Install-Module PSSlack

# Import the module.
    Import-Module PSSlack    #Alternatively, Import-Module \\Path\To\PSSlack

# Get commands in the module
    Get-Command -Module PSSlack

# Get help
    Get-Help Send-SlackMessage -Full
    Get-Help about_PSSlack

Prerequisites

Examples

Send a Simple Slack Message

# This example shows a crudely crafted message without any attachments,
# using parameters from Send-SlackMessage to construct the message.

#Previously set up Uri from https://<YOUR TEAM>.slack.com/apps/A0F7XDUAZ
$Uri = "Some incoming webhook uri from Slack"

Send-SlackMessage -Uri $Uri `
                  -Channel '@wframe' `
                  -Parse full `
                  -Text 'Hello @wframe, join me in #devnull!'

# Send a message to @wframe (not a channel), parsing the text to linkify usernames and channels

      Simple Send-SlackMessage

Search for a Slack Message

# Search for a message containing PowerShell, sorting results by timestamp

Find-SlackMessage -Token $Token `
                  -Query 'PowerShell' `
                  -SortBy timestamp

      Find Message

# Search for a message containing PowerShell
# Results are sorted by best match by default
# Notice the extra properties and previous/next messages

Find-SlackMessage -Token $Token `
                  -Query 'PowerShell' |
    Select-Object -Property *

      Find Message Select All

You could use this simply to search Slack from the CLI, or in an automated solution that might avoid posting if certain content is already found in Slack.

Send a Richer Slack Message

# This is a simple example illustrating some common options
# when constructing a message attachment
# giving you a richer message

$Token = 'A token. maybe from https://api.slack.com/docs/oauth-test-tokens'

New-SlackMessageAttachment -Color $([System.Drawing.Color]::red) `
                           -Title 'The System Is Down' `
                           -TitleLink https://www.youtube.com/watch?v=TmpRs7xN06Q `
                           -Text 'Please Do The Needful' `
                           -Pretext 'Everything is broken' `
                           -AuthorName 'SCOM Bot' `
                           -AuthorIcon 'http://ramblingcookiemonster.github.io/images/tools/wrench.png' `
                           -Fallback 'Your client is bad' |
    New-SlackMessage -Channel '@wframe' `
                     -IconEmoji 💣 |
    Send-SlackMessage -Token $Token

      Rich messages

Notice that the title is clickable. You might link to...

  • The alert in question
  • A logging solution query
  • A dashboard
  • Some other contextual link
  • Strongbad

Send Multiple Slack Attachments

# This example demonstrates that you can chain new attachments
# together to form a multi-attachment message

$Token = 'A token. maybe from https://api.slack.com/docs/oauth-test-tokens'

New-SlackMessageAttachment -Color $_PSSlackColorMap.red `
                           -Title 'The System Is Down' `
                           -TitleLink https://www.youtube.com/watch?v=TmpRs7xN06Q `
                           -Text 'Everybody panic!' `
                           -Pretext 'Everything is broken' `
                           -Fallback 'Your client is bad' |
    New-SlackMessageAttachment -Color $([System.Drawing.Color]::Orange) `
                               -Title 'The Other System Is Down' `
                               -TitleLink https://www.youtube.com/watch?v=TmpRs7xN06Q `
                               -Text 'Please Do The Needful' `
                               -Fallback 'Your client is bad' |
    New-SlackMessage -Channel '@wframe' `
                     -IconEmoji 💣 `
                     -AsUser `
                     -Username 'SCOM Bot' |
    Send-SlackMessage -Token $Token

      Multiple Attachments

Notice that we can chain multiple New-SlackMessageAttachments together.

Send a Table of Key Value Pairs

# This example illustrates a pattern where you might
# want to send output from a script; you might
# include errors, successful items, or other output

# Pretend we're in a script, and caught an exception of some sort
$Fail = [pscustomobject]@{
    samaccountname = 'bob'
    operation = 'Remove privileges'
    status = "An error message"
    timestamp = (Get-Date).ToString()
}

# Create an array from the properties in our fail object
$Fields = @()
foreach($Prop in $Fail.psobject.Properties.Name)
{
    $Fields += @{
        title = $Prop
        value = $Fail.$Prop
        short = $true
    }
}

$Token = 'A token. maybe from https://api.slack.com/docs/oauth-test-tokens'

# Construct and send the message!
New-SlackMessageAttachment -Color $([System.Drawing.Color]::Orange) `
                           -Title 'Failed to process account' `
                           -Fields $Fields `
                           -Fallback 'Your client is bad' |
    New-SlackMessage -Channel 'devnull' |
    Send-SlackMessage -Uri $uri

# We build up a pretend error object, and send each property to a 'Fields' array
# Creates an attachment with the fields from our error
# Creates a message fromthat attachment and sents it with a uri

      Fields

Store and Retrieve Configs

To save time and typing, you can save a token or uri to a config file (protected via DPAPI) and a module variable.

This is used as the default for commands, and is reloaded if you open a new PowerShell session.

# Save a Uri and Token.
# If both are specified, token takes precedence.
Set-PSSlackConfig -Uri 'SomeSlackUri' -Token 'SomeSlackToken'

# Read the current cofig
Get-PSSlackConfig

Notes

Currently evaluating .NET Core / Cross-platform functionality. The following will not work initially:

  • Serialization of URIs and tokens via Set-PSSlackConfig. Set these values per-session if needed
  • [System.Drawing.Color]::SomeColor shortcut. Use the provided $_PSSlackColorMap hash to simplify this. E.g. $_PSSlackColorMap.red

There are a good number of Slack functions out there, including jgigler's PowerShell.Slack and Steven Murawski's Slack. We borrowed some ideas and code from these - thank you!

If you want to go beyond interacting with the Slack API, you might consider using a bot

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].