Giter Site home page Giter Site logo

rundeck-diy-webhook-notification's Introduction

rundeck-diy-webhook-notification

Rundeck notification plugin for the DIYer, because it allows you to supply your own custom messages to be sent to a webhook.

Installation

  1. Download the plugin file
wget "https://github.com/theque5t/rundeck-diy-webhook-notification/raw/master/build/libs/rundeck-diy-webhook-notification-1.0.0.jar"
  1. Put the plugin file, rundeck-diy-webhook-notification-1.0.0.jar, into the plugin directory
mv rundeck-diy-webhook-notification-1.0.0.jar /var/lib/rundeck/libext
  1. The plugin is now ready for use

Usage

Provider Name: DIYWebhookNotificationPlugin

Plugin Properties:

  • Webhook URL: The webhook url. Example: https://hostname/services/TXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX
    configure project: project.plugin.Notification.DIYWebhookNotificationPlugin.webhookUrl=••••••••
    configure framework: framework.plugin.Notification.DIYWebhookNotificationPlugin.webhookUrl=••••••••

  • Content Type: The content type header. Example: application/json
    configure project: project.plugin.Notification.DIYWebhookNotificationPlugin.contentType=value
    configure framework: framework.plugin.Notification.DIYWebhookNotificationPlugin.contentType=value

  • Message Body: The message body. Example: {"text":"Hello world!"}
    configure project: project.plugin.Notification.DIYWebhookNotificationPlugin.messageBody=value
    configure framework: framework.plugin.Notification.DIYWebhookNotificationPlugin.messageBody=value

picture


Building the Message

The execution order and summary of what occurs when building the final message body is as follows:

  1. Any embedded property references will be replaced with the runtime value.
  2. Any execution data references will be replaced with the runtime value.
  3. Any template markup will be rendered.

Embedded Property References

You can add embedded property references to your message following this syntax: ${group.key}

Example for "On Start":

{"text":"Job ${job.name}(#${job.execid}): Started"}
${job.name} and ${job.execid} from the above example are embedded property references

Execution Data References

You can add execution data references to your message following this syntax: $map.key$

Examples:

{"text":"Job ${job.name}(#${job.execid}): $execution.status$"}
$execution.status$ from the above example is an execution data reference
{"text":"Job ${job.name}(#$execution.id$): $execution.status$"}
$execution.id$ and $execution.status$ from the above example are execution data references
{"text":"Job ${job.name}(#${job.execid}) from Group $execution.context.job.group$: $execution.status$"}
$execution.context.job.group$ and $execution.status$ from the above example are execution data references

Refer here and here to see what data is available. You can also supply a reference that equals an entire map. For example:

{"text":"Job: ${job.name}
Id: $execution.job.id$
Status: $execution.status$
Job Details: $execution.job$"}
$execution.job$ from the above example points to the job map

Template Markup

You can add template markup following the template language syntax.

Example:

{"text":"Job ${job.name}(#${job.execid}): {{ "$execution.status$" | capitalize }}"}
{{ "$execution.status$" | capitalize }} from the above example is template markup

Refer to the documentation for designers for further assistance with the template language.


Slack Example

Webhook URL: https://hooks.slack.com/services/TXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX

Content Type: application/json

Message Body:

{
        "username": "Rundeck",
        "icon_url": "https://github.com/theque5t/rundeck-diy-webhook-notification/raw/master/docs/images/rundeck.png",
        "channel": "#test",
        "attachments": [
          {
            "fallback":"*$execution.job.name$* (<$execution.href$|#$execution.id$>) {% assign status = "$execution.status$" | capitalize | prepend: "*" | append: "*" %}{% if status == '*Running*' %}{{ status | append: " :warning:" }}{% elsif status == '*Succeeded*' %}{{ status | append: " :heavy_check_mark:" }}{% else %}{{ status | append: " :heavy_multiplication_x:" }}{% endif %}",
            "pretext":"*$execution.job.name$* (<$execution.href$|#$execution.id$>) {% assign status = "$execution.status$" | capitalize | prepend: "*" | append: "*" %}{% if status == '*Running*' %}{{ status | append: " :warning:" }}{% elsif status == '*Succeeded*' %}{{ status | append: " :heavy_check_mark:" }}{% else %}{{ status | append: " :heavy_multiplication_x:" }}{% endif %}",
            "color":"{% if status == '*Running*' %}warning{% elsif status == '*Succeeded*' %}good{% else %}danger{% endif %}",
            "fields":[
          {
            "title":"Job Name",
            "value":"<$execution.job.href$|$execution.job.name$>",
            "short":true
          },
          {
            "title":"Project",
            "value":"$job.project$",
            "short":true
          },
          {
            "title":"Execution ID",
            "value":"<$execution.href$|#$execution.id$>",
            "short":true
          },
          {
            "title":"Started By",
            "value":"{% assign user = "$execution.user$" %}{% if user == 'admin' %}<@XX00XXX0X>{% else %}{{ user }}{% endif %}",
            "short":true
          }{% assign optionMap = "$execution.context.option$" %}{% if optionMap == '{}' %}{% else %},
          {
            "title":"Options",
            "value":"{% assign lengthMinusTwo = optionMap | size | minus: 2 %}{% assign options = optionMap | slice: 1, lengthMinusTwo %}{% assign options = options | split: ", " | reverse %}{% for option in options %} •  {{ option | replace_first: '=', ': `' }}`\n{% endfor %}",
            "short":true
          }
          {% endif %}
        ]
      }
    ]
}

Linking to the Slack user: "value":"{% assign user = "$execution.user$" %}{% if user == 'admin' %}<@XX00XXX0X>{% else %}{{ user }}{% endif %}" from the above example is template markup that replaces the Rundeck user value with the correlating Slack member ID. The Slack member ID can be found on their Slack profile. This shows how you can link the job notifications to the Rundeck user's Slack account.

picture


Acknowledgements

rundeck-diy-webhook-notification makes use of the open source projects listed on the index.md in the build/reports/dependency-license directory. Click here to be automatically redirected to the index.md.

rundeck-diy-webhook-notification's People

Contributors

theque5t avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.