zabbix生成月度统计报表

简介: !/bin/bash##############################@version 0.1@date 2017-12-31##############################USER1="zabbix327"PASSW...

!/bin/bash

##############################

@version 0.1

@date 2017-12-31

##############################
USER1="zabbix327"
PASSWORD1="mm
HOST1="ip"
DATABASE1="zabbix"
TABLE="students"
######################
rm -rf /tmp/zabbix_statics.csv
mysql -h{HOST1} -u{USER1} -p{PASSWORD1} -D{DATABASE1}<<EOF #2>/dev/null
DROP TABLE if exists tmp_itemhost;
DROP TABLE if exists tmp_trigger;
DROP TABLE if exists tmp_triggeritem;
CREATE TABLE tmp_itemhost (
hostid int(20),
host varchar(1280),
hostname varchar(1280),
itemid int(20),
itemname varchar(1280),
itemkey varchar(1280),
itemport varchar(128) null,
itemstate int(20)
) ;
INSERT INTO tmp_itemhost(hostid,host,hostname,itemid,itemname,itemkey,itemport,itemstate)
(
select hosts.hostid,hosts.host,hosts.name,items.itemid,items.name,items.key_,items.port,items.state
from items left join hosts
on items.hostid=hosts.hostid
);

CREATE TABLE tmp_trigger(
triggerid int(20),
itemid int(20),
description varchar(1280),
priority int(20)
);
INSERT INTO tmp_trigger(triggerid,itemid,description,priority)
select triggers.triggerid,functions.itemid,triggers.description,triggers.priority
from triggers left join functions
on triggers.triggerid=functions.triggerid;

CREATE TABLE tmp_triggeritem(
triggerid int(20),
triggerdescription varchar(1280),
triggerpriority int(20),
hostid int(20),
host varchar(1280),
hostname varchar(1280),
itemid int(20),
itemname varchar(1280),
itemkey varchar(1280),
itemport varchar(128) null,
itemstate int(20)
) ;
INSERT INTO tmp_triggeritem(triggerid,triggerdescription,triggerpriority,hostid,host,hostname,itemid,itemname,itemkey,itemport,itemstate)
(
select tmp_trigger.triggerid,tmp_trigger.description,tmp_trigger.priority,hostid,host,hostname,tmp_itemhost.itemid,itemname,itemkey,itemport,itemstate
from tmp_trigger left join tmp_itemhost
on tmp_trigger.itemid=tmp_itemhost.itemid
);
EOF

mysql -h172.16.50.21 -uroot -pXmrbi3967968@ -Dzabbix -e "select count(),host,hostname,triggerdescription
into outfile '/tmp/zabbix_statics.csv' fields terminated by ',' optionally enclosed by ' ' lines terminated by '\r\n' from events left join tmp_triggeritem
on events.objectid=tmp_triggeritem.triggerid where events.source=0 and events.object=0 and events.value=1
and date_format(FROM_UNIXTIME(clock),'%Y-%m')=date_format(date +'%Y%m%d' -d '-1 days','%Y-%m') group by host,hostname,triggerdescription order by count(
) desc;"

sed -i "1i告警次数,主机名,主机IP,告警消息" /tmp/zabbix_statics.csv
sed -i "s/{HOST.NAME}//g" /tmp/zabbix_statics.csv
sed -i "s#\# #g" /tmp/zabbix_statics.csv

yy=(date +%Y) mm=(date +%m)
aa=cat /tmp/zabbix_statics.csv
mv /tmp/zabbix_statics.csv /tmp/zabbix_{yy}{mm}_statics.csv

目录
相关文章
|
监控 BI API
利用ZABBIX进行服务器自动巡检并导出报表
利用ZABBIX进行服务器自动巡检并导出报表
利用ZABBIX进行服务器自动巡检并导出报表
|
监控 数据建模 BI
Zabbix自动生成报表并发送邮件
Zabbix自动生成报表并发送邮件
Zabbix自动生成报表并发送邮件
|
监控 BI Perl
Zabbix 创建月度统计报表脚本(学习笔记十六)
一、脚本: #!/bin/bash ############################## # @version 0.1 # @date 2017-12-31 ############################## USER1="zabbi...
1266 0
|
运维 监控 关系型数据库
|
消息中间件 监控 Java
基于dropwizard/metrics ,kafka,zabbix构建应用统计数据收集展示系统
新blog地址:http://hengyunabc.github.io/about-metrics/ 想要实现的功能 应用可以用少量的代码,实现统计某类数据的功能 统计的数据可以很方便地展示 metrics metrics,按字面意思是度量,指标。
1336 0
|
22天前
|
监控 Java Shell
监控堆外第三方监控工具Zabbix
监控堆外第三方监控工具Zabbix
33 5

推荐镜像

更多
下一篇
DataWorks