Zabbix Documentation 4.4

3.04.04.4 (current)| In development:5.0 (devel)| Unsupported:1.82.02.22.43.23.44.2Guidelines

User Tools

Site Tools


manual:config:items:itemtypes:odbc_checks

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
manual:config:items:itemtypes:odbc_checks [2014/09/26 13:50]
dotneft
manual:config:items:itemtypes:odbc_checks [2019/10/01 08:44] (current)
martins-v linking to an example of db.odbc.get
Line 1: Line 1:
-==== - #15 ODBC monitoring ====+==== 15 ODBC monitoring ====
  
-=== Overview ===+=== Overview ===
  
 ODBC monitoring corresponds to the //Database monitor// item type in the Zabbix frontend. ODBC monitoring corresponds to the //Database monitor// item type in the Zabbix frontend.
Line 9: Line 9:
 Zabbix may query any database, which is supported by ODBC. To do that, Zabbix does not directly connect to the databases, but uses the ODBC interface and drivers set up in ODBC. This function allows for more efficient monitoring of different databases for multiple purposes - for example, checking specific database queues, usage statistics and so on. Zabbix supports unixODBC, which is one of the most commonly used open source ODBC API implementations. Zabbix may query any database, which is supported by ODBC. To do that, Zabbix does not directly connect to the databases, but uses the ODBC interface and drivers set up in ODBC. This function allows for more efficient monitoring of different databases for multiple purposes - for example, checking specific database queues, usage statistics and so on. Zabbix supports unixODBC, which is one of the most commonly used open source ODBC API implementations.
  
-=== Installing unixODBC ​ ===+=== Installing unixODBC ​ ===
  
 The suggested way of installing unixODBC is to use the Linux operating system default package repositories. In the most popular Linux distributions unixODBC is included in the package repository by default. If it's not available, it can be obtained at the unixODBC homepage: http://​www.unixodbc.org/​download.html. The suggested way of installing unixODBC is to use the Linux operating system default package repositories. In the most popular Linux distributions unixODBC is included in the package repository by default. If it's not available, it can be obtained at the unixODBC homepage: http://​www.unixodbc.org/​download.html.
Line 21: Line 21:
 <​note>​The unixODBC-devel package is needed to compile Zabbix with unixODBC support.</​note>​ <​note>​The unixODBC-devel package is needed to compile Zabbix with unixODBC support.</​note>​
  
-=== Installing unixODBC drivers ===+=== Installing unixODBC drivers ===
  
 A unixODBC database driver should be installed for the database, which will be monitored. unixODBC has a list of supported databases and drivers: http://​www.unixodbc.org/​drivers.html. In some Linux distributions database drivers are included in package repositories. A unixODBC database driver should be installed for the database, which will be monitored. unixODBC has a list of supported databases and drivers: http://​www.unixodbc.org/​drivers.html. In some Linux distributions database drivers are included in package repositories.
Line 30: Line 30:
  
   zypper in MyODBC-unixODBC   zypper in MyODBC-unixODBC
-=== Configuring unixODBC ===+ 
 +=== Configuring unixODBC ===
  
 ODBC configuration is done by editing the **odbcinst.ini** and **odbc.ini** files. To verify the configuration file location, type: ODBC configuration is done by editing the **odbcinst.ini** and **odbc.ini** files. To verify the configuration file location, type:
Line 85: Line 86:
 </​code>​ </​code>​
  
-=== Compiling Zabbix with ODBC support ===+=== Compiling Zabbix with ODBC support ===
 To enable ODBC support, Zabbix should be compiled with the following flag: To enable ODBC support, Zabbix should be compiled with the following flag:
 <​code>​ <​code>​
