zabbix lld监控oracle,zabbix实战--Zabbix lld发现web状态监控

一、软件版本

操作系统:CentOS-6.5-x86_64

zabbix版本:3.0.3

二、脚本参考:

1、python版本:

#!/usr/bin/env python

#coding:utf-8

import os,sys,json

#将要监控的web站点url添加到urllist列表

urllist=['www.baidu.com','www.hao123.com']

#这个函数主要是构造出一个特定格式的字典,用于zabbix

def web_site_discovery():

web_list=[]

web_dict={"data":None}

for url in urllist:

url_dict={}

url_dict["{#SITENAME}"]=url

web_list.append(url_dict)

web_dict["data"]=web_list

jsonStr = json.dumps(web_dict, sort_keys=True, indent=4)

return jsonStr

#这个函数用于测试站点返回的状态码,注意在cmd命令中如果有%{}这种字符要使用占位符代替,否则

#会报错

def web_site_code():

cmd='curl -o /dev/null -s -w %s %s' %("%",sys.argv[2])

reply_code=os.popen(cmd).readlines()[0]

return reply_code

if __name__ == "__main__":

try:

if sys.argv[1] == "web_site_discovery":

print web_site_discovery()

elif sys.argv[1] == "web_site_code":

print web_site_code()

else:

print "Pls sys.argv[0] web_site_discovery | web_site_code[URL]"

except Exception as msg:

print msg

2、shell的脚本方式:

#!/bin/bash

# Script to fetch nginx statuses for tribily monitoring systems

web=('www.baidu.com' 'www.hao123.com’)

function webdiscovery(){

length=${#web[@]}

printf "{\n"

printf  '\t'"\"data\":["

for ((i=0;i

do

printf '\n\t\t{'

printf "\"{#NAME}\":\"$\"}"

if [ $i -lt $[$length-1] ];then

printf ','

fi

done

printf  "\n\t]\n"

printf "}\n"

}

function web_site_code()

"$1"

}

$1 $2

3、zabbix_agent定义的key,以shell脚本为例:

[root@xiaoluo zabbix_agentd.conf.d]# cat web.conf

UserParameter=get_web,/usr/local/zabbix/script/web_discovery.sh webdiscovery

UserParameter=get_web_code[*],/usr/local/zabbix/script/web_discovery.sh web_site_code $1

4、测试key没问题之后,剩下的就是web ui的设置,具体可以参考自带的lld发现磁盘,或者查看视频

关注微信:

1460000008002380?w=132&h=132

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值