Zabbix Documentation 4.2

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:loadablemodules

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
manual:config:items:loadablemodules [2019/06/03 08:13]
martins-v updating example about loadmodule parameters
manual:config:items:loadablemodules [2019/09/12 08:44] (current)
martins-v code highlighting fix
Line 31: Line 31:
 The only mandatory function is **zbx_module_api_version()**:​ The only mandatory function is **zbx_module_api_version()**:​
  
-<file c>+<code c>
 int zbx_module_api_version(void);​ int zbx_module_api_version(void);​
-</file>+</code>
  
 This function should return the API version implemented by this module and in order for the module to be loaded this version must match module API version supported by Zabbix. Version of module API supported by Zabbix is ZBX_MODULE_API_VERSION. So this function should return this constant. Old constant ZBX_MODULE_API_VERSION_ONE used for this purpose is now defined to equal ZBX_MODULE_API_VERSION to preserve source compatibility,​ but it's usage is not recommended. This function should return the API version implemented by this module and in order for the module to be loaded this version must match module API version supported by Zabbix. Version of module API supported by Zabbix is ZBX_MODULE_API_VERSION. So this function should return this constant. Old constant ZBX_MODULE_API_VERSION_ONE used for this purpose is now defined to equal ZBX_MODULE_API_VERSION to preserve source compatibility,​ but it's usage is not recommended.
Line 41: Line 41:
 The optional functions are **zbx_module_init()**,​ **zbx_module_item_list()**,​ **zbx_module_item_timeout()**,​ **zbx_module_history_write_cbs()** and **zbx_module_uninit()**:​ The optional functions are **zbx_module_init()**,​ **zbx_module_item_list()**,​ **zbx_module_item_timeout()**,​ **zbx_module_history_write_cbs()** and **zbx_module_uninit()**:​
  
-<file c>+<code c>
 int zbx_module_init(void);​ int zbx_module_init(void);​
-</file>+</code>
  
 This function should perform the necessary initialization for the module (if any). If successful, it should return ZBX_MODULE_OK. Otherwise, it should return ZBX_MODULE_FAIL. In the latter case Zabbix will not start. This function should perform the necessary initialization for the module (if any). If successful, it should return ZBX_MODULE_OK. Otherwise, it should return ZBX_MODULE_FAIL. In the latter case Zabbix will not start.
  
-<file c>+<code c>
 ZBX_METRIC *zbx_module_item_list(void);​ ZBX_METRIC *zbx_module_item_list(void);​
-</file>+</code>
  
 This function should return a list of items supported by the module. Each item is defined in a ZBX_METRIC structure, see the section below for details. The list is terminated by a ZBX_METRIC structure with "​key"​ field of NULL. This function should return a list of items supported by the module. Each item is defined in a ZBX_METRIC structure, see the section below for details. The list is terminated by a ZBX_METRIC structure with "​key"​ field of NULL.
  
-<file c>+<code c>
 void zbx_module_item_timeout(int timeout); void zbx_module_item_timeout(int timeout);
-</file>+</code>
  
 If module exports **zbx_module_item_list()** then this function is used by Zabbix to specify the timeout settings in Zabbix configuration file that the item checks implemented by the module should obey. Here, the "​timeout"​ parameter is in seconds. If module exports **zbx_module_item_list()** then this function is used by Zabbix to specify the timeout settings in Zabbix configuration file that the item checks implemented by the module should obey. Here, the "​timeout"​ parameter is in seconds.
  
-<file c>+<code c>
 ZBX_HISTORY_WRITE_CBS zbx_module_history_write_cbs(void);​ ZBX_HISTORY_WRITE_CBS zbx_module_history_write_cbs(void);​
-</file>+</code>
  
 This function should return callback functions Zabbix server will use to export history of different data types. Callback functions are provided as fields of ZBX_HISTORY_WRITE_CBS structure, fields can be NULL if module is not interested in the history of certain type. This function should return callback functions Zabbix server will use to export history of different data types. Callback functions are provided as fields of ZBX_HISTORY_WRITE_CBS structure, fields can be NULL if module is not interested in the history of certain type.
  
-<file c>+<code c>
 int zbx_module_uninit(void);​ int zbx_module_uninit(void);​
-</file>+</code>
  
 This function should perform the necessary uninitialization (if any) like freeing allocated resources, closing file descriptors,​ etc. This function should perform the necessary uninitialization (if any) like freeing allocated resources, closing file descriptors,​ etc.
