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_ase.sh
301 lines (275 loc) · 7.9 KB
/
check_sybase_ase.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#!/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, 30.11.2017
# Home page: https://www.bersler.com/blog/nagios-script-for-checking-sap-adaptive-server-enterprise-sybase-ase/
#
# Script for monitoring SAP (Sybase) Adaptive Server Enterprise (ASE) using Nagios
#
#
# Script performs the following checks:
# - the server is up
# - no blocked processes (default threshold is 300 seconds)
# - no long running transactions (default threshold is 300 seconds)
# - log segment is not full in all databasess
# - free space in data segment for all databasess
#
#
# The script requires a local installation of Open Client ($SYBASE path and isql binary).
#
# parameters:
# maximum allowed time for blocked processes
BLOCKEDTIME=300
# maximum time for long running transactions
LONGRUNTIME=300
# warning level for free space
FREESPACEPCTWARN=90
# critical level for free space
FREESPACEPCTERR=95
# default values
SERVER=
LOGIN=
PASSWORD=
CHARACTERSET=iso_1
SYBASE=/opt/sybase
# variables
NUMDATABASES=0
NUMPROCESSES=0
EXTRAINFO=""
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_ase.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
set nocount on
go
select @@version
go
EOF`
alive=`echo "$out" | grep "Adaptive Server Enterprise"`
if [ -z "$alive" ]; then
echo "ASE SERVER CRITICAL - Unable to connnect|databases=$NUMDATABASES processes=$NUMPROCESSES"
exit
fi;
########################################################################
#log full
out=`isql -U$LOGIN -S$SERVER -w500 -J$CHARACTERSET << EOF | tail -n +4
$PASSWORD
set nocount on
set transaction isolation level 0
go
select name, case when name = 'tempdb' or (status3 & 256) = 256 then 'tempdb' else 'user' end as dbtype
from master..sysdatabases where lct_admin("logfull", dbid) = 1
go
EOF`
logfulldbs=""
numlogfulldbs=0
IFS=$'\n'
for a in $out; do
dbname=`echo "$a" | awk '{ print $1 }'`
dbtype=`echo "$a" | awk '{ print $2 }'`
if [ "$dbtype" == "tempdb" ]; then
echo "ASE SERVER CRITICAL - log full in temporary db $dbname|databases=$NUMDATABASES processes=$NUMPROCESSES"
exit
fi
if [ "$logfulldbs" == "" ]; then
logfulldbs=$dbname
else
logfulldbs="$logfulldbs, $dbname"
fi;
numlogfulldbs=$((numlogfulldbs+1))
done;
if [ ! -z "$logfulldbs" ]; then
echo "ASE SERVER CRITICAL - log full in $numlogfulldbs dbs: $logfulldbs|databases=$NUMDATABASES processes=$NUMPROCESSES"
exit
fi;
########################################################################
#statistical information
out=`isql -U$LOGIN -S$SERVER -w500 -J$CHARACTERSET << EOF | tail -n +4
$PASSWORD
set nocount on
set transaction isolation level 0
go
declare @databases int, @processes int
select @databases = count(*) from master..sysdatabases
select @processes = count(*) from master..sysprocesses where suid > 0 and spid <> @@spid
select @databases as databases, @processes as processes
go
EOF`
NUMDATABASES=`echo "$out" | awk '{ print $1 }'`
NUMPROCESSES=`echo "$out" | awk '{ print $2 }'`
########################################################################
#blocked processes
out=`isql -U$LOGIN -S$SERVER -w500 -J$CHARACTERSET << EOF | tail -n +4
$PASSWORD
set nocount on
set transaction isolation level 0
go
select
spid
from master..sysprocesses
where
suid > 0
and spid <> @@spid
and status = 'lock sleep'
and blocked > 0
and time_blocked > $BLOCKEDTIME
go
EOF`
blockedprocesses=""
numblockedprocesses=0
IFS=$'\n'
for a in $out; do
processes=`echo "$a" | awk '{ print $1 }'`
if [ "$blockedprocesses" == "" ]; then
blockedprocesses=$processes
else
blockedprocesses="$blockedprocesses, $processes"
fi;
numblockedprocesses=$((numblockedprocesses+1))
done;
if [ ! -z "$blockedprocesses" ]; then
echo "ASE SERVER CRITICAL - $numblockedprocesses blocked processes SPID: $blockedprocesses|databases=$NUMDATABASES processes=$NUMPROCESSES"
exit
fi;
########################################################################
#long running transactions
out=`isql -U$LOGIN -S$SERVER -w500 -J$CHARACTERSET << EOF | tail -n +4
$PASSWORD
set nocount on
set transaction isolation level 0
go
select db_name(dbid) from master..syslogshold where name not like '%replication_truncation_point%' and datediff(ss, starttime, getdate()) >= $LONGRUNTIME
go
EOF`
longrunningtransactions=""
numlongrunningtransactions=0
IFS=$'\n'
for a in $out; do
transactions=`echo "$a" | awk '{ print $1 }'`
if [ "$longrunningtransactions" == "" ]; then
longrunningtransactions=$transactions
else
longrunningtransactions="$longrunningtransactions, $transactions"
fi;
numlongrunningtransactions=$((numlongrunningtransactions+1))
done;
if [ ! -z "$databasessuspended" ]; then
echo "ASE SERVER CRITICAL - $numlongrunningtransactions long running transactions: $longrunningtransactions |databases=$NUMDATABASES processes=$NUMPROCESSES"
exit
fi;
########################################################################
#free space
out=`isql -U$LOGIN -S$SERVER -w500 -J$CHARACTERSET << EOF | tail -n +4
$PASSWORD
set nocount on
set transaction isolation level 0
go
select
convert(char(20), db_name(dbid)) dbname,
segmap,
sum(size) / (1048576 / @@maxpagesize) allocatedMB,
case when segmap = 4 then
lct_admin("logsegment_freepages", dbid)
else
sum(curunreservedpgs(dbid, lstart, unreservedpgs))
end / (1048576 / @@maxpagesize) as freeMB,
case when lct_admin("logfull", dbid) = 1 and segmap & 4 = 4
then 100
else
ceiling(round(convert(numeric(15, 4),
(sum(convert(numeric(15, 4), size)) -
case when segmap = 4 then
lct_admin("logsegment_freepages", dbid)
else
sum(convert(numeric(15, 4), curunreservedpgs(dbid, lstart, unreservedpgs)))
end
) / sum(convert(numeric(15, 4), size))), 4) * 100)
end as freePercent
from
master..sysusages
where
dbid in
(select dbid from master..sysdatabases where (status3 & 8192 != 8192 or status3 is null) and status & 32 != 32 and status2 & (16 + 32) = 0)
group by
dbid,
segmap
go
EOF`
fulldb=""
numfulldb=0
IFS=$'\n'
warning=""
error=""
for a in $out; do
dbname=`echo "$a" | awk '{ print $1 }'`
segmap=`echo "$a" | awk '{ print $2 }'`
allocatedmb=`echo "$a" | awk '{ print $3 }'`
freemb=`echo "$a" | awk '{ print $4 }'`
freepercent=`echo "$a" | awk '{ print $5 }'`
EXTRAINFO="$EXTRAINFO ${dbname}_seg${segmap}=${freepercent}"
if [ $freepercent -ge $FREESPACEPCTWARN ]; then
if [ "$fulldb" == "" ]; then
fulldb="$dbname ($freepercent% for segmap $segmap)"
else
fulldb="$fulldb, $dbname ($freepercent% for segmap $segmap)"
fi;
numfulldb=$((numfulldb+1))
warning=1;
fi;
if [ $freepercent -ge $FREESPACEPCTERR ]; then
error=1;
fi;
done;
if [ ! -z "$fulldb" ]; then
if [ ! -z "$error" ]; then
echo "ASE SERVER CRITICAL - $numfulldb space: $fulldb |databases=$NUMDATABASES processes=$NUMPROCESSES ${EXTRAINFO}"
else
echo "ASE SERVER WARNING - $numfulldb space: $fulldb |databases=$NUMDATABASES processes=$NUMPROCESSES ${EXTRAINFO}"
fi;
exit
fi;
########################################################################
#all is ok
echo "ASE SERVER OK |databases=$NUMDATABASES processes=$NUMPROCESSES ${EXTRAINFO}"