community.zabbix.zabbix_mediatype (2.3.1) — module

Create/Update/Delete Zabbix media types

Authors: Ruben Tsirunyan (@rubentsirunyan)

Install collection

Install with ansible-galaxy collection install community.zabbix:==2.3.1


Add to requirements.yml

  collections:
    - name: community.zabbix
      version: 2.3.1

Description

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


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# If you want to use Username and Password to be authenticated by Zabbix Server
- name: Set credentials to access Zabbix Server API
  ansible.builtin.set_fact:
    ansible_user: Admin
    ansible_httpapi_pass: zabbix
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# If you want to use API token to be authenticated by Zabbix Server
# https://www.zabbix.com/documentation/current/en/manual/web_interface/frontend_sections/administration/general#api-tokens
- name: Set API token
  ansible.builtin.set_fact:
    ansible_zabbix_auth_key: 8ec0d52432c15c91fcafe9888500cf9a607f44091ab554dbee860f6b44fac895
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Create an email mediatype with SMTP authentication"
  # set task level variables as we change ansible_connection plugin here
  vars:
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    ansible_httpapi_port: 443
    ansible_httpapi_use_ssl: true
    ansible_httpapi_validate_certs: false
    ansible_zabbix_url_path: "zabbixeu"  # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
    ansible_host: zabbix-example-fqdn.org
  community.zabbix.zabbix_mediatype:
    name: "Ops email"
    type: "email"
    smtp_server: "example.com"
    smtp_server_port: 2000
    smtp_email: "ops@example.com"
    smtp_authentication: true
    username: "smtp_user"
    password: "smtp_pass"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Create a script mediatype"
  # set task level variables as we change ansible_connection plugin here
  vars:
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    ansible_httpapi_port: 443
    ansible_httpapi_use_ssl: true
    ansible_httpapi_validate_certs: false
    ansible_zabbix_url_path: "zabbixeu"  # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
    ansible_host: zabbix-example-fqdn.org
  community.zabbix.zabbix_mediatype:
    name: "my script"
    type: "script"
    script_name: "my_script.py"
    script_params:
      - "arg1"
      - "arg2"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Create a jabber mediatype"
  # set task level variables as we change ansible_connection plugin here
  vars:
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    ansible_httpapi_port: 443
    ansible_httpapi_use_ssl: true
    ansible_httpapi_validate_certs: false
    ansible_zabbix_url_path: "zabbixeu"  # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
    ansible_host: zabbix-example-fqdn.org
  community.zabbix.zabbix_mediatype:
    name: "My jabber"
    type: "jabber"
    username: "jabber_id"
    password: "jabber_pass"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Create a SMS mediatype"
  # set task level variables as we change ansible_connection plugin here
  vars:
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    ansible_httpapi_port: 443
    ansible_httpapi_use_ssl: true
    ansible_httpapi_validate_certs: false
    ansible_zabbix_url_path: "zabbixeu"  # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
    ansible_host: zabbix-example-fqdn.org
  community.zabbix.zabbix_mediatype:
    name: "My SMS Mediatype"
    type: "sms"
    gsm_modem: "/dev/ttyS0"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Create a webhook mediatype"
  # set task level variables as we change ansible_connection plugin here
  vars:
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    ansible_httpapi_port: 443
    ansible_httpapi_use_ssl: true
    ansible_httpapi_validate_certs: false
    ansible_zabbix_url_path: "zabbixeu"  # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
    ansible_host: zabbix-example-fqdn.org
  community.zabbix.zabbix_mediatype:
    name: "My webhook Mediatype"
    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}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Create an email mediatype with message templates"
  # set task level variables as we change ansible_connection plugin here
  vars:
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    ansible_httpapi_port: 443
    ansible_httpapi_use_ssl: true
    ansible_httpapi_validate_certs: false
    ansible_zabbix_url_path: "zabbixeu"  # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
    ansible_host: zabbix-example-fqdn.org
  community.zabbix.zabbix_mediatype:
    name: "Ops email"
    type: "email"
    smtp_email: "ops@example.com"
    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}"

Inputs

    
name:
    description:
    - Name of the media type.
    required: true
    type: str

type:
    choices:
    - email
    - script
    - sms
    - webhook
    - jabber
    - ez_texting
    description:
    - Type of the media type.
    - Media types I(jabber) and I(ez_texting) works only with Zabbix versions 4.2 or older.
    required: true
    type: str

state:
    choices:
    - present
    - absent
    default: present
    description:
    - Desired state of the mediatype.
    - On C(present), it will create a mediatype if it does not exist or update the mediatype
      if the associated data is different.
    - On C(absent), it will remove the mediatype if it exists.
    type: str

status:
    choices:
    - enabled
    - disabled
    default: enabled
    description:
    - Whether the media type is enabled or no.
    type: str