Line 77: Line 77:
 Each item is defined in a ZBX_METRIC structure: Each item is defined in a ZBX_METRIC structure:
  
-<file c>+<code c>
 typedef struct typedef struct
 { {
Line 86: Line 86:
 } }
 ZBX_METRIC; ZBX_METRIC;
-</file>+</code>
  
 Here, **key** is the item key (e.g., "​dummy.random"​),​ **flags** is either CF_HAVEPARAMS or 0 (depending on whether the item accepts parameters or not), **function** is a C function that implements the item (e.g., "​zbx_module_dummy_random"​),​ and **test_param** is the parameter list to be used when Zabbix agent is started with the "​-p"​ flag (e.g., "​1,​1000",​ can be NULL). An example definition may look like this: Here, **key** is the item key (e.g., "​dummy.random"​),​ **flags** is either CF_HAVEPARAMS or 0 (depending on whether the item accepts parameters or not), **function** is a C function that implements the item (e.g., "​zbx_module_dummy_random"​),​ and **test_param** is the parameter list to be used when Zabbix agent is started with the "​-p"​ flag (e.g., "​1,​1000",​ can be NULL). An example definition may look like this:
  
-<file c>+<code c>
 static ZBX_METRIC keys[] = static ZBX_METRIC keys[] =
 { {
Line 96: Line 96:
  { NULL }  { NULL }
 } }
-</file>+</code>
  
 Each function that implements an item should accept two pointer parameters, the first one of type AGENT_REQUEST and the second one of type AGENT_RESULT:​ Each function that implements an item should accept two pointer parameters, the first one of type AGENT_REQUEST and the second one of type AGENT_RESULT:​
  
-<file c>+<code c>
 int zbx_module_dummy_random(AGENT_REQUEST *request, AGENT_RESULT *result) int zbx_module_dummy_random(AGENT_REQUEST *request, AGENT_RESULT *result)
 { {
Line 109: Line 109:
  return SYSINFO_RET_OK;​  return SYSINFO_RET_OK;​
 } }
-</file>+</code>
  
 These functions should return SYSINFO_RET_OK,​ if the item value was successfully obtained. Otherwise, they should return SYSINFO_RET_FAIL. See example "​dummy"​ module below for details on how to obtain information from AGENT_REQUEST and how to set information in AGENT_RESULT. These functions should return SYSINFO_RET_OK,​ if the item value was successfully obtained. Otherwise, they should return SYSINFO_RET_FAIL. See example "​dummy"​ module below for details on how to obtain information from AGENT_REQUEST and how to set information in AGENT_RESULT.
Line 119: Line 119:
 Module can specify functions to export history data by type: Numeric (float), Numeric (unsigned), Character, Text and Log: Module can specify functions to export history data by type: Numeric (float), Numeric (unsigned), Character, Text and Log:
  
-<file c>+<code c>
 typedef struct typedef struct
 { {
Line 129: Line 129:
 } }
 ZBX_HISTORY_WRITE_CBS;​ ZBX_HISTORY_WRITE_CBS;​
-</file>+</code>
  
 Each of them should take "​history"​ array of "​history_num"​ elements as arguments. Depending on history data type to be exported, "​history"​ is an array of the following structures, respectively:​ Each of them should take "​history"​ array of "​history_num"​ elements as arguments. Depending on history data type to be exported, "​history"​ is an array of the following structures, respectively:​
  
-<file c>+<code c>
 typedef struct typedef struct
 { {
Line 182: Line 182:
 } }
 ZBX_HISTORY_LOG;​ ZBX_HISTORY_LOG;​
-</file>+</code>
  
 Callbacks will be used by Zabbix server history syncer processes in the end of history sync procedure after data is written into Zabbix database and saved in value cache. Callbacks will be used by Zabbix server history syncer processes in the end of history sync procedure after data is written into Zabbix database and saved in value cache.
Line 233: Line 233:
 After ./configure has been run in the root of Zabbix source tree as described above, just run **make** in order to build **dummy.so**. After ./configure has been run in the root of Zabbix source tree as described above, just run **make** in order to build **dummy.so**.
  
-<file c>+<code c>
 /* /*
 ** Zabbix ** Zabbix
Line 523: Line 523:
  return dummy_callbacks;​  return dummy_callbacks;​
 } }
-</file>+</code>
  
 The module exports three new items: The module exports three new items: