The functionality "database monitor" is not officially supported ? 1.6???1.8???
Thanks .
Thanks .
#!/usr/bin/python
# We need pymssql in order to do MSSQL stuff from python
import pymssql
# We ned sys in order to grab the argument to the script (which is the IP to connect to)
import sys
# The MS SQL server to query. For custom port, use IPADDRES:PORT as this argument. Otherwise pymssql assumes port 1433
SQLServer = sys.argv[1]
# username to connect as
User = sys.argv[2]
# password
Password = sys.argv[3]
# database to connect to
Database = sys.argv[4]
# table to perform a simple SELECT on
Table = sys.argv[5]
# Set a sane default timeout (for all socket connections unfortunately...)
import socket
socket.setdefaulttimeout(3)
# Try to connect to the SQL server and do a simple SELECT
try:
# Setup connection string
conn = pymssql.connect(host=SQLServer, user=User, password=Password, database=Database)
# Connect to SQL
cur = conn.cursor()
# Just try to do a simple SELECT statement against a table... only grab 10 rows so that we're not intrusive
cur.execute('SELECT TOP 10 * FROM %s' % Table)
#### This section is for debugging problems and figuring out a table to query ####
# Apparently this is MSSQL's equivalent of 'SHOW TABLES'
#cur.execute("select * from SYSOBJECTS where TYPE = 'U' order by NAME")
# print the results of the SQL statement
#row = cur.fetchone()
#while row:
# print "%s" % (row[0])
# row = cur.fetchone()
#### This section is for debugging problems and figuring out a table to query ####
# Clean up the connection after we're done
conn.close()
# if we have gotten to this point assume the database is reachable and things are OK
print "OK"
# Catch all exceptions and print PROBLEM if the connection was unsuccessful
except:
print "PROBLEM"
Comment