二 编写脚本
python多线程版本
#!/usr/bin/python
#this script is used to check multiple urls within different websites from a given file which contains all the urls of different websites
#use zabbix low level discovery(LLD) to discovery different websites and different urls,and then use pycurl to check those urls,finally send the result to zabbix proxy or zabbix server using zabbix_sender
# here has two zabbix macros: {#WEBSITE_NAME} and {#WEBSITE_URL}
# tested on zabbix 3.0
#
#written by john wang
#
#curl_easy_perform()
# |
# |--NAMELOOKUP
# |--|--CONNECT
# |--|--|--APPCONNECT
# |--|--|--|--PRETRANSFER
# |--|--|--|--|--STARTTRANSFER
# |--|--|--|--|--|--TOTAL
# |--|--|--|--|--|--REDIRECT
import json
import logging
import os,sys,time
import threading
import Queue
import subprocess
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
import pycurl
# We should ignore SIGPIPE when using pycurl.NOSIGNAL - see
# the libcurl tutorial for more info.
try:
import signal
from signal import SIGPIPE,SIG_ING
signal.signal(signal.SIGPIPE,signal.SIG_IGN)
except ImportError:
pass
# need a given txt file contains urls
#eg.
#baiduwww.baidu.com
#taobao www.taobao.com
try:
if sys.argv[1]=="-":
urls=sys.stdin.readlines()
else:
urls=open(sys.argv[1],'rb').readlines()
#print urls
except:
print "Usage: %s check_urls.txt (list_websites)" %sys.argv[0]
raise SystemExit