diff --git a/README.md b/README.md index c5b3fb0..cea6d08 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ OPTIONS: -i Optional: Input to send to room (default: stdin) -l Nagios message level (critical, warning, unknown, ok, down, up). Will override color. + -s Zabbix trigger status (PROBLEM, OK). Re-maps (-l) to Zabbix trigger severity + (Disaster, High, Average, Warning, Information, Not classified). Will override color. -n Trigger notification for people in the room -o API host (api.hipchat.com) -v API version (default: v1) diff --git a/docs/images/zabbix-action.png b/docs/images/zabbix-action.png new file mode 100644 index 0000000..f22ee02 Binary files /dev/null and b/docs/images/zabbix-action.png differ diff --git a/docs/images/zabbix-conditions.png b/docs/images/zabbix-conditions.png new file mode 100644 index 0000000..1999f23 Binary files /dev/null and b/docs/images/zabbix-conditions.png differ diff --git a/docs/images/zabbix-operation1.png b/docs/images/zabbix-operation1.png new file mode 100644 index 0000000..553f852 Binary files /dev/null and b/docs/images/zabbix-operation1.png differ diff --git a/docs/images/zabbix-operation2.png b/docs/images/zabbix-operation2.png new file mode 100644 index 0000000..4c3942f Binary files /dev/null and b/docs/images/zabbix-operation2.png differ diff --git a/docs/images/zabbix-result.png b/docs/images/zabbix-result.png new file mode 100644 index 0000000..b91c7b8 Binary files /dev/null and b/docs/images/zabbix-result.png differ diff --git a/docs/zabbix-integration.md b/docs/zabbix-integration.md new file mode 100644 index 0000000..d9e6356 --- /dev/null +++ b/docs/zabbix-integration.md @@ -0,0 +1,70 @@ +# hipchat-cli Zabbix Integration + +This guide integrating hipchat-cli with a Zabbix Monitoring +Server to push trigger notifications to Hipchat. + +## Setup hipchat-cli and Config File + + +Setup your Hipchat API credentials in /etc/hipchat + +``` +HIPCHAT_TOKEN= +HIPCHAT_ROOM_ID= +HIPCHAT_FROM= +HIPCHAT_API=v2 +HIPCHAT_FORMAT=html +``` +For added protection of the credentials, add a new user to own these files. + +``` +useradd -d /opt/hipchat-cli hipchat-cli +chown hipchat-cli:hipchat-cli /etc/hipchat +chmod 400 /etc/hipchat +``` + +Checkout hipchat-cli. Note that we are setting the SetUID / SetGID so that any +user can call this script and it will be able to read the credentials file, though +the original user will not. + +``` +git clone https://github.com/hipchat/hipchat-cli.git /opt/hipchat-cli +chown -R hipchat-cli:hipchat-cli /opt/hipchat-cli +chmod 6755 /opt/hipchat-cli/hipchat_room_message +``` + +## Setup the Zabbix Actions + + +#### Create a new Action + +![](images/zabbix-action.png) + +#### Conditions + +To enable recovery messages, delete the default Condition ```Trigger value = PROBLEM``` + +![](images/zabbix-conditions.png) + +#### Add a new Operation + +* Operation Type: **Remote Command** +* Add a new Target + * Target: **Host** + * Select server (presumably the Zabbix server) running this script. + * **Add** + +![](images/zabbix-operation1.png) + +* Execute on: **Zabbix Server** +* Commands: ```echo "{TRIGGER.STATUS}: ({TRIGGER.SEVERITY}) {TRIGGER.NAME} " | /opt/hipchat-cli/hipchat_room_message -l "{TRIGGER.SEVERITY}" -s "{TRIGGER.STATUS}" -m html >> /dev/null 2>&1``` +* **Add** + +![](images/zabbix-operation2.png) + +Finally **Save** your new Action. + +#### Break something to Trigger the Action + +![](images/zabbix-result.png) + diff --git a/hipchat_room_message b/hipchat_room_message index 241d5eb..e76ce54 100755 --- a/hipchat_room_message +++ b/hipchat_room_message @@ -36,6 +36,8 @@ OPTIONS: -m Message format (html or text - default: html) -i Optional: Input to send to room (default: stdin) -l Nagios message level (critical, warning, unknown, + -s Zabbix trigger status (PROBLEM, OK). Re-maps (-l) to Zabbix trigger severity + (Disaster, High, Average, Warning, Information, Not classified). Will override color. ok, down, up). Will override color. -n Trigger notification for people in the room -o API host (api.hipchat.com) @@ -57,10 +59,11 @@ MESSAGE=${HIPCHAT_MESSAGE:-html} NOTIFY=${HIPCHAT_NOTIFY:-0} HOST=${HIPCHAT_HOST:-api.hipchat.com} LEVEL=${HIPCHAT_LEVEL:-} +STATUS=${HIPCHAT_STATUS:-} API=${HIPCHAT_API:-v1} ALLOW_INSECURE=false -while getopts "ht:r:f:c:m:o:i:l:v:nk" OPTION; do +while getopts "ht:r:f:c:m:o:i:l:s:v:nk" OPTION; do case $OPTION in h) usage; exit 1;; t) TOKEN=$OPTARG;; @@ -71,6 +74,7 @@ while getopts "ht:r:f:c:m:o:i:l:v:nk" OPTION; do n) NOTIFY=1;; i) INPUT=$OPTARG;; l) LEVEL=$OPTARG;; + s) STATUS=$OPTARG;; o) HOST=$OPTARG;; v) API=$OPTARG;; k) ALLOW_INSECURE=true;; @@ -93,19 +97,40 @@ if [[ -z $TOKEN ]] || [[ -z $ROOM_ID ]] || [[ -z $FROM && $API = "v1" ]]; then exit 1 fi -# nagios levels +# Override color based on level / status if [ ! -z "$LEVEL" ]; then - if [[ $LEVEL == 'CRITICAL' ]] || [[ $LEVEL == 'critical' ]]; then + LEVEL=$(echo $LEVEL | tr '[:lower:]' '[:upper:]') + + if [ ! -z "$STATUS" ]; then + # Map Level to zabbix trigger severity + STATUS=$(echo $STATUS | tr '[:lower:]' '[:upper:]') + if [[ "$STATUS" == 'OK' ]]; then + COLOR="green"; + elif [[ $LEVEL == 'DISASTER' ]]; then + COLOR="red"; + elif [[ $LEVEL == 'HIGH' ]]; then + COLOR="red"; + elif [[ $LEVEL == 'AVERAGE' ]]; then + COLOR="red"; + elif [[ $LEVEL == 'WARNING' ]]; then + COLOR="yellow"; + elif [[ $LEVEL == 'INFORMATION' ]]; then + COLOR="gray"; + elif [[ $LEVEL == 'NOT CLASSIFIED' ]]; then + COLOR="gray"; + fi + # nagios levels + elif [[ $LEVEL == 'CRITICAL' ]]; then COLOR="red"; - elif [[ $LEVEL == 'WARNING' ]] || [[ $LEVEL == 'warning' ]]; then + elif [[ $LEVEL == 'WARNING' ]]; then COLOR="yellow"; - elif [[ $LEVEL == 'UNKNOWN' ]] || [[ $LEVEL == 'unknown' ]]; then + elif [[ $LEVEL == 'UNKNOWN' ]]; then COLOR="gray"; - elif [[ $LEVEL == 'OK' ]] || [[ $LEVEL == 'ok' ]]; then + elif [[ $LEVEL == 'OK' ]]; then COLOR="green"; - elif [[ $LEVEL == 'DOWN' ]] || [[ $LEVEL == 'down' ]]; then + elif [[ $LEVEL == 'DOWN' ]]; then COLOR="red"; - elif [[ $LEVEL == 'UP' ]] || [[ $LEVEL == 'up' ]]; then + elif [[ $LEVEL == 'UP' ]]; then COLOR="green"; fi fi