community.zabbix.zabbix_mediatype – Create/Update/Delete Zabbix media types

Note

This plugin is part of the community.zabbix collection (version 1.5.1).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.zabbix.

To use it in a playbook, specify: community.zabbix.zabbix_mediatype.

Synopsis

  • This module allows you to create, modify and delete Zabbix media types.

Requirements

The below requirements are needed on the host that executes this module.

  • zabbix-api >= 0.5.4

Parameters

Parameter

Comments

attempt_interval

integer

The interval between retry attempts.

Possible range is 0-60.

Works only with Zabbix versions 3.4 or newer.

Default: 10

description

string

Description of the media type.

Works only with Zabbix versions 4.4 or newer.

Default: “”

event_menu

boolean

Can be used when type=webhook.

Includes entry in Event menu with link to created external ticket.

Choices:

  • no ← (default)

  • yes

event_menu_name

string

Requred when event_menu=True.

Event menu entry name.

event_menu_url

string

Requred when event_menu=True.

Event menu entry underlying URL.

gsm_modem

string

Serial device name of the gsm modem.

Required when type=sms.

http_login_password

string

Basic Auth password

http_login_user

string

Basic Auth login

login_password

string / required

Zabbix user password.

If not set the environment variable ZABBIX_PASSWORD will be used.

login_user

string / required

Zabbix user name.

If not set the environment variable ZABBIX_USERNAME will be used.

max_attempts

integer

The maximum number of attempts to send an alert.

Possible range is 0-10.

Works only with Zabbix versions 3.4 or newer.

Default: 3

max_sessions

integer

The maximum number of alerts that can be processed in parallel.

Possible value is 1 when type=sms and 0-100 otherwise.

Works only with Zabbix versions 3.4 or newer.

Default: 1

message_templates

list / elements=dictionary

Default notification messages for the event types.

Works only with Zabbix versions 5.0 or newer.

Default: []

body

string

Body of the default message.

May contain macros.

Default: “”

eventsource

string

Event source.

Required when recovery is used.

Choices:

  • triggers

  • discovery

  • autoregistration

  • internal

recovery

string

Operation mode.

Required when eventsource is used.

Choices:

  • operations

  • recovery_operations

  • update_operations

subject

string

Subject of the default message.

May contain macros and is limited to 255 characters.

Default: “”

message_text_limit

string

The message text limit.

Required when type=ez_texting.

160 characters for USA and 136 characters for Canada.

Choices:

  • USA

  • Canada

name

string / required

Name of the media type.

password

string

Authentication password.

Required when type=jabber or type=ez_texting.

Required when type=email and smtp_authentication=true.

process_tags

boolean

Can be used when type=webhook.

Process returned JSON property values as tags.

These tags are added to the already existing (if any) problem event tags in Zabbix.

Choices:

  • no ← (default)

  • yes

script_name

string

The name of the executed script.

Required when type=script.

script_params

list / elements=string

List of script parameters.

Required when type=script.

server_url

aliases: url

string / required

URL of Zabbix server, with protocol (http or https). url is an alias for server_url.

If not set the environment variable ZABBIX_SERVER will be used.

smtp_authentication

boolean

Whether SMTP authentication with username and password should be enabled or not.

If set to true, username and password should be specified.

Choices:

  • no ← (default)

  • yes

smtp_email

string

Email address from which notifications will be sent.

Required when type=email.

smtp_helo

string

SMTP HELO.

Required when type=email.

Default: “localhost”

smtp_security

string

SMTP connection security level to use.

Choices:

  • None

  • STARTTLS

  • SSL/TLS

smtp_server

string

SMTP server host.

Required when type=email.

Default: “localhost”

smtp_server_port

integer

SMTP server port.

Required when type=email.

Default: 25

smtp_verify_host

boolean

SSL verify host for SMTP.

Can be specified when smtp_security=STARTTLS or smtp_security=SSL/TLS

Choices:

  • no ← (default)

  • yes

smtp_verify_peer

boolean

SSL verify peer for SMTP.

Can be specified when smtp_security=STARTTLS or smtp_security=SSL/TLS

Choices:

  • no ← (default)

  • yes

state

string

Desired state of the mediatype.

On present, it will create a mediatype if it does not exist or update the mediatype if the associated data is different.

On absent, it will remove the mediatype if it exists.

Choices:

  • present ← (default)

  • absent

status

string

Whether the media type is enabled or no.

Choices:

  • enabled ← (default)

  • disabled

timeout

integer

The timeout of API request (seconds).

Default: 10

type

string / required

Type of the media type.

Media types jabber and ez_texting works only with Zabbix versions 4.2 or older.

Media type webhook works only with Zabbix versions 4.4 or newer.

Choices:

  • email

  • script

  • sms

  • webhook

  • jabber

  • ez_texting

username

string

Username or Jabber identifier.

Required when type=jabber or type=ez_texting.

