Announcement

Collapse
No announcement yet.

MSSQL ODBC Query By Zabbix Agent

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    MSSQL ODBC Query By Zabbix Agent

    Hi,

    I know Zabbix Server can connect to a MSSQL DB and execute a query using unixODBC drivers.

    But im wondering if there is instead a way for the Zabbix Agent on the host to connect to the DB and run the query?

    #2
    No, this is not possible. You need ODBC to connect to a database server.

    Comment


      #3
      Actually it is possible, using UserParameters and custom scripts.
      Take a look here https://share.zabbix.com/databases/m...te-ms-sql-2012, its for LLD purpouses, but the PS1 script included in this template is connecting to DB from local agent side and executing select query (code sample below from that template).

      I think you can even made custom UserParameter, which accepts SQL query as variable and passes it to script.
      That way it can be used on active agents without connection from Zabbix Server to DB

      Code:
      $SQLServer = "hostname"
      $uid = "Login" 
      $pwd = "Password"
      $connectionString = "Server = $SQLServer; User ID = $uid; Password = $pwd;"
      
      $connection = New-Object System.Data.SqlClient.SqlConnection
      $connection.ConnectionString = $connectionString
      $connection.Open()
      $SqlCmd = New-Object System.Data.SqlClient.SqlCommand  
      $SqlCmd.CommandText = "SELECT name FROM  sysdatabases"
      $SqlCmd.Connection = $Connection
      $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
      $SqlAdapter.SelectCommand = $SqlCmd
      $DataSet = New-Object System.Data.DataSet
      $SqlAdapter.Fill($DataSet) > $null
      $Connection.Close()
      Regards,
      Kaspars

      Comment

      Working...
      X