password:
    description:
    - Authentication password.
    - Required when I(type=jabber) or I(type=ez_texting).
    - Required when I(type=email) and I(smtp_authentication=true).
    type: str

username:
    description:
    - Username or Jabber identifier.
    - Required when I(type=jabber) or I(type=ez_texting).
    - Required when I(type=email) and I(smtp_authentication=true).
    type: str

gsm_modem:
    description:
    - Serial device name of the gsm modem.
    - Required when I(type=sms).
    type: str

smtp_helo:
    default: localhost
    description:
    - SMTP HELO.
    - Required when I(type=email).
    type: str

event_menu:
    default: false
    description:
    - Can be used when I(type=webhook).
    - Includes entry in Event menu with link to created external ticket.
    type: bool

smtp_email:
    description:
    - Email address from which notifications will be sent.
    - Required when I(type=email).
    type: str

description:
    default: ''
    description:
    - Description of the media type.
    type: str

script_name:
    description:
    - The name of the executed script.
    - Required when I(type=script).
    type: str

smtp_server:
    default: localhost
    description:
    - SMTP server host.
    - Required when I(type=email).
    type: str

max_attempts:
    default: 3
    description:
    - The maximum number of attempts to send an alert.
    - Possible range is 0-10.
    type: int

max_sessions:
    default: 1
    description:
    - The maximum number of alerts that can be processed in parallel.
    - Possible value is 1 when I(type=sms) and 0-100 otherwise.
    type: int

process_tags:
    default: false
    description:
    - Can be used when I(type=webhook).
    - Process returned JSON property values as tags.
    - These tags are added to the already existing (if any) problem event tags in Zabbix.
    type: bool

script_params:
    description:
    - List of script parameters.
    - Required when I(type=script).
    elements: str
    type: list

smtp_security:
    choices:
    - None
    - STARTTLS
    - SSL/TLS
    description:
    - SMTP connection security level to use.
    type: str

event_menu_url:
    description:
    - Requred when I(event_menu=true).
    - Event menu entry underlying URL.
    type: str

webhook_params:
    default: []
    description:
    - Can be used when I(type=webhook).
    - Webhook variables that are passed to webhook script when executed.
    elements: dict
    suboptions:
      name:
        description:
        - Name of the parameter.
        required: true
        type: str
      value:
        default: ''
        description:
        - 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.
        type: str
    type: list

webhook_script:
    description:
    - Required when I(type=webhook).
    - JavaScript code that will perform webhook operation.
    - This code has access to all parameters in I(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.
    type: str

event_menu_name:
    description:
    - Requred when I(event_menu=true).
    - Event menu entry name.
    type: str

http_login_user:
    description:
    - Basic Auth login
    required: false
    type: str

webhook_timeout:
    default: 30s
    description:
    - Can be used when I(type=webhook).
    - Execution timeout for JavaScript code in I(webhook_script).
    - Possible values are 1-60s.
    type: str

attempt_interval:
    default: 10s
    description:
    - The interval between retry attempts.
    - Possible range is 0-1h.
    type: str

smtp_server_port:
    default: 25
    description:
    - SMTP server port.
    - Required when I(type=email).
    type: int

smtp_verify_host:
    default: false
    description:
    - SSL verify host for SMTP.
    - Can be specified when I(smtp_security=STARTTLS) or I(smtp_security=SSL/TLS)
    type: bool

smtp_verify_peer:
    default: false
    description:
    - SSL verify peer for SMTP.
    - Can be specified when I(smtp_security=STARTTLS) or I(smtp_security=SSL/TLS)
    type: bool

message_templates:
    default: []
    description:
    - Default notification messages for the event types.
    elements: dict
    suboptions:
      body:
        default: ''
        description:
        - Body of the default message.
        - May contain macros.
        type: str
      eventsource:
        choices:
        - triggers
        - discovery
        - autoregistration
        - internal
        description:
        - Event source.
        - Required when I(recovery) is used.
        type: str
      recovery:
        choices:
        - operations
        - recovery_operations
        - update_operations
        description:
        - Operation mode.
        - Required when I(eventsource) is used.
        type: str
      subject:
        default: ''
        description:
        - Subject of the default message.
        - May contain macros and is limited to 255 characters.
        type: str
    type: list

message_text_limit:
    choices:
    - USA
    - Canada
    description:
    - The message text limit.
    - Required when I(type=ez_texting).
    - 160 characters for USA and 136 characters for Canada.
    type: str

http_login_password:
    description:
    - Basic Auth password
    required: false
    type: str

smtp_authentication:
    default: false
    description:
    - Whether SMTP authentication with username and password should be enabled or not.
    - If set to C(true), C(username) and C(password) should be specified.
    type: bool