当前位置:首页 » 编程语言 » zabbix微信python

zabbix微信python

发布时间: 2023-07-07 14:23:37

A. 监控常用的应用软件有什么

常用的有:
1.cactio

实际上cacti不是监控工具,而是个依赖于SNMP的数据采集和数据呈现的工具。但是很多人喜欢用来当监控(因为其功能可以很好的完成这个工作)

功能:数据采集、 保存数据[SQL, txt].
数据展示(rrdtool 绘图)。
数据分析和报警(很一般)。

2. nagios。

功能:数据报警(报警功能是Nagios的特色功能) [ 故障触发,故障恢复都可以。
依赖分析报警(能自动的识别到关键设备的故障,关联设备不会报警)。

数据采集(采集的数据是弱项,他只关心警戒位,只关心正常与否的状态,状态转换时可以实现报警,所以它采集的数据不需要保存),当然也有插件弥补这个不足,如PNP4Nagios。

3. zabbix (php)(推荐)

Nagiostcacti整合互相弥补不足!I

nagios和 cacti不适合超大规模的监控、由于大规模的带宽和网络限制,会导致监控的延迟等问题,所以有很多是 nagios+ cacti整合,但是依然不适合在大规模的环境中,不适合分布式部署, Nagios在大规模中就会出现延迟,失
去 Nagios本事的特色。
那么 zabbix同时整合了 cacti和 Nagios特点的工具,而且还具有了前两者不具有的工具,支持分布式等等。

4. 补充工具:

netdata:托管在github上的一款类型zabbix的开源监控工具https:/
/github. com/firehol/netdata
open- falcon:小米公司开源的企业级监控工具(python)(推荐)
Ganglia类似于 zabbix,大型分布式监控系统

开源监控工具对比http://www.oschina.net/news/67525/monitoring-tools

5. 监控软件数据采集的方式

SNMP 协议。
agent 代理的方式去采集数据。
shell 脚本api 接口

6. 数据展示方式

php html app

7. 数据告警

mail,msm,微信,电话,钉钉机器人

B. 请教各位一个问题zabbix怎样用shell或者python调用短信接口api进行发短信

2.填上发短信脚本的名称 zabbix 实战短信报警之调用短信接口3.注意zabbix_server.conf里面的配置,指定脚本放的位置及赋予脚本执行和属主zabbix

C. 如何采用Python zabbix

一:安装zabbix api 接口,修改zabbix api 调用接口,获取数据、

from zabbix_api import ZabbixAPI
import sys
import datetime
import time
import argparse

def fetch_to_csv(username,password,server,hostname,key,output,datetime1,datetime2,debuglevel):
zapi = ZabbixAPI(server=server, log_level=debuglevel)
try:
zapi.login(username, password)
except:
print "zabbix server is not reachable: %s" % (server)
sys.exit()
host = zapi.host.get({"filter":{"host":hostname}, "output":"extend"})
if(len(host)==0):
print "hostname: %s not found in zabbix server: %s, exit" % (hostname,server)
sys.exit()
else:
hostid=host[0]["hostid"]
print '*' * 100
print key
print '*' * 100
if(key==""):
print '*' * 100
items = zapi.item.get({"filter":{"hostid":hostid} , "output":"extend"})
if(len(items)==0):
print "there is no item in hostname: %s, exit" % (hostname)
sys.exit()
dict={}
for item in items:
dict[str(item['itemid'])]=item['key_']
if (output == ''):
output=hostname+".csv"
f = open(output, 'w')
str1="#key;timestamp;value\n"

if (datetime1=='' and datetime2==''):
for itemid in items:
itemidNr=itemid["itemid"]
str1=str1+itemid["key_"]+";"+itemid["lastclock"]+";"+itemid["lastvalue"]+"\n"
f.write(str1)
print "Only the last value from each key has been fetched, specify t1 or t1 and t2 to fetch more data"
f.close()
elif (datetime1!='' and datetime2==''):
try:
d1=datetime.datetime.strptime(datetime1,'%Y-%m-%d %H:%M:%S')
except:
print "time data %s does not match format Y-m-d H:M:S, exit" % (datetime1)
sys.exit()
timestamp1=time.mktime(d1.timetuple())
timestamp2=int(round(time.time()))
inc=0
history = zapi.history.get({"hostids":[hostid,],"time_from":timestamp1,"time_till":timestamp2, "output":"extend" })
for h in history:
str1=str1+dict[h["itemid"]]+";"+h["clock"]+";"+h["value"]+"\n"
inc=inc+1
f.write(str1)
f.close()
print str(inc) +" records has been fetched and saved into: " + output
elif (datetime1=='' and datetime2!=''):
for itemid in items:
itemidNr=itemid["itemid"]
str1=str1+itemid["key_"]+";"+itemid["lastclock"]+";"+itemid["lastvalue"]+"\n"
f.write(str1)
print "Only the last value from each key has been fetched, specify t1 or t1 and t2 to fetch more data"
f.close()
else:
try:
d1=datetime.datetime.strptime(datetime1,'%Y-%m-%d %H:%M:%S')
except:
print "time data %s does not match format Y-m-d H:M:S, exit" % (datetime1)
sys.exit()
try:
d2=datetime.datetime.strptime(datetime2,'%Y-%m-%d %H:%M:%S')
except:
print "time data %s does not match format Y-m-d H:M:S, exit" % (datetime2)
sys.exit()
timestamp1=time.mktime(d1.timetuple())
timestamp2=time.mktime(d2.timetuple())
inc=0

history =
zapi.history.get({"hostids":[hostid,],"time_from":timestamp1,"time_till":timestamp2,
"output":"extend" })
for h in history:
str1=str1+dict[h["itemid"]]+";"+h["clock"]+";"+h["value"]+"\n"
inc=inc+1
f.write(str1)
f.close()
print str(inc) +" records has been fetched and saved into: " + output
else:
#print "key is: %s" %(key)
itemid = zapi.item.get({"filter":{"key_":key, "hostid":hostid} , "output":"extend"})
if(len(itemid)==0):
print "item key: %s not found in hostname: %s" % (key,hostname)
sys.exit()
itemidNr=itemid[0]["itemid"]
if (output == ''):
output=hostname+".csv"
f = open(output, 'w')
str1="#key;timestamp;value\n"

if (datetime1=='' and datetime2==''):
str1=str1+key+";"+itemid[0]["lastclock"]+";"+itemid[0]["lastvalue"]+"\n"
#f.write(str1)
f.write(str1)
f.close()
print "Only the last value has been fetched, specify t1 or t1 and t2 to fetch more data"
elif (datetime1!='' and datetime2==''):
d1=datetime.datetime.strptime(datetime1,'%Y-%m-%d %H:%M:%S')
timestamp1=time.mktime(d1.timetuple())
timestamp2=int(round(time.time()))

history =
zapi.history.get({"history":itemid[0]["value_type"],"time_from":timestamp1,"time_till":timestamp2,
"itemids":[itemidNr,], "output":"extend" })
inc=0
for h in history:
str1 = str1 + key + ";" + h["clock"] +";"+h["value"] + "\n"
inc=inc+1
f.write(str1)
f.close()
print str(inc) +" records has been fetched and saved into: " + output
elif (datetime1=='' and datetime2!=''):
str1=str1+key+";"+itemid[0]["lastclock"]+";"+itemid[0]["lastvalue"]+"\n"
f.write(str1)
f.close()
print "Only the last value has been fetched, specify t1 or t1 and t2 to fetch more data"
else:
d1=datetime.datetime.strptime(datetime1,'%Y-%m-%d %H:%M:%S')
d2=datetime.datetime.strptime(datetime2,'%Y-%m-%d %H:%M:%S')
timestamp1=time.mktime(d1.timetuple())
timestamp2=time.mktime(d2.timetuple())

history =
zapi.history.get({"history":itemid[0]["value_type"],"time_from":timestamp1,"time_till":timestamp2,
"itemids":[itemidNr,], "output":"extend" })
inc=0
for h in history:
str1 = str1 + key + ";" + h["clock"] +";"+h["value"] + "\n"
inc=inc+1
print str(inc) +" records has been fetched and saved into: " + output
f.write(str1)
f.close()

二:撰写通过key获取一周内的数据

items : 在zabbix 中搜索主机,选择最新数据,找到项目(items),点击进入,能看到机器的所有keys,在负载到程序的items 字典中,程序会循环读取items ,获取数据

#/usr/bin/env python
#-*-coding:UTF-8

import os,sys,time

users=u'admin'
pawd = 'zabbix'

exc_py = '/data/zabbix/fetch_items_to_csv.py'
os.system('easy_install zabbix_api')
os.system('mkdir -p /data/zabbix/cvs/')

if not os.path.exists(exc_py):
os.system("mkdir -p /data")

os.system("wget
http://doc.bonfire-project.eu/R4.1/_static/scripts/fetch_items_to_csv.py
-O /data/zabbix/fetch_items_to_csv.py")

def work():
moniter='192.168.1.1'

ip_list =
['192.168.1.15','192.168.1.13','192.168.1.66','192.168.1.5','192.168.1.7','192.168.1.16','192.168.1.38','192.168.1.2','192.168.1.13','192.168.1.10']

for ip in ip_list:
show_items(moniter,ip )

if __name__ == "__main__":
sc = work()

三:数据采集完毕,进行格式化输出

#!/usr/bin/env python
#-*-coding:utf8-*-
import os,sys,time
workfile = '/home/zabbix/zabbix/sjz/'
def collect_info():
dict_doc = dict()
for i in os.listdir(workfile):
dict_doc[i] = list()
for v in os.listdir('%s%s' %(workfile,i)):
dict_doc[i].append(v)

count = 0
for x,y in dict_doc.items():
for p in y:
fp = '%s/%s/%s' %(workfile,x,p)
op = open(fp,'r').readlines()
np = '%s.txt' %p
os.system( """ cat %s|awk -F";" '{print $3}' > %s """ %(fp,np))
count += 1
print count
if __name__ == "__main__":
sc = collect_info()

四,整理数据,汇报成图形,撰写技术报告

热点内容
多个ip段怎么配置网关 发布:2025-02-09 05:57:23 浏览:413
体检中心的无线网密码多少 发布:2025-02-09 05:40:15 浏览:515
脚本语言是编译还是解释 发布:2025-02-09 05:30:24 浏览:642
天墓密码结局是什么 发布:2025-02-09 05:25:52 浏览:437
如何找回因特网帐号的密码 发布:2025-02-09 05:20:05 浏览:373
树莓派源码 发布:2025-02-09 05:07:00 浏览:651
安卓手机为什么搜不到懂球帝 发布:2025-02-09 05:04:42 浏览:817
生命密码解读走什么 发布:2025-02-09 04:55:51 浏览:279
python常用正则表达式 发布:2025-02-09 04:42:53 浏览:179
机器人编程培训哪家好 发布:2025-02-09 04:37:44 浏览:308