Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ OPTIONS:
-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 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)

41 changes: 33 additions & 8 deletions hipchat_room_message
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ OPTIONS:
-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,
-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.
ok, down, up). Will override color.
-n Trigger notification for people in the room
-o API host (api.hipchat.com)
Expand All @@ -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;;
Expand All @@ -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;;
Expand All @@ -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
Copy link
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
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