Skip to content

Slack Ops with Maira

Usually, Slack apps are either provided to dump notifications to a slack channel, or to run some simple slash commands from within slack. Very few apps provide a complete all round experience that is provided by Maira Slack app. Maira has a very powerful slack app that provides functionalities such as:

  • Sending messages from within your workflows to a user or channel.
  • Asking a question from a user or on a channel and use the response to decide next steps of your workflow.
  • Taking survey of users on a slack channel. The workflow can wait till a specified time or untill pre-defined number of responses have been received.
  • Send mpl command to Maira from within slack.
  • Interact with Maira using at-mentions (@Maira) that can run your commands and send a response.
  • Interact with Maira using shortcuts to run commands or entire playbooks.
  • Create/manage channels from within your workflows to create instant war-rooms for your incidents.

Using the above, you can use a large part of functionality from within Slack itself. You can share the output of commands with your co-workers, manage your cluster from within slack or respond to confirmations for actions from workflows.

Maira Slack App

Maira Slack Integration

Installation

If you would like to use Maira's slack app, the first step is install Maira app in your slack workspace by clicking on Add to Slack

Once added to your slack workspace, you can issue /mpl login command to connect slack user with maira user. This will open a browser session where you can enter your Maira credentials to link your Maira identity with your Slack identicy. Once user connection is successful, you can use /mpl help command to get help with maira.

From now on, all commands that you run from within Slack will use the same Access Control as configured on Maira UI.

You can logout using /mpl logout if you would like to disconnect or if you would like to login with different credentials.

Slash commands

Once you have connected your slack identity with your Maira identity, you can run slash commands that will execute MPL commands on Maira Cloud. To run these, you can run command like /mpl !k8s list-pods in Slack input box. Below is an example of the output you can expect.

Slash commands

As you can see from the example, you can assign values to variables and the system remembers those values. This allows user to use those variables in a subsequent call, making this a session like one from MPL REPL shell. You can start a new session by issuing /mpl session-new command. For list of available commands, use /mpl help.

Internally Maira resumes the session before executing any command user enters in slack. Infact the session called slack can be resumed in mpl console with all the states intact.

> mpl -r slack
Resumed session: slack
mpl> /history
   1  !k8s list-pods
   2  x = !k8s list-pods
   3  print x[].containers[0].name

mpl> /!3
print x[].containers[0].name
"hello-python",
"hello-python",
"maira-gateway"

Issuing slack commands from your workflows

Besides accessing Maira commands from within workflows, you can also use slack as a tool to involve users in your workflows. Maira supports notifying users, asking a question, surveying the users, managing channels etc.

Notifying users on slack

You can notify any slack channel or user (who have connected their slack identity with Maira identity) using a command in your workflow. To do that, use a command like this:

!slack ask --message "Test message from Maira App --name "#general"

This should show a notification in the #general channel in your slack workspace like this:

Asking a question from a user or channel

You can use slack as a convenient way to ask a question about anything. Based on the answer, the workflow can take different paths. Here is an example:

opt = json ["disable", "reset password", "ignore"]
x = !slack ask --message msg --name slack_user --options opt --timeout "1 hour" --retry_interval "20 m"
if x == "disable":
    ...

This will send a message that looks like the following: Slack ask command

Maira will also send a reminder every 20 minutes up to 3 times if no response is received. The workflow will wait for response and continue automatically when a response is received. There is no need to explicitly save state and/or poll.

Surveying multiple users or channels

A slight variation of the ask command allows you to send a survey to multiple users or channels. It will wait until a response has been received from all users/channels up to specified timeout. After that, the workflow will receive results as a JSON object and can take different steps based on the responses. Below is an example:

opt = json ["disable", "reset password", "ignore"]
users = json ["@alice", "@bob"]
x = !slack survey --message msg --name users --options opt --timeout "1 hour" --retry_interval "20 m"

if x["@alice"] == "disable" && x["@bob"] == "disable":
    ...

Channel management

Maira Slack app allows you to manage slack channels right from your workflows. This allows you to do things like creating a new channel for a high priority incident and assign users to it. You can also send periodic updates on the channel until the incident is resolved. For this, Maira provides commands to list channels, users, creating channels, and updating users. For a complete listing of our slack commands, please refer to our Command Documentation for Slack.

Auto-completion of command arguments

Like most other Maira commands, when running from MPL REPL shell, Maira will dynamically auto-complete the arguments so that you don't have to remember the available channel and user names. Please see below screenshot for an example.

Command completion

Command completion

Shortcuts

It is easy to make a few errors/mistakes while typing the full command for a service in slack. To ease the access of Maira/MPL commands, the slack app provides a shortcut features which helps to: * remove dependency on typing the complete exact command for a service and instead use a UI designed specifically for this. * run all Maira services using simple modals having dropdown options and input fields to select and use your specific service such as Kubernetes, Kafka, Prometheus, etc.

As you can see from the above screenshots, the entire Maira command library is available as slack shortcut along with help for each parameter.

In addition, Maira slack app also provides another shortcut to execute multi-line workflows as seen below.