Overview

This document will describe how to enable a custom script-based alert dispatcher which is capable of responding to Ambari alerts. The dispatcher will invoke a script with the parameters of the alert as command line arguments.

Configuration Changes

The dispatcher must know the location of the script that is being executed. This is configured through ambari.properties by setting either:

  • notification.dispatch.alert.script
  • a custom property key that points to the script, such as foo.bar.alert.dispatch.script

Some examples of this are:

notification.dispatch.alert.script=/contrib/ambari-alerts/scripts/default_logger.py
com.mycompany.dispatch.syslog.script=/contrib/ambari-alerts/scripts/legacy_sys_logger.py
com.mycompany.dispatch.shell.script=/contrib/ambari-alerts/scripts/shell_logger.sh

 

Script Call

 When an alert instance changes state and Ambari needs to dispatch that alert state change, the custom script will be invoked:

# main method which is called when invoked on the command line
# :param definitionName: the alert definition unique ID
# :param definitionLabel: the human readable alert definition label
# :param serviceName: the service that the alert definition belongs to
# :param alertState: the state of the alert (OK, WARNING, etc)
# :param alertText: the text of the alert

def main():
    definitionName = sys.argv[1]
    definitionLabel = sys.argv[2]
    serviceName = sys.argv[3]
    alertState = sys.argv[4]
    alertText = sys.argv[5]

 

API Calls

Alert Dispatch Target Creation

POST api/v1/alert_targets
    
    {
      "AlertTarget": {
        "name": "syslogger",
        "description": "Syslog Target",
        "notification_type": "ALERT_SCRIPT",
        "global": true
      }
    }

The above call will create a global alert target that will dispatch all alerts across all alert groups. Without specifying ambari.dispatch-property.script as a property of the alert target, Ambari will look for the default configuration key of notification.dispatch.alert.script in ambari.properties.

Custom Script For Dispatch Target

POST api/v1/alert_targets
    
    {
      "AlertTarget": {
        "name": "syslogger",
        "description": "Syslog Target",
        "notification_type": "ALERT_SCRIPT",
        "global": true,
        "properties": {
          "ambari.dispatch-property.script": "com.mycompany.dispatch.syslog.script"
        }
      }
    }

The above call also creates a global alert target. However, a specific script key is being specified. The result is that ambari.properties should contain something similar to:

com.mycompany.dispatch.syslog.script=/contrib/ambari-alerts/scripts/legacy_sys_logger.py
  • No labels