Nagios to Monitor Windows ODBC Connections

The following is a short description about our investigation into cross platform Nagios monitoring specifically monitoring of ODBC connections in a Windows 2008 R2 with a Nagios installation on a Debian system, not going to go into every little detain in this post just be basics.

Lets first start by describing the case a bit.
A Windows program that uses ODBC connections to external sources to get data, normally no monitoring of the connections to see if they are up or down, historically the users of the program noticed that the connection was down when they had not goten the data for 2 to 3 weeks and the panic begins.

So the solution is to monitor the troublesome connection so that we know when it goes down and can take the appropriate action

The easy part

Adding the host to Nagios was the easy part of this endeavor.
I just added the Windows host as any other host, defined a new service group where I later added the Windows specific check commands that we wanted to use.

The Windows part

The only windows agent we found that would be able to do the things we wanted was the NSClient++  after the normal easy Windows next next next install with a few chooses that where more or less guesses about what we actually needed to have we had the NSClient++ up and ruining and ready to send monitoring data like disk size and memory usage, now on the what happened to be the hard part part of it all.

The hard part

We needed an easy way to get the information about about the ODBC connection so we decided to use a plugin that we found on Nagios Exchange called Check ODBC  because it looked easy to integrate into the NSClient++, More that double the estimated time later we still haven’t gotten it to work, turned out that the instructions on how to integrate it was lacking to say the least. After spending a lot of time trying to get that plugin working and nor being able to get it to work as intended I went to my old friend Python to see if the problem could be solved by writing my own plugin instead.
The pyodbc module had all i needed, just needed to get a Python environment on the Windows machine, I settled for python 3.3 since the module was confirmed to be working on that version of Python.

Pyodbc module for windows download 

The Python rows that solved the problem in a nice ans easy way

import pyodbc, sys
try:
    pyodbc.connect(’DSN=DSNNAME; UID=USERNAME;PWD=PASS’)
except pyodbc.Error:
   print (”Cant connect”)
  sys.exit(2)
else:
   print (”OK”)
  sys.exit(0)

In the ini file that is the config file for NSCLient++ add the following

Checkexternalscripts =1

[/setting/external scripts ]

allow arguments = true

[/settings/external scripts/scripts]
;A way to use the py command in widows to run the whole script when its called by the Nagios server.
check_odbc= py ”C:\Program Files\NSClient++\check_odbc.exe”

 

Conclusion

As with many Open Source projects the documentation is lacking and this is something we need to it better at so we don’t have to spend time on trying to figure it out on our own.

As with most cross platform integration there is always some unforeseen problem that shows its ugly face during the whole endeavor and most of the time its not Linux that makes it hard for us.

Sometimes the things that seam to be easy things are not so easy but you learn a lot from doing them and sometimes its better to find another way to solve the problem than the first idea that you think would solve the problems for you.