bitplaces / rundeck-slack-plugin

A Rundeck Plugin for Slack
Apache License 2.0
39 stars 91 forks source link

The 'Options' field is not properly escaped, fails when " some_key_without_value: " is present #8

Open sirkubax opened 7 years ago

sirkubax commented 7 years ago

It seems, that when in thetemplates/slack-message.ftl the value ${executionData.argstring} is a { 'key': value, 'key2': value, "some_key_without_value": }

Options: app: promo system_version_file: stg_default version_in_system_version_file: version_unknown diff: --diff dont_enable_after_deploy: false dry_run: disable_nagios_probe: True version_override: 0.9.926 verbose: -v

a dry_run: is not empty, it contains ' ' whitespace :) yet it should be escaped...

The slack reject the output. Is this a Slack issue, or a rundeck-slack plugin escaping issue?


2017-04-13 09:02:11,316 [quartzScheduler_Worker-7] ERROR grails.app.services.rundeck.services.NotificationService - Error sending notification: Notification{eventTrigger='onstart', type='SlackNotification', content='{"username":"Rundeck","external_template":"slack-message.ftl","room":"#rundeck","teamDomain":"x","apiAuthToken":"y","icon_url":""}'}: class com.bitplaces.rundeck.plugins.slack.SlackNotificationPluginException: Unknown status returned from Slack API: [invalid_payload].
com.bitplaces.rundeck.plugins.slack.SlackNotificationPluginException: Unknown status returned from Slack API: [invalid_payload].
        at com.bitplaces.rundeck.plugins.slack.SlackNotificationPlugin.postNotification(SlackNotificationPlugin.java:179)
        at rundeck.services.NotificationService.triggerPlugin(NotificationService.groovy:490)
        at rundeck.services.NotificationService$_triggerJobNotification_closure5.doCall(NotificationService.groovy:352)
        at rundeck.services.NotificationService.triggerJobNotification(NotificationService.groovy:147)
        at rundeck.services.NotificationService$_triggerJobNotification_closure1.doCall(NotificationService.groovy:89)
        at rundeck.services.NotificationService.triggerJobNotification(NotificationService.groovy:86)
        at rundeck.services.ExecutionService.executeAsyncBegin(ExecutionService.groovy:959)
        at rundeck.quartzjobs.ExecutionJob.executeCommand(ExecutionJob.groovy:325)
        at rundeck.quartzjobs.ExecutionJob.execute_internal(ExecutionJob.groovy:143)
        at rundeck.quartzjobs.ExecutionJob$_execute_closure1.doCall(ExecutionJob.groovy:91)
        at com.codahale.metrics.Timer.time(Timer.java:99)
        at rundeck.quartzjobs.ExecutionJob.execute(ExecutionJob.groovy:90)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
sirkubax commented 7 years ago

This fixes the problem on the 'template level' :)

<#if (executionData.argstring)?has_content>
    ,{
      "title": "Options",
-      "value": "${executionData.argstring}",
+      "value": "${executionData.argstring?js_string?replace(":", "A")}",
      "short": false
    }
</#if>

Result:

Options: app: promo system_version_file: stg_default version_in_system_version_file: version_unknown diff: --diff dont_enable_after_deploy: false dry_run: disable_nagios_probe: True version_override: 0.9.926 verbose: -v

(do not ask me, why the replacment does not contain "A")

At Slack channel:

Options

-app promo -diff --diff -disable_nagios_probe True -dont_enable_after_deploy false -dry_run " " -system_version_file stg_default -verbose -v -version_in_system_version_file version_unknown -version_override 0.9.926

sirkubax commented 7 years ago

http://stackoverflow.com/questions/6383525/how-to-escape-json-strings-in-freemarker