Line 93: Line 94:
 <​note>​See more about Zabbix installation from the [[manual:​installation:​install#​from_the_sources|source code]].</​note>​ <​note>​See more about Zabbix installation from the [[manual:​installation:​install#​from_the_sources|source code]].</​note>​
  
-=== Item configuration in Zabbix frontend ===+=== Item configuration in Zabbix frontend ===
  
-Configure a database monitoring [[manual:​config:​items:​item#​overview|item]]+Configure a database monitoring [[manual:​config:​items:​item#​overview|item]].
  
-{{odbc.png|}}+{{odbc0.png|}} 
 + 
 +All mandatory input fields are marked with a red asterisk. ​
  
 Specifically for database monitoring items you must enter: Specifically for database monitoring items you must enter:
  
 |//​Type// ​  ​|Select //Database monitor// here.   | |//​Type// ​  ​|Select //Database monitor// here.   |
-|//​Key// ​  ​|Enter **db.odbc.select**[unique_description,​data_source_name]\\ The unique description will serve to identify the item in triggers etc.\\ The data source name (DSN) must be set as specified in odbc.ini. ​ |+|//​Key// ​  ​|Enter ​one of the two supported item keys:​\\ ​**db.odbc.select**[unique_description,​data_source_name] ​- this item is designed to return one value, i.e. the first column of the first row of the SQL query result. If a query returns more than one column, only the first column is read. If a query returns more than one line, only the first line is read.\\ **db.odbc.get**[unique_description,​data_source_name] - this item is capable of returning multiple rows/​columns in JSON format. Thus it may be used as a master item that collects all data in one system call, while JSONPath preprocessing may be used in dependent items to extract individual values. For more information,​ see an [[:​manual/​discovery/​low_level_discovery/​sql_queries#​using_dbodbcget|example]] of the returned format, used in low-level discovery. This item is supported since Zabbix 4.4.\\ The unique description will serve to identify the item in triggers etc.\\ The data source name (DSN) must be set as specified in odbc.ini. ​ |
 |//User name// ​  ​|Enter the database user name (optional if user is specified in odbc.ini) | |//User name// ​  ​|Enter the database user name (optional if user is specified in odbc.ini) |
 |//​Password// ​  ​|Enter the database user password (optional if password is specified in odbc.ini) | |//​Password// ​  ​|Enter the database user password (optional if password is specified in odbc.ini) |
-|//SQL query// ​  | Enter the SQL query  |+|//SQL query// ​  | Enter the SQL query.\\ Note that with the ''​db.odbc.select[]''​ item the query must return one value only.  |
 |//Type of information// ​ |It is important to know what type of information will be returned by the query, so that it is selected correctly here. With an incorrect //type of information//​ the item will turn unsupported. ​ | |//Type of information// ​ |It is important to know what type of information will be returned by the query, so that it is selected correctly here. With an incorrect //type of information//​ the item will turn unsupported. ​ |
  
-=== Important notes ===+=== Important notes ===
  
-  * The query must not be executing longer than the [[:​manual/​appendix/​config/​zabbix_server|Timeout]] parameter on the serverStarting from Zabbix 2.0.8 the [[:​manual/​appendix/​config/​zabbix_server|Timeout]] parameter value is also used as ODBC login timeout (note that depending on ODBC drivers the login timeout setting might be ignored). +  * Zabbix does not limit the query execution time. It is up to the user to choose queries that can be executed in a reasonable amount of time. 
-  * The query must return ​one value only. +  * The [[:​manual/​appendix/​config/​zabbix_server|Timeout]] parameter value from Zabbix server ​is used as the ODBC login timeout (note that depending on ODBC drivers the login timeout setting might be ignored). 
-  * If a query returns more than one column, only the first column is read. +  * The SQL command ​must return a result set like any query with ''​select ​...''​. The query syntax will depend on the RDBMS which will process them. The syntax of request to a storage procedure ​must be started ​with ''​call'' ​keyword
-  * If a query returns more than one line, only the first line is read +  * See also [[:​manual/​installation/​known_issues#​odbc_checks|known issues]] for ODBC checks
-  * The SQL command ​must begin with ''​select''​. +
-  * The SQL command mustn'​t contain any line breaks.+
  
-=== Error messages ===+=== Error messages ===
  
-Starting from Zabbix 2.0.8 the ODBC error messages are structured into fields to provide ​more detailed information. ​Example+ODBC error messages are structured into fields to provide detailed information. ​For example
-<​code>​ + 
-Cannot execute ODBC query:​[SQL_ERROR]:​[42601][7][ERROR:​ syntax error at or near ";";​ Error while executing the query]| +  Cannot execute ODBC query: [SQL_ERROR]:​[42601][7][ERROR:​ syntax error at or near ";";​ Error while executing the query] 
-------------------------- ​ --------- ​  ​----- ​ |  ------------------------------------------------------------------- | +  ​└───────────┬───────────┘ ​ └────┬────┘ └──┬──┘└┬┘└─────────────────────────────┬─────────────────────────────────────┘ 
-            ​| ​                 |         ​   `- Native error code            ​`- error message.                      `- Record separator +              ​│ ​                  ​│ ​        ​│    └─ ​Native error code            ​└─ Native ​error message 
-            ​| ​                 |         ​`-SQLState +              ​│ ​                  ​│ ​        ​└─ ​SQLState 
-            ​`- ​Zabbix message ​ ​`- ​ODBC return code +              ​└─ ​Zabbix message ​  └─ ​ODBC return code 
-</​code>​ + 
-Note that the error message length is limited to 128 bytes, so the message can be truncated. If there is more than one ODBC diagnostic record Zabbix tries to concatenate them as far as the length limit allows.+Note that the error message length is limited to 2048 bytes, so the message can be truncated. If there is more than one ODBC diagnostic record Zabbix tries to concatenate them (separated with ''​|''​) ​as far as the length limit allows.