ZABBIX Forums  
  #1  
Old 07-11-2017, 14:52
TheCookieMonster TheCookieMonster is offline
Junior Member
 
Join Date: Jul 2017
Posts: 8
Post 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?
Reply With Quote
  #2  
Old 12-12-2017, 13:45
GPegel GPegel is offline
Senior Member
Zabbix certified professionalZabbix certified specialist
 
Join Date: Dec 2015
Location: The Netherlands
Posts: 105
Default

No, this is not possible. You need ODBC to connect to a database server.
Reply With Quote
  #3  
Old 22-12-2017, 13:24
kaspars.mednis kaspars.mednis is offline
Senior Member
 
Join Date: Oct 2017
Posts: 334
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 23:37.