See www.zabbix.com for the official Zabbix site.

Docs/specs/ZBXNEXT-2650

From Zabbix.org
Jump to: navigation, search

Provide to a users with mechanism to create user-defined Zabbix trigger functions.

ZBXNEXT-2650

Status: Initial draft, do not comment

Owner: Vladimir Ulogov

Summary

Files involved in proposed change

The pretty trivial modification of the following file(s):

  • libs/zbxserver/evalfunc.c
  • libs/zbxmodules/modules.c

And change in module API (backward compatible), will permit end-user to create user-defined trigger functions.

Changing the order of functions resolution

By introducing new configuration parameter, we can also permit to users to re-define internal trigger functions. Proposed configuration introduction is:

TriggerUserFunctionFirst=[0|1]

  • If set to '0', which shall be default, Zabbix fill resolve standard trigger functions internally, then will try to resolve User defined trigger functions;
  • If set to '1', Zabbix will try to resolve function in Zabbix Loadable Modules, if resolution is failed, the search will continue in standard trigger functions list.

Specification

Details

Here is general "userfunction resolution algorithm"

ZBXNEXT-2650 1.svg

Changes in libs/zbxserver/evalfunc.c

In the function evaluate_function():

  • Check if TriggerUserFunctionFirst == 0
  • If "YES", then proceed with resolving internal trigger functions, at the end, if buffer is not holding value (i.e. function is "not resolved") call zbx_find_usertriggerfunction() defined in libs/zbxmodules/modules.c
  • If "NO", call zbx_find_usertriggerfunction() defined in libs/zbxmodules/modules.c. At the end, if buffer is not holding value (i.e. function is "not resolved") proceed with internal functions resolution
  • If after ether choices buffer is still not initialized, return FAIL, otherwise SUCCESS

Changes in libs/zbxmodules/modules.c

Define the function char* zbx_find_usertriggerfunction(const char *function, DC_ITEM *item, const char *parameter, time_t now)

Inside this function, we will parse parameter and will handle both seconds/number of the elements and timeshifts. Then using zbx_vc_get_value_range(...) will get the history of the item inside "zbx_vector_history_record_t"

Then for all initialized modules, we will do the following loop:

  • dlsym function with name "zbx_user_function()" in the module
  • this function shall be defined as "char* zbx_user_function(const char *function, zbx_vector_history_record_t *values)"
  • pass the function name and connected parameters
  • if this function return NULL, go to next module. Otherwise return this value to the buffer passwd to evaluate_function()


Zabbix Loadable Module API changes

If user wants to resolve any user-defined trigger functions in his module, he have to define the following function in his module:

"char* zbx_user_function(const char *function, zbx_vector_history_record_t *values)"

If function is not defined, this module will be skipped during "trigger functions discovery". Inside this module, user shall build own mechanizm for resolving the function with name passed as "const char *function", ether through "if() elif" or through dynamic resolution of the functions written in high-level languages.

Frontend

We do need to somehow feed information about user-defined trigger functions to the frontend.

Database changes

None planned

Documentation

ChangeLog

  • N/A