hikerspath
8/21/2019 - 4:38 PM

Integromat: Slack to OpsGenie

So the goal here is to be able to create a toolset that will be re-usable based on the reporting webhook from slack and split-processing it both into an OpsGenie Page for those that would like to have advanced notification and into a specially format

1. Create Automation Senario

This step will create the automation pipeline in order of operation.

1.1. Webhook Trigger (In Integromat)

In integromat, create a new senario and add a webhook trigger:

  1. After creating a senario, click on the ? bubble to define the triggering action.
  2. Add a 'Custom webhook' trigger as the first step in the automation pipeline. This will be an INSTANT trigger that will execute whenever integromat receives data.
  3. Configure a new inbound webhook called Slack - Outgoing Webhook so you will know what will be sending data inbound.
  4. Set 'Max number of results' to 3
  5. Copy the actual hook address (EX: https://hook.integromat.com/____hash____) as you will need it in the next step.
  6. Click 'Ok'

1.2. Create Outgoing Webhook (In Slack)

  1. Assuming you are logged in on slack in your browser, you should be able to access the outgoing webhooks endpoints: https://meltwater.slack.com/apps/A0F7VRG6Q-outgoing-webhooks
    • If watching "#fou-drone-service" you can just add your triggers webhook to the URL(s) list (one per line) found in the #fou-drone-service outgoing webhook and add your local user-id in a Hey <@__user_id__> CSV match list
    • If watching "#fou-grafana-service" you can just add your triggers webhook to the URL(s) list (one per line) found in the #fou-grafana-service outgoing webhook and add your local user-id in a Hey <@__user_id__> CSV match list
    • If watching "#foundation-mission" you can just add your triggers webhook to the URL(s) list (one per line) found in the #foundation-mission outgoing webhook and add your local user-id in a Hey <@__user_id__> CSV match list
    • If you are watching something new or just want work-load separation, feel free to create your own
  2. Assuming you have elected to create your own and have already clicked on the add button, the following base configs may help.
    1. Channel should be set to a single chatroom you want to monitor
    2. Trigger Word(S) match from the beginning of the line, so we really have no choice but to watch tails threaded ping since that will always hold the format of ^Hey <@__oncall_user__> ! <@__requestor__> said: __original_message_ (EX: Hey <@UA7T176Y5>)
    3. URL(s) should contain the webhook URL you created in step 1.1.
    4. Token used for verification / anti-spam if you need it, I don't use this feature yet
    5. Descriptive Label Should be something similar to Team: channel-name (EX: A-Team: fou-drone-service)
    6. Customize Name Should reflect the service Integromat: Team (EX: Integromat: A-Team)
    7. Cuztomize Icon If you want the actual logo you can use https://logo.clearbit.com/integromat.com
    8. Translate User IDs Make sure you take the global ID's and shift them to the local workspace ones (easier to parse)
  3. Click 'Save settings'

1.3. Test Webhook (Slack / Integromat)

  1. In Integromat, set the 'Run once' trigger so that you can parse out sample data (saves having to build a data structure)
  2. In the slack room you added, trigger the message by sending a Hey @__your_id_here__
  3. In Integromat you should observe an execution which will have populated the webhook with data it will use from that point forward.

1.4. Add a Text Parsing Tool (In Integromat)

  1. Using the 'Tools' menu, add a 'Match pattern' text parsing module
  2. Attach it to the previous entry in the workflow
  3. Set the Pattern to .*!\s+<@(.*)>\s+said.* (will match all 'Tails' pings)
  4. Ensure Case sensitive option is only one selected.
  5. Set the Text box to the text field from the webhook
  6. Click 'Ok'
  7. Right-click on the module and 'Rename' it to 'Find (Real Requestor)'

1.5. Add a HTTP Request Operation (In Integromat)

  1. Ok, I lied, you will need to get your token for the slack API
  2. Add a new 'HTTP' module with a 'Make a request' option
  3. Attach it to the previous entry in the workflow
  4. URL should be set to the value you copied with the 'user' parameter edited to be the drop-in $1 from the previous match
  5. Click 'Ok'
  6. Right-Click on the module and 'Rename' to Slack (Real Requestor)

1.6. Add a JSON Parser Operation (In Integromat)

  1. Add a new 'JSON' module with a 'Parse JSON' option
  2. Attach it to the previous entry in the workflow
  3. Leave the Data structure field empty so that it is dynamic
  4. Ensure the JSON string segment is populated with the Data from the HTTP call in the prior step.
  5. Click 'Ok'
  6. Right-Click on the module and 'Rename' it to JSON (Requestor)

1.7. Test Webhook (Slack / Integromat)

  1. In Integromat, set the 'Run once' trigger so that you can parse out sample data (saves having to build a data structure)
  2. In the slack room you added, trigger the message by sending a Hey @__your_id_here__
  3. In Integromat you should observe an execution which will have populated the webhook with data it will use from that point forward.

1.8. Add a HTTP Request Operation (In Integromat)

  1. Add a new 'HTTP' module with a 'Make a request' option
  2. Attach it to the JSON (Requestor) module in the workflow
  3. Check the Show advanced settings checkbox
  4. Ensure the Evaluate all states as errors checkbox is checked
  5. URL should be set to https://api.opsgenie.com/v2/alerts
  6. Method should be set to POST
  7. Body type should be set to Raw
  8. Content type should be set to JSON (application/json)
  9. Headers should be set to a team-owned API integration in OpsGenie
    • Navigate to team dashboard in OpsGenie
    • Choose 'Integrations' from the navigation bar
    • Choose 'Add Integration' (unless you are reusing or already have one)
    • Copy the API Key from the 'Settings' of the integration you have added / edited
    • Click the 'Add a header' +
    • Set Name to Authorization
    • Set the Value to GenieKey __copied_api_key_from_opsgenie__
  10. Check the Reject connections that are using unverified certs
  11. Check the Disable serialization of multiple same query string keys as arrays
  12. Check the Requet compressed content
  13. Request content should be set to:
{
 "message": "Slack Alert ({{6.channel_name}})",
 "alias": "slack/__opsgenie_team__/{{6.channel_name}}",
 "description":"Help {{27.user.real_name}} in #{{6.channel_name}} thread https://{{6.team_domain}}.slack.com/archives/{{6.channel_id}}/p{{6.timestamp}}",
 "responders":[{
   "username":"__your_email_address__",
   "type":"user"
 }],
 "visibleTo":[{
   "name":"__opsgenie_team__",
   "type":"team"
 }],
 "tags": [
   "slack",
   "mention",
   "{{6.channel_name}}"
 ],
 "entity":"{{ifempty(27.user.profile.email; 27.user.real_name)}}"
}

Once you are done adding the HTML above, there are a couple steps to remember.

  1. Click 'Ok' to save or it won't
  2. Right click on the module and rename it to 'OpsGenie (Alert)'
  3. Click on the connector between the router and the OpsGenie (Alert) modules and filter down to the userID's that actually want to be paged.

2. Filtering Inbound Traffic

To ensure that nobody else is sending you messages you don't want...

  1. Click on the connector between the webhook and the initial text parser for the 'Find (Real Requestor)'
  2. Filter on the following:
    • user_id of the webhook equals UB6SQ901L (the tails uid)
    • AND
    • trigger_word of the webhook contains your own personal uid