summaryrefslogtreecommitdiffstats
path: root/contrib/check_mssql.sh
diff options
context:
space:
mode:
authorStanley Hopcroft <stanleyhopcroft@users.sourceforge.net>2003-05-13 12:13:05 (GMT)
committerStanley Hopcroft <stanleyhopcroft@users.sourceforge.net>2003-05-13 12:13:05 (GMT)
commit20c7e2e1beb11ddedd22cdaaae49237f147ece31 (patch)
tree00116eaa1cae8325449968bd572827af0b8d5cea /contrib/check_mssql.sh
parent1c823d7969501c7c89f2ae765e40265518d8a731 (diff)
downloadmonitoring-plugins-20c7e2e1beb11ddedd22cdaaae49237f147ece31.tar.gz
check_mssql.sh. A new plugin from Mr T DE BLENDE to check MS SQLServer databases.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@504 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'contrib/check_mssql.sh')
-rwxr-xr-xcontrib/check_mssql.sh81
1 files changed, 81 insertions, 0 deletions
diff --git a/contrib/check_mssql.sh b/contrib/check_mssql.sh
new file mode 100755
index 0000000..048da72
--- /dev/null
+++ b/contrib/check_mssql.sh
@@ -0,0 +1,81 @@
1#!/bin/sh
2# This script is designed to be used by Nagios. It checks for the availability of both Microsoft SQL Server 7 and 2000.
3#
4# Requirements:
5#
6# Sqsh (http://www.sqsh.org/)
7# FreeTDS (http://www.freetds.org/)
8#
9# It was written by Tom De Blende (tom.deblende@village.uunet.be) in 2003.
10#
11# Version 1.0.
12# Version 1.1: rewritten the initial script so that it not only works from the CLI but also from within Nagios. Always helpful...
13#
14# You might want to change these values:
15
16sqshcmd="/usr/local/bin/sqsh"
17catcmd=`which cat`
18grepcmd=`which grep`
19rmcmd=`which rm`
20mktempcmd=`which mktemp`
21wccmd=`which wc`
22sedcmd=`which sed`
23trcmd=`which tr`
24
25###################################################################################################################
26
27
28hostname=$1
29usr=$2
30pswd=$3
31srv=$4
32
33
34if [ ! "$#" == "4" ]; then
35 echo -e "\nYou did not supply enough arguments. \nUsage: $0 <host> <username> <password> <version> \n \n$0 checks Microsoft SQL Server connectivity. It works with versions 7 and 2000.\n\nYou need a working version of Sqhs (http://www.sqsh.org/) and FreeTDS (http://www.freetds.org/) to connect to the SQL server. \nIt was written by Tom De Blende (tom.deblende@village.uunet.be) in 2003. \n\nExample:\n $0 dbserver sa f00bar 2000\n" && exit "3"
36
37elif [ $sqshcmd == "" ]; then
38 echo -e "Sqsh not found! Please verify you have a working version of Sqsh (http://www.sqsh.org/) and enter the full path in the script." && exit "3"
39
40fi
41
42exit="3"
43
44
45# Creating the command file that contains the sql statement that has to be run on the SQL server. Normally one would use the -C parameter of sqsh, but it seems that there is a bug that doesn't allow statements with more than one blanc.
46
47tmpfile=`$mktempcmd /tmp/$hostname.XXXXXX`
48
49if [ $srv == "7" ]; then
50 spid=7
51elif [ $srv == "2000" ]; then
52 spid=50
53else
54 echo -e "$srv is not a supported MS SQL Server version!" && exit "3"
55fi
56
57echo -e "select loginame from sysprocesses where spid > $spid order by loginame asc\ngo" > $tmpfile
58
59
60# Running sqsh to get the results back.
61
62resultfile=`$mktempcmd /tmp/$hostname.XXXXXX`
63$sqshcmd -S $hostname -U $usr -P $pswd -w 100000 -i $tmpfile -o $resultfile 2>/dev/null
64
65if [ ! -s $resultfile ]; then
66 $rmcmd -f $tmpfile $resultfile;
67 echo CRITICAL - Could not make connection to SQL server.;
68 exit 2;
69else
70 nmbr=`$catcmd $resultfile | $grepcmd -v "\-\-\-\-\-" | $grepcmd -v "loginame" | $grepcmd -v "affected" | $sedcmd '/^$/d' | $sedcmd 's/ //g' | $wccmd -l | sed 's/ //g'`;
71 users=`$catcmd $resultfile | $grepcmd -v "\-\-\-\-\-" | $grepcmd -v "loginame" | $grepcmd -v "affected" | $sedcmd '/^$/d' | $sedcmd 's/ //g' | $trcmd \\\n , | $sedcmd 's/,$/./g' | $sedcmd 's/,/, /g'`;
72 $rmcmd -f $tmpfile $resultfile;
73 echo "OK - MS SQL Server $srv has $nmbr user(s) connected: $users" | sed 's/: $/./g';
74 exit 0;
75fi
76
77# Cleaning up.
78
79$rmcmd -f $tmpfile $resultfile
80echo $stdio
81exit $exit