Ad Widget

Collapse

database monitor

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dagun
    Member
    • Sep 2009
    • 71

    #1

    database monitor

    The functionality "database monitor" is not officially supported ? 1.6???1.8???
    Thanks .
  • Padawan.AVT
    Junior Member
    • May 2009
    • 26

    #2
    AFAIK still not, but I've managed to make it work with some limitations (length of the query must be less than 255 characters)

    My small HowTo:

    Comment

    • ericgearhart
      Senior Member
      • Jan 2009
      • 115

      #3
      Here's a quick and dirty python script I wrote that can query MS SQL servers and just try to do a simple SELECT against a table.

      I then set up an "external script" Item in Zabbix and I have it run the script, and I have a trigger setup on the item that makes sure the output is always OK


      The script takes five arguments: server to connect to, username, password, database, table

      For example:
      ./query_mssql.py mssqlserver01 myMSSQLuser reallysecretpassword importantdatabase importtanttable

      Code:
      #!/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"
      Last edited by ericgearhart; 03-01-2010, 20:05. Reason: copyedit and more clarification

      Comment

      • ericgearhart
        Senior Member
        • Jan 2009
        • 115

        #4
        I deliberately wrote this script in way that was Python database API compliant, so that it would be really stupid easy to substitute using 'pymssql' with another Python SQL module that supported another database in the future, such as MySQLdb or pypostgresql

        In fact I guess I could expand this script out, and an argument to the script could be the database 'type' that you want to monitor :P
        Last edited by ericgearhart; 03-01-2010, 20:14.

        Comment

        • dagun
          Member
          • Sep 2009
          • 71

          #5
          How long we will wait??

          How long we will wait??

          Comment

          Working...