This is a translation of the original English documentation page. Help us make it better.

3 Прилагођене скрипте упозорења

Преглед

Ако нисте задовољни постојећим типовима медија за слање упозорења, постоји алтернативни начин да то урадите. Можете креирати скрипту која ће обрађивати обавештење на ваш начин.

Прилагођене скрипте упозорења се извршавају на Zabbix серверу. Ове скрипте морају да се налазе у директоријуму наведеном у параметру конфигурационе датотеке сервера AlertScriptsPath.

Ево примера прилагођене скрипте упозорења:

#!/bin/bash
       
       to=$1
       subject=$2
       body=$3
       host=$4
       value=$5
       
       cat <<EOF | mail -s "$subject" "$to"
       $body
       
       Host: $host
       Value: $value
       EOF

Zabbix проверава излазни код извршених команди и скрипти. Сваки излазни код, који се разликује од 0, сматра се грешком извршење команде. У таквим случајевима, Zabbix ће покушати да понови неуспело извршење.

Променљиве окружења се не чувају нити креирају за скрипту, тако да њима треба експлицитно руковати.

Configuration

To configure custom alert scripts as a media type:

  1. Go to Alerts → Media types.
  2. Click on Create media type.

The Media type tab contains general media type attributes:

All mandatory input fields are marked with a red asterisk.

The following parameters are specific for the script media type:

Parameter Description
Script name Enter the name of the script file (e.g., notification.sh) that is located in the directory specified in the server configuration file AlertScriptsPath parameter.
Script parameters Add optional script parameters that will be passed to the script as command-line arguments in the order in which they are defined.

Script parameters support {ALERT.SENDTO}, {ALERT.SUBJECT}, {ALERT.MESSAGE} macros, and all macros that are supported in notifications, as well as user macros.

See common media type parameters for details on how to configure default messages and alert processing options.

Even if an alert script does not use default messages, the message templates for operation types used by this media type must still be defined. Otherwise, a notification will not be sent.

If more than one script media type is configured, these scripts may be processed in parallel by the alerter processes. The total number of alerter processes is limited by the server configuration file StartAlerters parameter.

Media type testing

To test a configured script media type:

  1. Locate the relevant script in the list of media types.

  2. Click on Test in the last column of the list; a testing form will open in a pop-up window. The testing form will contain the same number of parameters that are configured for the script media type.

  3. Edit the script parameter values if needed. Editing only affects the test procedure; the actual values will not be changed.

  4. Click on Test.

When testing a configured script media type, {ALERT.SENDTO}, {ALERT.SUBJECT}, {ALERT.MESSAGE} and user macros will resolve to their values, but macros that are related to events (e.g., {HOST.HOST}, {ITEM.LASTVALUE}, etc.) will not resolve, as during testing there is no related event to get the details from. Note that macros within {ALERT.SUBJECT} and {ALERT.MESSAGE} macros will also not resolve. For example, if the value of {ALERT.SUBJECT} is composed of "Problem: {EVENT.NAME}" then the {EVENT.NAME} macro will not be resolved.

Кориснички медији

Када је тип медија конфигурисан, идите у одељак Корисници → Корисници и уредите кориснички профил тако што ћете кориснику доделити овај тип медија. Кораци за подешавање корисничких медија, који су заједнички за све типове медија, описани су на страници Типови медија.

Имајте на уму да када дефинишете кориснички медиј, поље Пошаљи не може бити празно. Ако се ово поље не користи у скрипти упозорења, унесите било коју комбинацију подржаних знакова да бисте заобишли захтеве валидације.