diff --git a/README.md b/README.md index aa9ab2c..01b0fa1 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,11 @@ See the [rundeck documentation](http://rundeck.org/docs/manual/plugins.html#inst information on installing rundeck plugins. ## Configuration -This plugin uses Slack webhooks. Create a new webhook and copy the provided token. +This plugin uses Slack incoming webhooks integration. [Create a new webhook](https://demarque.slack.com/services/new) and copy the provided URL. ![configuration](config.png) -The only required configuration settings are: - -- `API Auth Token`: webhook token -- `Team Domain`: the `mycompany` part of `https://mycompany.slack.com` +The only required configuration setting is the webhook URL. Additionally you can set: @@ -78,4 +75,4 @@ You have three possibilties to enable slack icons for incoming web-hooks: * Original author: Hayden Bakkum @hbakkum * @totallyunknown * @notandy -* @lusis \ No newline at end of file +* @lusis diff --git a/config.png b/config.png index 197256c..f60bf5e 100644 Binary files a/config.png and b/config.png differ diff --git a/src/main/java/com/bitplaces/rundeck/plugins/slack/SlackNotificationPlugin.java b/src/main/java/com/bitplaces/rundeck/plugins/slack/SlackNotificationPlugin.java index 449fe4a..2d4fdbb 100644 --- a/src/main/java/com/bitplaces/rundeck/plugins/slack/SlackNotificationPlugin.java +++ b/src/main/java/com/bitplaces/rundeck/plugins/slack/SlackNotificationPlugin.java @@ -47,11 +47,6 @@ @PluginDescription(title="Slack", description="Sends Rundeck Notifications to Slack") public class SlackNotificationPlugin implements NotificationPlugin { - private static final String SLACK_API_BASE = ".slack.com/"; - private static final String SLACK_API_URL_SCHEMA = "https://"; - private static final String SLACK_API_WEHOOK_PATH = "services/hooks/incoming-webhook"; - private static final String SLACK_API_TOKEN = "?token=%s"; - private static final String SLACK_MESSAGE_COLOR_GREEN = "good"; private static final String SLACK_MESSAGE_COLOR_YELLOW = "warning"; private static final String SLACK_MESSAGE_COLOR_RED = "danger"; @@ -68,25 +63,19 @@ public class SlackNotificationPlugin implements NotificationPlugin { private static final Configuration FREEMARKER_CFG = new Configuration(); - - - @PluginProperty( - title = "API Auth Token", - description = "Slack API authentication token.", - required = true) - private String apiAuthToken; - @PluginProperty( - title = "Team Domain", - description = "Slack team domain.", - required = true) - private String teamDomain; + title = "Incoming webhook URL", + description = "Slack Incoming webhook URL", + required = true + ) + private String wh_url; @PluginProperty( title = "Channel", description = "Override default Slack channel to send notification message to.", required = false, - defaultValue = "#general") + defaultValue = "#general" + ) private String room; @PluginProperty( @@ -157,19 +146,13 @@ public boolean postNotification(String trigger, Map executionData, Map config) { throw new IllegalArgumentException("Unknown trigger type: [" + trigger + "]."); } - if (teamDomain.isEmpty()) { - throw new SlackNotificationPluginException( - "Slack teamDomain 'plugin.Notification.SlackNotification.teamDomain' missing in framework or project properties"); - } - - if (apiAuthToken.isEmpty()) { + if (wh_url.isEmpty()) { throw new SlackNotificationPluginException( - "Slack apiAuthToken 'plugin.Notification.SlackNotification.apiAuthToken' missing in framework or project properties"); + "Slack wh_url 'plugin.Notification.SlackNotification.wh_url' missing in framework or project properties"); } String message = generateMessage(trigger, executionData, config, room); - String token = String.format(SLACK_API_TOKEN, urlEncode(apiAuthToken)); - String slackResponse = invokeSlackAPIMethod(teamDomain, token, message); + String slackResponse = invokeSlackAPIMethod(wh_url, message); if ("ok".equals(slackResponse)) { return true; @@ -218,8 +201,8 @@ private String urlEncode(String s) { } } - private String invokeSlackAPIMethod(String teamDomain, String token, String message) { - URL requestUrl = toURL(SLACK_API_URL_SCHEMA + teamDomain + SLACK_API_BASE + SLACK_API_WEHOOK_PATH + token); + private String invokeSlackAPIMethod(String whurl, String message) { + URL requestUrl = toURL(whurl); HttpURLConnection connection = null; InputStream responseStream = null; @@ -241,7 +224,7 @@ private URL toURL(String url) { try { return new URL(url); } catch (MalformedURLException malformedURLEx) { - throw new SlackNotificationPluginException("Slack API URL is malformed: [" + malformedURLEx.getMessage() + "].", malformedURLEx); + throw new SlackNotificationPluginException("Slack webhook URL is malformed: [" + malformedURLEx.getMessage() + "].", malformedURLEx); } } @@ -292,7 +275,7 @@ private String getSlackResponse(InputStream responseStream) { try { return new Scanner(responseStream,"UTF-8").useDelimiter("\\A").next(); } catch (Exception ioEx) { - throw new SlackNotificationPluginException("Error reading Slack API JSON response: [" + ioEx.getMessage() + "].", ioEx); + throw new SlackNotificationPluginException("Error reading webhook JSON response: [" + ioEx.getMessage() + "].", ioEx); } }