How to Set Up Zabbix Trigger Actions for Email Alerts and Remote Commands
This guide walks through configuring Zabbix trigger actions to send email notifications, define users and media types, create a Python alert script, enable remote command execution, and automate SSH service recovery when a trigger fires.
Configure Email Alert Action
First create a trigger action that sends an email when a trigger condition is met.
Define the action conditions and the operations to be performed. Steps 1‑5 send a message every 30 minutes using the zabbix_send.py script. If the problem is not acknowledged within two hours, a second set of operations notifies the admin group every 15 minutes, twice.
Define recovery and update operations to notify the admin when the issue is resolved or when its status changes.
Configure Users and Media Types
Set up a Zabbix user with an email address and assign a media type that takes three parameters: recipient, subject, and message body.
Edit /etc/zabbix/zabbix_server.conf to add the script path: AlertScriptsPath=/usr/lib/zabbix/alertscripts Restart the Zabbix server and place the zabbix_send.py script in the alertscripts directory with execution permission. chmod +x zabbix_send.py Create a graph directory for chart images and grant write permissions.
mkdir -p /usr/lib/zabbix/alertscripts/graph && chmod 777 -R /usr/lib/zabbix/alertscripts/graphEmail Script (Python)
#!/usr/bin/python
#coding=utf-8
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
import smtplib, sys, os, time, re, requests
user='Admin' # Zabbix user
password='zabbix'
graph_path='/usr/lib/zabbix/alertscripts/graph'
graph_url='http://192.168.179.132/chart.php'
loginurl='http://192.168.179.132/index.php'
host='192.168.179.132'
to_email=sys.argv[1]
subject=sys.argv[2].decode('utf-8')
smtp_host='smtp.163.com'
from_email='[email protected]'
mail_pass='asd1234'
# Functions get_itemid, get_graph, text_to_html, send_mail, run omitted for brevityConfigure Remote Command Action
Enable remote commands on the Zabbix agent: EnableRemoteCommands=1 Allow the Zabbix user to run commands without a password by editing /etc/sudoers:
Defaults !requiretty
zabbix ALL=(ALL) NOPASSWD: ALLTest the setup with:
zabbix_get -s 192.168.179.132 -k "system.run[sudo df -h]"Create a Restart‑SSH Script
#/bin/bash
systemctl restart sshdMake the script executable:
chmod +x /restart_ssh.shCreate Monitoring Item, Trigger, and Action
Define an item that checks the SSH port, create a trigger that fires when the port is down, and add an action that runs the restart script after a two‑minute delay.
Trigger the alarm by stopping the SSH service: systemctl stop sshd After two minutes Zabbix executes the script, and the service is restarted, which can be verified with:
zabbix_get -s 192.168.179.132 -k net.tcp.port[192.168.179.132,22]The guide encourages readers to share feedback and collaborate.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Ops Development Stories
Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
