一、zatree for zabbix-2.4.6
1、下载zatree
git clone https://github.com/spide4k/zatree.git zatree
git clone https://github.com/BillWang139967/zatree.git //3.0+
2、复制zatree至httpd访问目录下:
sudo cp zatree/zabbix-2.4.5/zatree-zabbix-2.4.5 /var/www/html/zabbix
3、修改权限
sudo chown -R apache.apache /var/www/html/zabbix
4、修改zabbix配置,以使能够连接至数据库
cd /var/www/html/zabbix
sudo vim conf/zabbix.conf.php
$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = '192.168.10.15';
$DB['PORT'] = '3306';
$DB['DATABASE'] = 'zabbix'; //数据库名
$DB['USER'] = 'zabbix'; //数据库用户
$DB['PASSWORD'] = 'zabbix'; //数据库密码
// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';
$ZBX_SERVER = '192.168.10.15';
$ZBX_SERVER_PORT = '10051'; //zabbix监听端口
$ZBX_SERVER_NAME = 'zabbix'; //主机名
5、修改zabbix登录用的用户名和密码
sudo vim zatree/zabbix_config.php
'api_url'=>'api_jsonrpc.php',
'user'=>'admin',
'password'=>'zabbix',
6、删除没用的图片信息
sudo vim zatree/graph.php
<!--
<div align="center" style='font-size:12px;'>
<font size="5px" color="red">运维帮,一个技术分享订阅号,扫描我,给我们力量</font><br> <font size="2px" color="red">编辑 zatree/graph.php 文件删除我</font><br>
<img src="static/yunweibang-weixin.jpg" /><br>
<a href="https://github.com/spide4k/zatree" target="_blank">Zatree</a> version 2.4 for Zabbix 2.4.x, 技术支持QQ群: 271659981, 微信订阅号:yunweibang
</div>
-->
7、修改zatree标签的链接的错误(红色处为修改的地方)
sudo vim zatree/header.php
<body>
<ul class="menu" id="menu">
<li><a href="/zabbix/index.php" target="xiaFrame" rel="index.php">首页</a></li>
<li><a href="zabbix.php" target="xiaFrame" rel="zabbix.php">HostGraph</a></li>
<li><a href="peckvalue.php" target="xiaFrame" rel="peckvalue.php">Peckvalue-Table</a></li>
<li><a href="echart.php" target="xiaFrame" rel="echart.php">Peckvalue-Echart</a></li>
</ul>
sudo vim zatree/echart.php
<frameset rows="30,*" border="1">
<frame name="header" scrolling="no" src="header.php" />
<frameset cols="220,*" frameborder="1" border="2" framespacing="0" bordercolor="#d0d0d0"`>
<frame src="echart_left.php" name="leftFrame" id="leftFrame" title="leftFrame" />
<frame src="echart_zabbix.php" name="rightFrame" id="rightFrame" title="rightFrame" />
</frameset>
</frameset>
sudo vim zatree/peckvalue.php
<frameset rows="30,*" border="1">
<frame name="header" scrolling="no" src="header.php" />
<frameset cols="220,*" frameborder="1" border="2" framespacing="0" bordercolor="#d0d0d0">
<frame src="peckvalue_left.php" name="leftFrame" id="leftFrame" title="leftFrame" />
<frame src="peckvalue_zabbix.php" name="rightFrame" id="rightFrame" title="rightFrame" />
</frameset>
</frameset>
sudo vim zatree/zabbix.php
<frameset rows="30,*" border="1">
<frame name="header" scrolling="no" src="header.php" />
<frameset cols="236,*" frameborder="1" border="2" framespacing="0" bordercolor="#d0d0d0">
<frame src="left.php" name="leftFrame" id="leftFrame" title="leftFrame" />
<frame src="graph.php" name="rightFrame" id="rightFrame" title="rightFrame" />
</frameset>
</frameset>
8、如果出现下面的警告,可在php的配置文件中增加一行
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/zabbix/zatree/graph.php:9) in /var/www/html/zabbix/zatree/graph.php
sudo vim /etc/php.ini
output_buffering = on
9、重启zabbix_server服务
sudo /etc/init.d/zabbix_server restart
完成zatree的配置。
二、zabbix discovery
Configuration --> Discovery --> Create discovery rule
配置name,IP range(支持网段),Delay,Check type,port range,key
Configuration --> Actions --> Create action (Event source Discovery)
配置name
添加定义好的discovery rule,
Received value 模糊匹配主机名
添加配置后的主机放置的组Add to host groups
发现的主机使用的模板Link to templates
配置zabbix server的/etc/hosts 增加要发现的主机ip和对应的主机名,效果如下:
三、进程发现及监控
1、发现进程名(合并数组)
vim check_process_jqlm.sh
#!/bin/bash
array1=($(ps aux|grep [b]eam|awk '{print $36}'|awk '/data/{print $0}'|awk -F "/" '{print $(NF)}'|awk '{sub(/"$/,"")}1'))
array2=($(ps aux|grep [b]eam|awk '{print $37}'|awk '/data/{print $0}'|awk -F "/" '{print $(NF)}'|awk '{sub(/"$/,"")}1'))
array=(${array1[@]} ${array2[@]})
COUNT=${#array[@]}
INDEX=0
echo '{"data":['
for a in ${array[@]};do
echo -n '{"{#PROCESSNAME}":"'$a'"} '
INDEX=`expr $INDEX + 1`
if [ $INDEX -lt $COUNT ]; then
echo ','
fi
done
echo ']}'
结果:
PS:非数组格式保存的情况下
#!/bin/bash
array=$(ps aux|egrep "[g]amed|[w]orldd" --color|awk -F "/" '{print $NF}')
COUNT=`echo "$array" |wc -l`
INDEX=0
echo '{"data":['
# echo "$array" | while read LINE; do
for a in ${array[@]};do
echo -n '{"{#PROCESSNAME}":"'$a'"}'
INDEX=`expr $INDEX + 1`
if [ $INDEX -lt $COUNT ]; then
echo ','
fi
done
echo ']}'
2、获取该进程的cpu,mem,status
vim check_resource_jqlm.sh
#!/bin/bash
process=$1
if [ ! -n "${process}" ];then
exit 1
else
if [ $# -eq 2 ] ; then
basename=$(echo $0|awk -F "." '{print $1}')
name=$2
case $2 in
cpu)
ps aux|grep "${process}" -w|egrep -v "grep|${basename}" |awk '{print $3}'
;;
mem)
ps aux|grep "${process}" -w|egrep -v "grep|${basename}"|awk '{print $6/1024}'
;;
"${process}")
ps aux|grep "${process}" -w|egrep -v "grep|${basename}"|wc -l
;;
esac
else
echo 0
fi
fi
3、配置zabbix_agentd.conf并重启
UnsafeUserParameters=1
UserParameter=jqlm_proc.discovery,/tmp/check_process_jqlm.sh
UserParameter=jqlm_proc.rec[*],/tmp/check_resource_jqlm.sh $1 $2
4、zabbix面板配置
1)、创建发现规则名字
2)、创建发现items
3)、依次创建相关items
四、zabbix3.0实现告警配置
1)、邮件
故障{TRIGGER.STATUS},服务器:{HOSTNAME}发生:{TRIGGER.NAME}
告警主机:{HOSTNAME} {HOST.IP}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息:{TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
2、短信
{TRIGGER.STATUS}:{HOSTNAME}: {TRIGGER.NAME}