I’ve been trying to get the Zenoss SQL Transaction Zenpack working so that we can use Zenoss to run SQL queries for specific monitoring purposes and ran into a few things that might be worth sharing.
Using tsql for troubleshooting
Zenoss, among many other tools uses pymssql to connect to your SQL Servers; and pymssql uses FreeTDS behind the scenes. If you can’t get pymssql to work them you can go a layer deeper to see if you can find the issues. In my case I have the following configuration:
Fedora Server 23
freetds-0.95.81-1
pymssql-2.1.3
First off, FreeTDS uses a config file at /etc/freetds.conf that has a [Global] section and examples for configuring individual server types. This is important because you need to use TDS version 7.0+ for Windows Authentication to work.
If we try to connect using the diagnostic tool tsql (not to be confused with the language T-SQL) without changing the default TDS version or adding a server record in the config file our attempts will fail
To fix this you can either:
Change the Global value for “tds version” to be 7+ (sounds like a good idea to me if you only have MSSQL):
or you can add a server record for each Microsoft SQL Server and leave the global version less than 7.
It’s basically a simplified version of the example on the pymssql web page, but will prove if pymssql and MSSQL Windows Authentication is working or not.
————-BEGIN Code
import pymssql
print(‘Connecting to SQL’)
conn = pymssql.connect(server=’server.domain.com’, user=’DOMAIN\username’, password=’Super Secret P@ssW0rds’, database=’master’)
print(‘Creating cursor’)
cursor = conn.cursor()
print(‘Executing query’)
cursor.execute(“””
SELECT MAX(req.total_elapsed_time) AS [total_time_ms]
FROM sys.dm_exec_requests AS req
WHERE req.sql_handle IS NOT NULL
“””)
print(‘Fetching results’)
row = cursor.fetchone()
while row:
print(row[0])
row = cursor.fetchone()
print(‘Closing connection’)
conn.close