Zabbix 創(chuàng)建月度統(tǒng)計(jì)報(bào)表腳本(學(xué)習(xí)筆記十六)

一、腳本:

#!/bin/bash

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

# @version 0.1

# @date 2017-12-31

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

USER1="zabbix

PASSWORD1="123456"

HOST1="localhost"

DATABASE1="zabbix"

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

rm -rf /tmp/zabbix_statics.csv

mysql -h${HOST1} -u${USER1} -p${PASSWORD1} -D${DATABASE1}

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 -hIP -uroot -p密碼 -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(now(),'%Y-%m') group by host,hostname,triggerdescription order by count(*) desc;"

sed -i "1i告警次數(shù),主機(jī)名,主機(jī)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


二、報(bào)表格式如下:


三、zabbix表參考:

https://www.cnblogs.com/learningJAVA/p/7886164.html

https://blog.csdn.net/hy_timer/article/details/72082004

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容