A program that detects HTTP and HTTPS states and returns time, and the plugins that Nagios can use
The code is full of comments, and if it is unclear and where there is a mistake, please point out
#!/bin/env python#coding:utf8########################################################################### file name: check_http_status.py#description: uses Python's Pycurl module to get the return status and return time of the URL #author:pangli# mail:[email protected]######################################################################### #import pycurlimport fcntlimport sysimport osimport StringIOimport timefrom Optparse import optionparsertime = int (Time.time ()) data_path = Os.path.split (Os.path.realpath (__file__)) [0] + "/http_data/" #判断数据文件夹是否存在if not Os.path.isdir (Data_path): os.makedirs (Data_path) #返回代码: 200-207 success Status, 300-307 redirect status, Here also divided into the success of the code_rule = [200, 201, 202, 203, 204, 205, 206, 207, 300, 301, 302, 303, 304, 305, 306, 307]usage = "python % (Script_name) s -u <url|ipaddress> -w <connecttime,totaltime> -c <connecttime,totaltime> -t Execution results show
Nagios detects HTTP and HTTPS plug-ins, Python detects http and HTTPS plugins