forked from jedda/OSX-Monitoring-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_kerio_connect_stats.sh
executable file
·97 lines (83 loc) · 3.51 KB
/
check_kerio_connect_stats.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# Check Kerio Connect Statistics
# by Jedda Wignall
# http://jedda.me
# v1.1 - 27 Mar 2012
# Added some timing padding to ensure reset occurs.
# v1.0 - 26 Mar 2012
# Initial release.
# This script checks the stats.dat file in your kerio connect mailstore and lets you know if counters have passed warn/crit thresholds.
# It returns full performance data on the requested counters, and finishes by using the Kerio Admin API to reset your statistics.
#
# You will need to fill in a few variables below to get this working.
# The script takes the following arguments:
# -n Quoted list (space delimited) of counter names you want to query.
# -n Quoted list (space delimited) (same order) of warning thresholds for the counters.
# -c Quoted list (space delimited) (same order) of critical thresholds for the counters.
#
# Examples:
#
# ./check_kerio_connect_stats.sh -n "mtaLargestSize" -w "4000" -c "10000"
# returns:
# OK | mtaLargestSize=3394;
#
# ./check_kerio_connect_stats.sh -n "mtaReceivedMessages mtaTransmittedMessages" -w "5 35" -c "25 48"
# returns:
# WARNING: mtaReceivedMessages is 8 | mtaReceivedMessages=8;mtaTransmittedMessages=11;
# START CONFIG SECTION
# the local path to your kerio connect mailstore. change if different
kerioStore="/usr/local/kerio/mailserver"
# put your kerio admin url, username and password below. this is used to reset your kerio stats after we are done.
kerioAdminURL="https://your.server.url:4040"
kerioAdminUser="Admin"
kerioAdminPass="*YourPassword*"
# END CONFIG SECTION
# from here below is the script - don't change variables unless you know what you are doing
function resetKerioStatistics() {
login=`curl --cookie /tmp/tempcookies --cookie-jar /tmp/tempcookies -k -X POST -H "Content-type: application/json" \
-d '{"jsonrpc": "2.0","id": 1,"method": "Session.login","params": {"userName": "'$kerioAdminUser'","password": "'$kerioAdminPass'","application": {"name": "Statistics Reset","vendor": "jedda.me","version": "1.0.0"}}}
' -silent $kerioAdminURL'/admin/api/jsonrpc'`
token=`echo $login | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w token | awk -F '|' '{ print $3 }'`
reset=`curl --cookie /tmp/tempcookies -k -X POST -H "Content-type: application/json" -H "X-Token: $token" -d '{"jsonrpc":"2.0","id":1,"method":"Statistics.reset","params":{}}' -silent $kerioAdminURL'/admin/api/jsonrpc'`
sleep 3
logout=`curl --cookie /tmp/tempcookies -k -X POST -H "Content-type: application/json" -H "X-Token: $token" -d '{"jsonrpc": "2.0","id": 1, "method": "Session.logout"}' -silent $kerioAdminURL'/admin/api/jsonrpc'`
}
nameList=""
warnList=""
critList=""
performance=""
warnString=""
critString=""
i=0
while getopts "n:w:c:" optionName; do
case "$optionName" in
n) nameList=( $OPTARG );;
w) warnList=( $OPTARG );;
c) critList=( $OPTARG );;
esac
done
for counter in ${nameList[*]}
do
match=`grep $counter $kerioStore/stats.dat | tr -d '\t' `
value=`echo $match | awk -F '[>,<]' '{ print $3 }'`
performance="$performance${nameList[$i]}=$value;"
if [ $value -ge ${critList[$i]} ]; then
critString="CRITICAL: ${nameList[$i]} is $value"
fi
if [ $value -ge ${warnList[$i]} ]; then
warnString="WARNING: ${nameList[$i]} is $value"
fi
i=$((i+1))
done
resetKerioStatistics &
sleep 2
if [ "$critString" != "" ]; then
printf "$critString | $performance\n"
exit 2
elif [ "$warnString" != "" ]; then
printf "$warnString | $performance\n"
exit 1
else
printf "OK | $performance\n"
exit 0
fi