Wednesday, February 27, 2013

Nagios MS SQL Server Plugin

I recently attempted to use the  check_mssql_database.py plugin. It doesn't give much feedback for errors. I was typically seeing something like this while attempting to connect to SQL Server 2005 from a Nagios Xi installation:

CRITICAL:Unable to access SQL Server.
I did some research, including looking at the Python script. After looking into the DB connection method, I discovered that I had to configure the freetds.conf file (in /etc, in my case.)

I added a stanza like this (you might need a more exotic configuration or configurations):

[MYSERVERNAME]
     host = myservers_IP_ADDRESS
     port = my_port_number 
     tds version = 7.0


After doing this, I was able to connect (not all the checks return sane values, but that's a problem for a different day.) My connection string goes like so:
check_mssql_server.py -H 'hostname_or_IP'    --warning 20 --critical 30 -U 'MYDOMAIN\username' -P 'MYPASSWORD' --deadlocks

You can specify instance with -I, but I was using the default instance of 'MSSQLSERVER'


The plugin's install document is here:
Install doc

Edit: it would appear that most of the tests are not going to be useful. Quite a few of them return nonsensical, large values and other return the same value consistently, no matter what the conditions on the server.

Also, Nagios Xi does something funny where it auto escapes the \ in the domain\username combo. The plugin ends up running DOMAINNAME\\username (which it can't handle.) I tried removing the quotes and several other things.

I ended up finally modifying the plugin to add my domain name to the user name and then I used the short username in Nagios Xi without the domain preface. If I knew Python better, I would have had it strip off the extra \ - but I had to get it working quickly. I might go back and make that change later.

 To be honest, I'm not very familiar with Nagios Xi - having used the original Nagios since 2002 or so, so it could be something I'm overlooking.