Required when type=email and smtp_authentication=true.

validate_certs

boolean

If set to False, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates.

If not set the environment variable ZABBIX_VALIDATE_CERTS will be used.

Choices:

  • no

  • yes ← (default)

webhook_params

list / elements=dictionary

Can be used when type=webhook.

Webhook variables that are passed to webhook script when executed.

Default: []

name

string / required

Name of the parameter.

value

string

Value of the parameter.

All macros that are supported in problem notifications are supported in the parameters.

Values are URL-encoded automatically. Values from macros are resolved and then URL-encoded automatically.

Default: “”

webhook_script

string

Required when type=webhook.

JavaScript code that will perform webhook operation.

This code has access to all parameters in webhook_params.

It may perform HTTP GET, POST, PUT and DELETE requests and has control over HTTP headers and request body.

It may return OK status along with an optional list of tags and tag values or an error string.

Works only with Zabbix versions 4.4 or newer.

webhook_timeout

string

Can be used when type=webhook.

Execution timeout for JavaScript code in webhook_script.

Possible values are 1-60s.

Default: “30s”

Notes

Note

  • If you use login_password=zabbix, the word “zabbix” is replaced by “****” in all module output, because login_password uses no_log. See this FAQ for more information.

Examples

- name: 'Create an email mediatype with SMTP authentication'
  community.zabbix.zabbix_mediatype:
    name: "Ops email"
    server_url: "http://example.com/zabbix/"
    login_user: Admin
    login_password: "zabbix"
    type: 'email'
    smtp_server: 'example.com'
    smtp_server_port: 2000
    smtp_email: '[email protected]'
    smtp_authentication: true
    username: 'smtp_user'
    password: 'smtp_pass'

- name: 'Create a script mediatype'
  community.zabbix.zabbix_mediatype:
    name: "my script"
    server_url: "http://example.com/zabbix/"
    login_user: Admin
    login_password: "zabbix"
    type: 'script'
    script_name: 'my_script.py'
    script_params:
      - 'arg1'
      - 'arg2'

- name: 'Create a jabber mediatype'
  community.zabbix.zabbix_mediatype:
    name: "My jabber"
    server_url: "http://example.com/zabbix/"
    login_user: Admin
    login_password: "zabbix"
    type: 'jabber'
    username: 'jabber_id'
    password: 'jabber_pass'

- name: 'Create a SMS mediatype'
  community.zabbix.zabbix_mediatype:
    name: "My SMS Mediatype"
    server_url: "http://example.com/zabbix/"
    login_user: Admin
    login_password: "zabbix"
    type: 'sms'
    gsm_modem: '/dev/ttyS0'

# Supported since Zabbix 4.4
- name: 'Create a webhook mediatype'
  community.zabbix.zabbix_mediatype:
    name: "My webhook Mediatype"
    server_url: "http://example.com/zabbix/"
    login_user: Admin
    login_password: "zabbix"
    type: 'webhook'
    webhook_script: "{{ lookup('file', 'slack.js') }}"
    webhook_params:
      - name: alert_message
        value: '{ALERT.MESSAGE}'
      - name: zabbix_url
        value: '{$ZABBIX.URL}'
    process_tags: True
    event_menu: true
    event_menu_name: "Open in Slack: '{EVENT.TAGS.__channel_name}'"
    event_menu_url: '{EVENT.TAGS.__message_link}'

# Supported since Zabbix 5.0
- name: 'Create an email mediatype with message templates'
  community.zabbix.zabbix_mediatype:
    name: "Ops email"
    server_url: "http://example.com/zabbix/"
    login_user: Admin
    login_password: "zabbix"
    type: 'email'
    smtp_email: '[email protected]'
    message_templates:
      - eventsource: triggers
        recovery: operations
        subject: "Problem: {EVENT.NAME}"
        body: "Problem started at {EVENT.TIME} on {EVENT.DATE}\r\nProblem name: {EVENT.NAME}\r\n"
      - eventsource: triggers
        recovery: recovery_operations
        subject: "Resolved: {EVENT.NAME}"
        body: "Problem resolved at {EVENT.TIME} on {EVENT.DATE}\r\nProblem name: {EVENT.NAME}\r\n"
      - eventsource: triggers
        recovery: update_operations
        subject: "Updated problem: {EVENT.NAME}"
        body: "{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.\r\n"
      - eventsource: discovery
        recovery: operations
        subject: "Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}"
        body: "Discovery rule: {DISCOVERY.RULE.NAME}\r\n\r\nDevice IP: {DISCOVERY.DEVICE.IPADDRESS}"
      - eventsource: autoregistration
        recovery: operations
        subject: "Autoregistration: {HOST.HOST}"
        body: "Host name: {HOST.HOST}\r\nHost IP: {HOST.IP}\r\nAgent port: {HOST.PORT}"

Authors

  • Ruben Tsirunyan (@rubentsirunyan)