LoginSignup
11
8

More than 5 years have passed since last update.

Zabbix アラートスクリプトの引数

Posted at

Zabbix でアラートスクリプト実行時に渡される引数について。

Zabbix 2.2 / 2.4

Zabbix 2.2 / 2.4 は、send_to, subject, message の順。

該当のコードは、以下。この後にcmdが実行される。

  • Zabbix 2.2
src/zabbix_server/alerter/alerter.c
            zbx_snprintf_alloc(&cmd, &cmd_alloc, &cmd_offset, " '%s' '%s' '%s'", send_to, subject, message);

  • Zabbix 2.4
src/zabbix_server/alerter/alerter.c
            zbx_snprintf_alloc(&cmd, &cmd_alloc, &cmd_offset, " '%s' '%s' '%s'", send_to, subject, message);

Zabbix 3.0

Zabbix 3 では、マクロで引数を指定できる。

Script parameters に、{ALERT.SENDTO}{ALERT.SUBJECT}{ALERT.MESSAGE}を指定すると、2 系と同じ動きになる。

該当コードは、以下。この後にcmdが実行される。

src/zabbix_server/alerter/alerter.c
            for (pstart = mediatype->exec_params; NULL != (pend = strchr(pstart, '\n')); pstart = pend + 1)
            {
                char    *param_esc;

                param_offset = 0;

                zbx_strncpy_alloc(&param, &param_alloc, &param_offset, pstart, pend - pstart);

                substitute_simple_macros(NULL, NULL, NULL, NULL, NULL, NULL, NULL, alert, NULL, &param,
                        MACRO_TYPE_ALERT, NULL, 0);

                param_esc = zbx_dyn_escape_shell_single_quote(param);

                zbx_snprintf_alloc(&cmd, &cmd_alloc, &cmd_offset, " '%s'", param_esc);

                zbx_free(param_esc);
            }
11
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
8