MS SQL Server Nagios Check Plugin v0.1

This program is free software; you can redistribute it and/or modify it under the GNU General Public License. 
Written by Francois Zbinden (zbinden at dataflow dot ch), 2008

This program is a Win32 native Microsoft SQL Server Nagios check plugin for use with NRPE_NT. It requires SQL Server Native Client installed. You can use it to just detect SQL Server connectivity or run querys. Performance data output is supported.

Usage: check_mssql_nt.exe [/h] /H:hostname [/D:dbname] [/U:username] [/P:password] [/t:timeout] [/CHK_CONNECT] [/CHK_CONNECTIONCOUNT] [/CHK_QUERY:ownquery] /w:warn_secs /c:crit_secs /Wv:[max_value|min_value:max_value] /Cv:[max_value|min_value:max_value] [/PF:outformatter] 
     
	/h, /?					
			Display the help
			
	/H:
			Hostname of the sql server
			
	/D:
			Database name
			
	/U: 
			Username. If empty it will try to login using the current windows account. 
			
	/P: 
			Password		
			
	/CHK_CONNECT 
		  		Try to connect the database. This is the default
		  		
	/CHK_CONNECTIONCOUNT
		  		Actual count of connections. If a database name is specified, count of connections to the database.		  		
		  		
	/CHK_QUERY:
		  		SQL Query to execute. The query must return one record, if no record or mutliple record are returned, it will produce a CRITICAL. If one record is returned, the value will be the first row of the record. 
		  	
	/w: 
			Warn if query duration is longer than value
	
	/c: 
			Critical if query duration is longer than value
	
	
	/Wv: 
			Warn if query result value is bigger than value
	
	/Cv:
			Critical if query result value is bigger than value
			
	/FO: 
			Pretty format the output. Use %d as value placeholder. Example: /FO:"%d pending orders"
	
	
	/t:	
			Timeout in seconds
						     
Examples:
     Check connectivity: 
     		check_mssql_nt /H:sqlv1 
     	
     Check connectivity with time check (warn >= 0.1s, critical >= 2s): 
     		check_mssql_nt /H:sqlv1 -w:0.1 -c:2
     	
     Check total connections count of all databases (warn if count >= 50, critical >= 100): 
     		check_mssql_nt /H:sqlv1 /CHK_CONNECTIONCOUNT -Wv:50 -Cv100
     
     Check total connections count of 'warehouse' databas (warn if count is over 50, critical over 100): 
     		check_mssql_nt /H:sqlv1 /D:warehouse /CHK_CONNECTIONCOUNT -Wv:50 -Cv100
     		
     Check a custom query (warn if result is over 50 or query duration is over one second, critical over 100 or duration is over 5 seconds): 
				check_mssql_nt /H:sqlv1 /D:warehouse /CHK_QUERY:"select count(*) from orders where status='pending'" -W1 -C5 -Wv:100 -Cv100 /FO:"%d pending orders"
     		
     You can also use it as a event handler:
       check_mssql_nt /H:sqlv1 /CHK_QUERY:"delete from orders where status='error'" 
     		