-
Notifications
You must be signed in to change notification settings - Fork 3
/
check_sipgate_balance
executable file
·38 lines (35 loc) · 1.09 KB
/
check_sipgate_balance
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
#!/bin/bash
. /usr/lib/nagios/plugins/utils.sh
# Checks Sipgate api for the billing state.
# Requires curl and xml2 cli tools
# Written by Darko Krizic <[email protected]>
username=$1
password=$2
warning=$3
critical=$4
#echo "username=[$username] password=[$password] warning=[$warning] critical=[$critical]" >/tmp/x
out=$(curl -s -u "$username:$password" https://api.sipgate.net/my/billing/balance/)
status=$?
if [ $status -eq 0 ]
then
out2=$(echo $out | xml2)
currency=$(echo $out2 | sed -e 's/ /\n/g' | grep currency | awk -F= '{print $2}')
total=$(echo $out2 | sed -e 's/ /\n/g' | grep totalIncludingVat | awk -F= '{print $2}')
round=$(echo $total | awk -F\. '{print $1}')
perf="'Balance'=$total;$warning;$critical"
if [ $round -lt $critical ]
then
echo "CRITICAL Balance $total $currency below $critical | $perf"
exit $STATE_CRITICAL
fi
if [ $round -lt $warning ]
then
echo "WARNING Balance $total $currency below $warning | $perf"
exit $STATE_WARNING
fi
echo "OK Balance is $total $currency | $perf"
exit $STATE_OK
else
echo "Unable to read balance, status $status"
exit $STATE_UNKNOWN
fi