在之前的很多zabbix的文章中并未提起zabbix Actions,Actions动作完成自愈,在我看来需要对zabbix做规划后使用较妥Actions可以在指定的条件下触发操作,这些操作可以是一个脚本也可以是一段信息,并且可以指定机器进行发送通常使用于报警介质和运行其他脚本达到预期的目的
示例
当redis端口挂掉后进行重新启动redis创建一个items如下:这里使用zabbix-agent,type不能为active,action不支持
创建action
configuration->create action->action参考:https://www.zabbix.com/documentation/3.2/manual/config/notifications/action
configuration->create action->action->operations参考:https://www.zabbix.com/documentation/3.2/manual/config/notifications/action/operation
agent机器配置
注释requiretty
[root@linuxea-Node61 /data/rds]# sed -i 's/Defaults requiretty/#Defaults requiretty/g' /etc/sudoers && cat /etc/sudoers|grep Defaults
添加sudo文件
[root@linuxea-Node61 /data/rds]# echo 'zabbix ALL=(root)NOPASSWD:/usr/bin/docker rm -f redis,/usr/local/bin/docker-compose -f /data/rds/docker-compose.yaml up -d' >> /etc/sudoers
修改zabbix-agentd配置文件
[root@linuxea-Node61 /data/rds]# sed -i 's/# EnableRemoteCommands=0/EnableRemoteCommands=1/g' /etc/zabbix/zabbix_agentd.conf
[root@linuxea-Node61 /data/rds]# sed -i 's/# LogRemoteCommands=0/LogRemoteCommands=1/g' /etc/zabbix/zabbix_agentd.conf
测试
当redis 6379端口关闭zabbix server日志会抛出日志
[root@linuxea-Node114 /var/log/zabbix]# grep sudo zabbix_server.log
5891:20170927:222228.830 slow query: 0.002530 sec, "insert into alerts (alertid,actionid,eventid,clock,message,status,error,esc_step,alerttype) values (13,7,44551,1506522148,'10.0.1.61:sudo /usr/bin/docker rm -f redis && sudo /usr/local/bin/docker-compose -f /data/rds/docker-compose.yaml up -d',1,'',1,1);
zabbix-agent端也会有日志抛出,并且执行成功
[root@linuxea-Node61 /data/rds]# tail -f /var/log/zabbix/zabbix_agentd.log -f
13953:20170927:221641.462 **************************
13953:20170927:221641.462 using configuration file: /etc/zabbix/zabbix_agentd.conf
13953:20170927:221641.462 agent #0 started [main process]
13967:20170927:221641.462 agent #1 started [collector]
13968:20170927:221641.463 agent #2 started [listener #1]
13969:20170927:221641.463 agent #3 started [listener #2]
13974:20170927:221641.465 agent #5 started [active checks #1]
13973:20170927:221641.465 agent #4 started [listener #3]
13969:20170927:222416.166 Executing command 'sudo /usr/bin/docker rm -f redis && sudo /usr/local/bin/docker-compose -f /data/rds/docker-compose.yaml up -d'
报警消失