This repository has been archived by the owner on May 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck_sybase_rs.sh
121 lines (112 loc) · 2.51 KB
/
check_sybase_rs.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
#
# This file is subject to the terms and conditions of the GNU General Public
# License v.3. See the file "LICENSE" in the main directory of this archive
# for more details.
#
#
# Author: Adam Leszczynski, aleszczynski@bersler.com
# Version: 1.0, 01.12.2017
# Home page: https://www.bersler.com/blog/nagios-script-for-checking-sap-replication-server-sybase-rs/
#
# Script for monitoring SAP (Sybase) Replication Server using Nagios
#
#
# Script performs the following checks:
# - no processes are down (suspended)
# - health status
#
# The script requires a local installation of Open Client ($SYBASE path and isql binary).
#
# default values
SERVER=
LOGIN=
PASSWORD=
CHARACTERSET=cp1250
SYBASE=/opt/sybase
while getopts "S:U:P:c:?" opt; do
case $opt in
S)
SERVER=$OPTARG
;;
U)
LOGIN=$OPTARG
;;
P)
PASSWORD=$OPTARG
;;
C)
CHARACTERSET=$OPTARG
;;
X)
SYBASE=$OPTARG
;;
\?)
echo "ERROR, use: check_sybase_rs.sh -S server -U login [-P password] [-C character set] [-X path_to_sybase_installation]"
exit
;;
esac
done
if [ -z $SERVER ]; then
echo "ERROR: -S missing"
exit
fi
if [ -z $LOGIN ]; then
echo "ERROR: -U missing"
exit
fi
if [ ! -x $SYBASE/SYBASE.sh ]; then
echo "ERROR: Missing file: $SYBASE/SYBASE.sh"
exit
fi
source $SYBASE/SYBASE.sh
unset LANG
#test connect
out=`isql -U$LOGIN -S$SERVER -w500 -J$CHARACTERSET << EOF | tail -n +4
$PASSWORD
admin version
go
EOF`
alive=`echo "$out" | grep "Replication Server"`
if [ -z "$alive" ]; then
echo "REPLICATION SERVER CRITICAL - Unable to connnect|threads=0 down=0"
exit
fi;
#test health
out=`isql -U$LOGIN -S$SERVER -w500 -J$CHARACTERSET << EOF | tail -n +4
$PASSWORD
admin health
go
EOF`
healthy=`echo "$out" | grep "HEALTHY"`
#test threads
numthreads=`isql -U$LOGIN -S$SERVER -w500 -J$CHARACTERSET << EOF | tail -n +4 | wc -l
$PASSWORD
admin who
go
EOF`
#test connections down
out=`isql -U$LOGIN -S$SERVER -w500 -J$CHARACTERSET << EOF | tail -n +4
$PASSWORD
admin who_is_down
go
EOF`
connectionsdown=""
numconsdown=0
IFS=$'\n'
for a in $out; do
#echo "-> [$a]";
suspended=`echo "$a" | awk '{ print $NF }'`
if [ "$connectionsdown" == "" ]; then
connectionsdown=$suspended
else
connectionsdown="$connectionsdown, $suspended"
fi;
numconsdown=$((numconsdown+1))
done;
if [ ! -z "$healthy" ]; then
echo "REPLICATION SERVER OK |threads=$numthreads down=0"
else
echo "REPLICATION SERVER CRITICAL - $numconsdown threads down: $connectionsdown |threads=$numthreads down=$numconsdown"
fi;
#echo [$out]