zabbix configuration example alarm message SMS alarm Zabbix

Zabbix SMS Alarm example

Zabbix SMS alarm Example:

Note zabbix script file in the default directory is placed alertscripts (zabbix action calls the script directory)

# Edit zabbix_server.conf 
# AlertScriptsPath DATADIR = $ {} / ZABBIX / alertscripts 
# default in more than four rows

2. Create a text alarm script sms.sh

Copy the code
CAT alertscripts # / sms.sh

! # / Bin / bash LOGFILE = " /var/log/sms.log " # script log file:> " $ LOGFILE " Exec 1> " $ LOGFILE " Exec 2> & 1 Mobile = $ 1 # 2 # $ phone number is not used = $ content . 3 # = message content XXD " / usr / bin / xxd The " TIMEOUT = . 5 MESSAGE_ENCODE = $ (echo " $ content " | $ {} XXD -PS | Sed ' S / \ (.. \) /% \. 1 / G '| TR -d ' \ n- ' ) -d # SMS encoding process curl "$} = {Mobile Mobile Content & MESSAGE_ENCODE = $ {} "HTTP: //172.16.5.110/ SMS / # Configure interface to send SMS Submit; http://172.16.5.110/sms interface address of a short message, Test #: # / alertscripts /sms.sh 1.88 billion "" " send a test alarm " # script executes first argument is the phone number; the second set empty; the third parameter is the message contents # script execution, to the log file /. var / log / sms.log in to see the return value greater than 0 if the representatives sent successfully, it failed to send less than 0.
Copy the code

3, modify the script to execute permissions j

chown -R zabbix:zabbix alertscripts/sms.sh

4, test scripts:

./alertscripts/sms.sh 1.88 billion "" " Send a test alarm " # script executes first argument is the phone number; the second set empty; the third parameter is the message content. # After execution of the script, to the log file /var/log/sms.log in to see the return value greater than 0 if the representatives sent successfully, failed to send less than 0.

5, Zabbix platform configuration.

 The script name and server configuration file names consistent sms.sh 

 

Add User: (may be configured to a user group)

Alarm Action Configuration: (Select [Event Source] [trigger])

配置 【动作】 - 【条件】 - 【操作】 (默认配置 或者更改为中文标题 )

Copy the code
默认接收人
故障{TRIGGER.STATUS},服务器:{HOSTNAME1}发生: {TRIGGER.NAME}故障
默认信息
告警主机:{HOSTNAME1} 告警时间:{EVENT.DATE} {EVENT.TIME} 告警等级:{TRIGGER.SEVERITY} 告警信息: {TRIGGER.NAME} 告警项目:{TRIGGER.KEY1} 问题详情:{ITEM.NAME}:{ITEM.VALUE} 当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1} 事件ID:{EVENT.ID}
Copy the code

报警 【条件】 配置: (也可以默认)

 报警 【操作】 配置 (默认的 管理员账户组权限,可以加一个 报警账户组 )

默认配置事件 -  操作账户 - 发送方式  短信脚本。

 

 

Zabbix 短信报警 示例:

注意zabbix 脚本文件默认放置目录是 alertscripts (zabbix 动作调用脚本目录)

# 编辑 zabbix_server.conf
# AlertScriptsPath=${datadir}/zabbix/alertscripts
# 默认在 四百多行

2、创建短信报警脚本  sms.sh

Copy the code
# cat alertscripts/sms.sh

#!/bin/bash LOGFILE="/var/log/sms.log" # 脚本日志文件 :>"$LOGFILE" exec 1>"$LOGFILE" exec 2>&1 mobile=$1 # 手机号 # $2没有用到 content=$3 # 短信内容 XXD="/usr/bin/xxd" TIMEOUT=5 MESSAGE_ENCODE=$(echo "$content" | ${XXD} -ps | sed 's/\(..\)/%\1/g' | tr -d '\n') # 短信编码处理 curl -d "mobile=${mobile}&content=${MESSAGE_ENCODE}" http://172.16.5.110/sms/ # 配置提交短信接口发送; http://172.16.5.110/sms 为短信接口地址, # 测试: # /alertscripts/sms.sh 1880000000 "" "发送报警测试" # 脚本执行第一个参数为手机号;第二个设置空;第三个参数为短信内容。 # 脚本执行后,到日志文件 /var/log/sms.log 里查看返回值,如果大于0代表发送成功,小于0发送失败。
Copy the code

3、修改j脚本执行权限

chown -R zabbix:zabbix alertscripts/sms.sh

4、测试脚本:

./alertscripts/sms.sh 1880000000 "" "发送报警测试" # 脚本执行第一个参数为手机号;第二个设置空;第三个参数为短信内容。 # 脚本执行后,到日志文件 /var/log/sms.log 里查看返回值,如果大于0代表发送成功,小于0发送失败。

5、Zabbix 平台配置。

 脚本名称和服务端配置的文件名一致 sms.sh 

 

添加 用户: (可以配置成 一个用户组)

报警动作 配置 :  (【事件源】 选择 【 触发器 】)

Configuration [action] - [condition] - [Operation] (the default configuration or change the Chinese title)

Copy the code
The default recipient
fault {TRIGGER.STATUS}, server: {HOSTNAME1} occurs: {TRIGGER.NAME} failure
The default message
alarm host: {HOSTNAME1} Alarm Time: {EVENT.DATE} {EVENT.TIME} alarm level: {TRIGGER.SEVERITY} alarms: {TRIGGER.NAME} alarm project: {TRIGGER.KEY1} details of the problem: {ITEM .NAME}: {ITEM.VALUE} current status: {TRIGGER.STATUS}: {ITEM.VALUE1} event ID: {EVENT.ID}
Copy the code

[Configuration] Alarm conditions: (may default)

 [Operation] alarm configuration (default Administrator account group permissions, you can add an alarm Account Group)

The default configuration event - Operating Account - Send as SMS script.

 

 

Guess you like

Origin www.cnblogs.com/hcs88/p/12394223.html