您现在的位置是:首页 > 文章详情

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

日期:2018-11-28点击:768

视频资源:http://www.roncoo.com/course/view/fb3050a5b34b42f39ccad83ebebc89c1 


一、软件版本

操作系统: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' %("%{http_code}",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<$length;i++))

    do

        printf '\n\t\t{'

        printf "\"{#NAME}\":\"${web[$i]}\"}"

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

                printf ','

        fi

    done

    printf  "\n\t]\n"

    printf "}\n"

}

 

function web_site_code()

{          

    /usr/bin/curl -I -m 10 -o /dev/null -s -w %{http_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发现磁盘,或者查看视频


关注微信:

face/yHBt8Yn6ENmixPDQCWswcjHCGXsnDhdy.png


原文链接:https://blog.roncoo.com/article/126416
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章