Skip to content

Commit 4005213

Browse files
committed
Zimbra monitoring scripts and template for Zabbix
1 parent ece1101 commit 4005213

File tree

5 files changed

+277
-0
lines changed

5 files changed

+277
-0
lines changed

zabbix-zimbra/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Zimbra monitoring with Zabbix
2+
=============================
3+
4+
This template offers services autodiscover, version tracking and service status.
5+
It's compatibile with Zimbra 8.6 (and its services with spaces).
6+
7+
Please note the external script requires sudo privileges to run, so either copy the content of the sudo_zbx-zimbra.conf file to your sudoers
8+
or link it to /etc/sudoers.d/.
9+
Also copy yo-zimbra.conf to /etc/zabbix/zabbix_agentd.conf.d/ and the script file to your zabbix agent's script directory (usually /etc/zabbix/scripts, if differeny adjust yo-zimbra.conf accordingly).
10+
11+
Restart zabbix-agent and import the template to your server.
12+
The service discovery is set very long (1 day), so it may take very long for services to show up in Zabbix.
13+
14+
15+
The bash script was inspired by [blog.linuxnet.ch](https://blog.linuxnet.ch/zimbra-monitoring-with-zabbix/).
16+
17+
18+
License & Copyright
19+
-------------------
20+
Code and documentation copyright 2014 YetOpen S.r.l.. Released under the GPLv3 license.

zabbix-zimbra/sudo_zbx-zimbra.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
zabbix ALL=(zimbra) NOPASSWD:/opt/zimbra/bin/zmcontrol

zabbix-zimbra/yo-zimbra.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
UserParameter=zimbra.status[*],/etc/zabbix/scripts/zbx_zimbra.sh "$1"
2+
UserParameter=zimbra.version,/etc/zabbix/scripts/zbx_zimbra.sh version
3+
UserParameter=zimbra.discovery,/etc/zabbix/scripts/zbx_zimbra.sh discover
4+
# zmcontrol takes some time...
5+
Timeout=15
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<zabbix_export>
3+
<version>2.0</version>
4+
<date>2014-12-29T12:56:51Z</date>
5+
<groups>
6+
<group>
7+
<name>Templates</name>
8+
</group>
9+
</groups>
10+
<templates>
11+
<template>
12+
<template>Template Zimbra Services</template>
13+
<name>Template Zimbra Services</name>
14+
<groups>
15+
<group>
16+
<name>Templates</name>
17+
</group>
18+
</groups>
19+
<applications>
20+
<application>
21+
<name>Zimbra</name>
22+
</application>
23+
<application>
24+
<name>Zimbra service</name>
25+
</application>
26+
</applications>
27+
<items>
28+
<item>
29+
<name>Zimbra version</name>
30+
<type>0</type>
31+
<snmp_community/>
32+
<multiplier>0</multiplier>
33+
<snmp_oid/>
34+
<key>zimbra.version</key>
35+
<delay>43200</delay>
36+
<history>7</history>
37+
<trends>365</trends>
38+
<status>0</status>
39+
<value_type>1</value_type>
40+
<allowed_hosts/>
41+
<units/>
42+
<delta>0</delta>
43+
<snmpv3_contextname/>
44+
<snmpv3_securityname/>
45+
<snmpv3_securitylevel>0</snmpv3_securitylevel>
46+
<snmpv3_authprotocol>0</snmpv3_authprotocol>
47+
<snmpv3_authpassphrase/>
48+
<snmpv3_privprotocol>0</snmpv3_privprotocol>
49+
<snmpv3_privpassphrase/>
50+
<formula>1</formula>
51+
<delay_flex/>
52+
<params/>
53+
<ipmi_sensor/>
54+
<data_type>0</data_type>
55+
<authtype>0</authtype>
56+
<username/>
57+
<password/>
58+
<publickey/>
59+
<privatekey/>
60+
<port/>
61+
<description/>
62+
<inventory_link>0</inventory_link>
63+
<applications>
64+
<application>
65+
<name>Zimbra</name>
66+
</application>
67+
</applications>
68+
<valuemap/>
69+
<logtimefmt/>
70+
</item>
71+
</items>
72+
<discovery_rules>
73+
<discovery_rule>
74+
<name>Zimbra services discovery</name>
75+
<type>0</type>
76+
<snmp_community/>
77+
<snmp_oid/>
78+
<key>zimbra.discovery</key>
79+
<delay>86400</delay>
80+
<status>0</status>
81+
<allowed_hosts/>
82+
<snmpv3_contextname/>
83+
<snmpv3_securityname/>
84+
<snmpv3_securitylevel>0</snmpv3_securitylevel>
85+
<snmpv3_authprotocol>0</snmpv3_authprotocol>
86+
<snmpv3_authpassphrase/>
87+
<snmpv3_privprotocol>0</snmpv3_privprotocol>
88+
<snmpv3_privpassphrase/>
89+
<delay_flex/>
90+
<params/>
91+
<ipmi_sensor/>
92+
<authtype>0</authtype>
93+
<username/>
94+
<password/>
95+
<publickey/>
96+
<privatekey/>
97+
<port/>
98+
<filter>#ZIMBRASERVICE:</filter>
99+
<lifetime>30</lifetime>
100+
<description/>
101+
<item_prototypes>
102+
<item_prototype>
103+
<name>Zimbra service &quot;$1&quot;</name>
104+
<type>0</type>
105+
<snmp_community/>
106+
<multiplier>0</multiplier>
107+
<snmp_oid/>
108+
<key>zimbra.status[{#ZIMBRASERVICE}]</key>
109+
<delay>120</delay>
110+
<history>7</history>
111+
<trends>365</trends>
112+
<status>0</status>
113+
<value_type>3</value_type>
114+
<allowed_hosts/>
115+
<units/>
116+
<delta>0</delta>
117+
<snmpv3_contextname/>
118+
<snmpv3_securityname/>
119+
<snmpv3_securitylevel>0</snmpv3_securitylevel>
120+
<snmpv3_authprotocol>0</snmpv3_authprotocol>
121+
<snmpv3_authpassphrase/>
122+
<snmpv3_privprotocol>0</snmpv3_privprotocol>
123+
<snmpv3_privpassphrase/>
124+
<formula>1</formula>
125+
<delay_flex/>
126+
<params/>
127+
<ipmi_sensor/>
128+
<data_type>0</data_type>
129+
<authtype>0</authtype>
130+
<username/>
131+
<password/>
132+
<publickey/>
133+
<privatekey/>
134+
<port/>
135+
<description/>
136+
<inventory_link>0</inventory_link>
137+
<applications>
138+
<application>
139+
<name>Zimbra service</name>
140+
</application>
141+
</applications>
142+
<valuemap/>
143+
<logtimefmt/>
144+
</item_prototype>
145+
</item_prototypes>
146+
<trigger_prototypes>
147+
<trigger_prototype>
148+
<expression>{Template Zimbra Services:zimbra.status[{#ZIMBRASERVICE}].last()}#1</expression>
149+
<name>Zimbra service &quot;{#ZIMBRASERVICE}&quot; not running on {HOST.NAME}</name>
150+
<url/>
151+
<status>0</status>
152+
<priority>2</priority>
153+
<description/>
154+
<type>0</type>
155+
</trigger_prototype>
156+
</trigger_prototypes>
157+
<graph_prototypes/>
158+
<host_prototypes/>
159+
</discovery_rule>
160+
</discovery_rules>
161+
<macros/>
162+
<templates/>
163+
<screens/>
164+
</template>
165+
</templates>
166+
</zabbix_export>

zabbix-zimbra/zbx_zimbra.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/sh
2+
3+
# Zabbix script to check Zimbra services and perform service discovery.
4+
# Supports Zimbra 8.6 and "two-worded" service names
5+
# Author: Lorenzo Milesi <maxxer@yetopen.it>
6+
# Copyright: YetOpen S.r.l. 2014
7+
# License: GPLv3
8+
9+
# uncomment for debug
10+
#set -x
11+
12+
COMMAND="sudo -u zimbra /opt/zimbra/bin/zmcontrol"
13+
14+
case "$1" in
15+
version)
16+
# Return zimbra version
17+
VERS=$($COMMAND -v)
18+
if [ $? -eq 0 ] ; then
19+
echo $VERS
20+
exit 0;
21+
fi
22+
# error
23+
return 1;
24+
;;
25+
discover)
26+
# Return a list of running services in JSON
27+
echo "{"
28+
echo "\t\"data\":[\n"
29+
SRVCS=$($COMMAND status | grep Running | awk '{$(NF--)=""; print}' | sed 's/^/\t{ \"{#ZIMBRASERVICE}\":\"/' | sed 's/\ $/\" },/')
30+
# Remove last comma from the sting, to make a good JSON
31+
echo $(echo $SRVCS | sed 's/,\+$//')
32+
echo "\n\t]\n"
33+
echo "}"
34+
return 0;
35+
;;
36+
*)
37+
# move on...
38+
check=$1
39+
40+
if [ "$check" = "" ]; then
41+
echo "No Zimbra service specified..."
42+
exit 1
43+
fi
44+
45+
maxage=120
46+
file='/var/run/zabbix/zimbra_status'
47+
48+
# Very basic concurrency check
49+
x=0
50+
while [ -f "$file.tmp" ]; do
51+
sleep 5;
52+
x=$((x+1))
53+
# don't wait too long anyway, remove an eventually stale lock. Anyway we have 15s zabbix agent timeout
54+
if [ $x -ge 3 ]; then
55+
rm "$file.tmp";
56+
fi
57+
done
58+
#check if cached status file size > 0
59+
if [ -s ${file} ]; then
60+
OLD=`stat -c %Z $file`
61+
NOW=`date +%s`
62+
63+
# if older then maxage, update file
64+
if [ `expr $NOW - $OLD` -gt $maxage ]; then
65+
$COMMAND status > $file.tmp
66+
mv $file.tmp $file
67+
fi
68+
else
69+
rm -f ${file}
70+
$COMMAND status > $file.tmp
71+
mv $file.tmp $file
72+
fi
73+
74+
STATUS="$(cat $file | grep "$check" | awk '{print $NF}')"
75+
76+
if [ "$STATUS" != "Running" ]; then
77+
echo 0
78+
else
79+
echo 1
80+
fi
81+
;;
82+
esac
83+
84+
exit 0;
85+

0 commit comments

Comments
 (0)