Post alerts to slack.com


(default-formatter events)

Simple formatter for rendering an event as a Slack attachment.


(extended-formatter events)

Format an event as a Slack attachment with a series of fields.


(slack account_name token username channel)(slack account-info message-info)(slack {:keys [webhook_uri account token]} {:keys [username channel icon formatter], :or {formatter default-formatter}} http-params)

Posts events into a slack.com channel using Incoming Webhooks. Takes your account name, webhook token, bot username and channel name. Returns a function that will post a message into slack.com channel:

(def credentials {:account “some_org”, :token “53CR3T”}) (def slacker (slack credentials {:username “Riemann bot” :channel “#monitoring” :icon “:smile:”}))

(by [:service] slacker)

Hint: token is the last part of the webhook URL that Slack gives you. https://hooks.slack.com/services/QWERSAFG0/AFOIUYTQ48/120984SAFJSFR Token in this case would be 120984SAFJSFR

You can also supply a custom formatter for formatting events into Slack messages. Formatter result may contain:

  • username - overrides the username provided upon construction
  • channel - overrides the channel provided upon construction
  • icon - overrides the icon provided upon construction
  • text - main text formatted using Slack markup
  • attachments - array of attachments according to https://api.slack.com/docs/attachments

(def slacker (slack credentials {:username “Riemann bot”, :channel “#monitoring” :formatter (fn [e] {:text (:state e) :icon “:happy:”})))

You can use slack inside of a grouping function which produces a seq of events, like rollup:

(def slacker (slack credentials {:username “Riemann bot”, :channel “#monitoring” :formatter (fn [es] {:text (apply str (map :state es))})))

(rollup 5 60 slacker)

The last parameter of the arity-3 version of the function is a map of parameters passed directly to clj-http. For example, you can set socket and connection timeouts like so:

(slack {…} {…} {:socket-timeout 1000 :conn-timeout 1000})


(slack-escape message)

Escape message according to slack formatting spec.


(slack-fallback events)

Minimal, plain-text event formatting. Used for dumb clients such as IRC.