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

Docs/specs/ZBXNEXT-2163

From Zabbix.org
Jump to: navigation, search

Custom parameter support for script media type

ZBXNEXT-2163

Status: v1.1

Owner: Andris Zeila

Summary

Currently Zabbix passes 3 hardcoded parameters to the Script media type scripts - send to, subject and message. Zabbix should allow user to customize the parameters that are passed to this script.

Specification

The Script media parameters are defined by media_type table exec_params field and must support new built-in alert macros:

  • {ALERT.SENDTO} - 'Send to' value from user media type configuration
  • {ALERT.SUBJECT} - 'Default subject' value from action configuration
  • {ALERT.MESSAGE} - 'Default message' value from action configuration


Frontend changes

User should be add script parameters one by one similarly to the user macros:

                       .-----------------------------.
           Script name | notification.sh             |
                       '-----------------------------'

                       .-----------------------------.
     Script parameters | {ALERT.SENDTO}              | Remove
                       '-----------------------------'

                       .-----------------------------.
                       | {ALERT.SUBJECT}             | Remove
                       '-----------------------------'

                       .-----------------------------.
                       | {ALERT.MESSAGE}             | Remove
                       '-----------------------------'

                        Add


                       .----------.  .----------.   .----------.  .----------.
                       |  Update  |  |  Clone   |   |  Delete  |  |  Cancel  |
                       '----------'  '----------'   '----------'  '----------'

The parameters are stored in media_type table exec_params field separated by newline character. The last parameter must also have newline character at the end. The leading and trailing whitespace characters are left intact. For example parameters:

<space>leading
trailing<space><space>
<space><space><space>

Will be saved as

<space>leading<newline>trailing<space><space><newline><space><space><space><newline>

The parameters are escaped and strong quoted by server before passing them to the script.

When creating new Script media the initial 'Script parameters' fields must be pre-filled with macros compatible with the current parameter format:

{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}

Server Changes

A new macro type MACRO_TYPE_ALERT supporting {ALERT.SENDTO}, {ALERT.SUBJECT} and {ALERT.MESSAGE} macros must be added.

When processing Script media type server must expand the alert macros for each parameter, quote the resulting parameters, assemble final command line and call the script.

API changes

Media type object must support a new exec_params field.

Translation strings

  • Script parameters

Database changes

A new field must be added to media_type table:

FIELD		|exec_params	|t_varchar(255)	|''	|NOT NULL	|ZBX_NODATA

A database patch must be added to set exec_params field to {ALERT.SENDTO}\n{ALERT.SUBJECT}\n{ALERT.MESSAGE}\n for the existing Script media types.

Documentation

Also discussed

  • Manual ordering of script parameters will not be implemented for now.

ChangeLog

  • v1.1 Changed script parameter input method
  • v1.0 Initial version