ninxsoft / Kmart

A Mac command-line tool that generates kick-ass Jamf Pro reports.
MIT License
142 stars 12 forks source link

Feature request: Slack webhook support #7

Closed smashism closed 3 years ago

smashism commented 3 years ago

Hi, it'd be really handy if there was an export that could post results via a Slack webhook into a channel (with flags for webhook URL, username, icon/emoji icon, etc.).

ninxsoft commented 3 years ago

💯 agree, Slack integration would be an awesome feature!

I haven't actually played with the Slack API, however after a quick scan of the docs it appears I can get away with the following config options:

{
  "name": "KMART Report",
  "url": "https://myorg.jamfcloud.com",
  "credentials": "base_64_encoded_username:password",
  "slack": {
    "enabled": true,
    "webhook_url": "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
    "token": "xoxb-your-token",
    "channel": "channel_name",
    "text": "KMART Report has been generated!",
    "username": "username",
    "icon_url": "https://icon.url",
    "icon_emoji": ":white_check_mark:",
    "attachments": {
      "json": "filename.json",
      "plist": "filename.plist",
      "yaml": "filename.yaml",
      "markdown": "filename.md",
      "html": "filename.html"
    }
  }
}

If a webhook_url is empty or not specified, use the default Slack API endpoint (token, channel, etc.).

@smashism do you have a preference or specific use case for Webhooks over the standard Slack API ?

smashism commented 3 years ago

I'd be fine with a webhook but I'm also a simple creature.

ninxsoft commented 3 years ago

Here's a screenshot of Slack successfully receiving KMART report file uploads:

Slack

Note: File Uploads are not possible via Webhooks, so instead the following fields are now required:

{
  "name": "KMART Report",
  "url": "https://myorg.jamfcloud.com",
  "credentials": "base_64_encoded_username:password",
  "slack": {
    "enabled": true,
    "token": "xoxb-your-token",
    "channel": "channel_name_or_id",
    "text": "Custom Slack message supporting Markdown and Emoji",
    "attachments": [
      "json",
      "plist",
      "yaml",
      "markdown",
      "html"
    ]
  }
}
ninxsoft commented 3 years ago

Fixed in #11