When developing custom alert scripts or even just meaningful notifications in Zabbix, it’s important to test your changes frequently. This can be difficult given that Zabbix does not currently offer any means to immediately fire a test notification.

The purpose of this article is to describe how to configure Zabbix in 5 to 10 minutes so that you can toggle a trigger on demand from the command line, which will in turn create an event, call an action and then most importantly, send an alert (A.K.A notification or message) to enable testing with faster feedback.

To achieve this, the following steps detail how to create a dummy text item and a trigger which will fire every time the value of the dummy items changes. Instruction is also provided for creating the required media types and actions, and finally, triggering a notification on demand using zabbix_sender.

Create an item

First create a dummy item. Navigate to the desired host or template (a pre-canned template is included below) and select Items > Create Item.

The Zabbix trapper item type enables an agent (or in our case zabbix_sender) to submit an item value to the Zabbix server at any time; without waiting for polling intervals or active check batch sends. We’ll use a simple Text value type for storing an arbitrary timestamp as follows:

  • Name: Test timestamp
  • Type: Zabbix trapper
  • Key: test.timestamp
  • Type of information: Text
  • Enabled: checked
  • Click Add to save

Add an item

Create a trigger

Next create a trigger which will fire each time the value of the timestamp item changes. On your host or template, navigate to Triggers > Create trigger.

Use the diff() trigger function to identify a change in value. Also, ensure Multiple PROBLEM events generation is checked to ensure an event (and subsequent notification) is created every time the item value changes; not just the first time.

  • Name: Timestamp changed
  • Expression: {[host/template]:test.timestamp.diff()}>0 (replace host/template)
  • Multiple PROBLEM events generation: checked
  • Severity: Any (except Not classified)
  • Click Add to save

Add an item

Create a media type

If you intend to call a custom alert script when your trigger changes state, first define a new media type (under Administration > Media types > Create media type) with the name of your script as follows:

  • Type: Script
  • Script name: [Filename of your script]
  • Enabled: checked
  • Click Add to save

Add an item

Zabbix also requires at least one user to “send” to using your new media type so define contact media as follows (from Administration > Users > [User] > Media > Add):

  • Type: [Media type defined above]
  • Send to: [Recipient passed to script]
  • Click Add to save the media
  • Click Update to save the user

Add an item

Create an action

Navigate to Configuration > Actions > Create action and enter a desirable name, default subject and message for your action. Select the Conditions tab and add a new condition with:

  • New condition: Trigger = [dummy trigger]
  • Click Add to save the condition

Add an item

Select the Operations tab and add a new operation as follows:

  • Send to Users: [user with custom media type]
  • Send only to: [custom media type]
  • Click Add to save to the operation

Add an item

Finally, click Add to save the action.

Toggle the trigger

To put the trigger into a PROBLEM state, simply submit a value for your test item using zabbix_sender that is different to the previous value. The simplest way to generate a new value on each command line call is to embed a timestamp using $(date --rfc-3339=ns). Send a new value to the Zabbix server with the following (taking care to replace all argument values with the correct values for your environment):

$ VALUE="$(date --rfc-3339=ns)"; zabbix_sender \
  	--zabbix-server=127.0.0.1 \
  	--host="Zabbix server" \
  	--key="test.timestamp" \
  	--value="${VALUE}"

To put the trigger back into an OK state (and cause a ‘Recovery message’ to be sent), simply resubmit the same item value by running the zabbix_sender command again without making a change to the VALUE environment variable:

$ zabbix_sender \
  	--zabbix-server=127.0.0.1 \
  	--host="Zabbix server" \
  	--key="test.timestamp" \
  	--value="${VALUE}"

Template

The following XML document is a Zabbix v2.2+ template which contains the Items and Triggers described in this article.

For more information concerning Zabbix configuration import and export see the Zabbix documentation.

<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
    <version>2.0</version>
    <date>2015-10-01T06:36:53Z</date>
    <groups>
        <group>
            <name>Templates</name>
        </group>
    </groups>
    <templates>
        <template>
            <template>Dummy triggers</template>
            <name>Dummy triggers</name>
            <description/>
            <groups>
                <group>
                    <name>Templates</name>
                </group>
            </groups>
            <applications>
                <application>
                    <name>Testing</name>
                </application>
            </applications>
            <items>
                <item>
                    <name>Test timestamp</name>
                    <type>2</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>test.timestamp</key>
                    <delay>0</delay>
                    <history>90</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>4</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>0</delta>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <formula>1</formula>
                    <delay_flex/>
                    <params/>
                    <ipmi_sensor/>
                    <data_type>0</data_type>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>Testing</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                </item>
            </items>
            <discovery_rules/>
            <macros/>
            <templates/>
            <screens/>
        </template>
    </templates>
    <triggers>
        <trigger>
            <expression>{Dummy triggers:test.timestamp.diff()}&gt;0</expression>
            <name>Timestamp changed</name>
            <url/>
            <status>0</status>
            <priority>5</priority>
            <description/>
            <type>1</type>
            <dependencies/>
        </trigger>
    </triggers>
</zabbix_export>