Posting URL alerts to a Slack channel 

Post URL alerts to one or more Slack channels.

Post URL alerts to one or more Slack channels.

Multiple instances of the config_locationslack_posturl.conf file results in multiple instances of the event plugin. The Slack configuration file can have any name provided the file has the .conf file extension, contains the valid event plugin identifier [posturl], and resides in the event-plugins directory location. All configuration files are loaded, so differentiate the file names such as slack_posturl1.conf, slack_posturl2.conf, and so on. Multiple plugin instances facilitate flexibility when setting up alerts to different Slack channels for development and production clusters. All OpsCenter event plugins support multiple configurations files and subsequent plugin instances.

Prerequisites

Set up an incoming webhook integration using slack. For instructions, refer to the slack API.

Procedure

  1. Create a new file slack_posturl.conf in the conf/event-plugins/ directory.
  2. Copy and paste the contents from the example below into the file.

    Example slack_posturl.conf:

    [posturl]
    enabled=1
    
    # levels can be comma-delimited list of any of the following:
    # DEBUG,INFO,WARN,ERROR,CRITICAL,ALERT
    # If left empty, will listen for all levels
    levels=
    
    # clusters is a comma-delimited list of cluster names for which
    # this alert config will be eligible to run.
    # If left empty, this alert will be called for events on all clusters
    clusters=
    
    # the URL to send an HTTP POST to
    url=https://hooks.slack.com/services/your/webhook/url
    
    # Set a username for basic HTTP authorization
    #username=foo
    
    # Set a password for basic HTTP authorization
    #password=bar
    
    # The number of seconds before a connection to url or proxy_url
    # will be aborted due to a timeout
    connection_timeout=5
    
    # Set the type of posted data. Available options are 'json' or 'form'
    post_type=json
    
    # Fields specified here will override the default event data fields.
    #
    # They must be formatted as key-value pair, with key and value separated by
    # an equals (=). Each pair after the first must be on its own line,
    # indented beyond the first line
    #
    # You may use tokens found within the default event data for or in
    # values. For example, some available keys are:
    #   cluster, time, level_str, message, target_node, event_source, success, api_source_ip, user, source_node
    # Keys must be encapsulated in {brackets}.
    #
    #fields=textKey=value
    #    mixedKey=cluster-{cluster}
    #    event-msg={message}
    fields=text={level_str} from {cluster}: {message}
    
    # Customizable templates for http post data. Some available keys are:
    #     node, cluster, datetime, level_str, message, target_node, event_source, success, api_source_ip, user, source_node
    # More advanced formatting options explained here: https://docs.python.org/2/library/string.html#formatspec Each line
    # beyond the first must be indented. Use with post_type=template, and content-type and other headers must be manually
    # assigned.
    #template={{
    #  "messages":[
    #    {{
    #      "type": "link",
    #      "message": "Cluster {cluster} failure - {message}"
    #      "href": "http://opscenter1"
    #    }}
    #  ]}}
    
  3. Required: Ensure that the URL in the example config file url=https://hooks.slack.com/services/your/webhook/url is replaced with your custom-defined incoming webhook URL.
  4. Save slack_posturl.conf and restart the OpsCenter daemon.
    Verify alerts are getting populated in the slack channel that you defined for your webhook.