Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ OPTIONS:
-t <token> API token
-r <room id> Room ID
-f <from name> From name
-c <color> Message color (yellow, red, green, purple or random - default: yellow)
-c <color> Message color (yellow, red, green, purple, gray or random - default: yellow)
-m <format> Message format (html or text - default: html)
-i <input> Message to send to room, allows you to specify input via command line instead of stdin
-l <level> Nagios message level (critical, warning, unknown, ok, down, up). Will override color.
-s <status> Zabbix trigger status (PROBLEM, OK). Re-maps <level> (-l) to Zabbix trigger severity
(Disaster, High, Average, Warning, Information, Not classified). Will override color.
-n Trigger notification for people in the room (default: 0)
-o API host (api.hipchat.com)
-v <version> API version (default: v1)
Expand Down
Binary file added docs/images/zabbix-action.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/zabbix-conditions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/zabbix-operation1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/zabbix-operation2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/zabbix-result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions docs/zabbix-integration.md
Original file line number Diff line number Diff line change
@@ -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)

43 changes: 34 additions & 9 deletions hipchat_room_message
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ OPTIONS:
-t <token> API token
-r <room id> Room ID
-f <from name> From name
-c <color> Message color (yellow, red, green, purple or random - default: yellow)
-c <color> Message color (yellow, red, green, purple, gray or random - default: yellow)
-m <format> Message format (html or text - default: html)
-i <input> Optional: Input to send to room (default: stdin)
-l <level> Nagios message level (critical, warning, unknown, ok, down, up). Will override color.
-s <status> Zabbix trigger status (PROBLEM, OK). Re-maps <level> (-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 <version> API version (default: v1)
Expand All @@ -51,8 +53,9 @@ MESSAGE=${HIPCHAT_MESSAGE:-html}
NOTIFY=${HIPCHAT_NOTIFY:-0}
HOST=${HIPCHAT_HOST:-api.hipchat.com}
LEVEL=${HIPCHAT_LEVEL:-}
STATUS=${HIPCHAT_STATUS:-}
API=${HIPCHAT_API:-v1}
while getopts “ht:r:f:c:m:o:i:l:v:n” OPTION; do
while getopts “ht:r:f:c:m:o:i:l:s:v:n” OPTION; do
case $OPTION in
h) usage; exit 1;;
t) TOKEN=$OPTARG;;
Expand All @@ -63,6 +66,7 @@ while getopts “ht:r:f:c:m:o:i:l:v:n” OPTION; do
n) NOTIFY=1;;
i) INPUT=$OPTARG;;
l) LEVEL=$OPTARG;;
s) STATUS=$OPTARG;;
o) HOST=$OPTARG;;
v) API=$OPTARG;;
[?]) usage; exit;;
Expand All @@ -75,19 +79,40 @@ if [[ -z $TOKEN ]] || [[ -z $ROOM_ID ]] || [[ -z $FROM ]]; 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these be $STATUS instead of $LEVEL?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a running Zabbix instance to test against anymore to verify this, however I believe the PR is correct as it exists. The Zabbix Status is either "OK" or "PROBLEM", and if it is "PROBLEM" then Level is used to map the severity.

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
Expand Down