Группа :: Мониторинг
Пакет: nagios-plugins-nginx
Главная Изменения Спек Патчи Sources Загрузить Gear Bugs and FR Repocop
Патч: port-to-python3.patch
Скачать
Скачать
diff --git a/check_nginx b/check_nginx
index 8b5513c..6b62ca7 100755
--- a/check_nginx
+++ b/check_nginx
@@ -1,4 +1,4 @@
-#!/usr/bin/python2
+#!/usr/bin/python3
# -*- coding: utf-8 -*-
# check_nginx is a Nagios to monitor nginx statu
# my blog: http://www.nginxs.com
@@ -6,12 +6,12 @@
# MSN: yangzi2008@126.com
import string
-import urllib2
+import urllib.request, urllib.error, urllib.parse
import getopt
import sys
def usage():
- print """check_nginx is a Nagios to monitor nginx status
+ print("""check_nginx is a Nagios to monitor nginx status
Usage:
check_nginx [-h|--help][-U|--url][-P|--path][-u|--user][-p|--passwd][-w|--warning][-c|--critical]
@@ -37,7 +37,7 @@ def usage():
if dont't have password:
./check_nginx -U www.nginxs.com -P /status -w 1000 -c 2000
if don't have path and password:
- ./check_nginx -U www.nginxs.com -w 1000 -c 2000"""
+ ./check_nginx -U www.nginxs.com -w 1000 -c 2000""")
sys.exit(3)
@@ -65,16 +65,16 @@ for name,value in options:
critical = value
try:
if 'path' in dir():
- req = urllib2.Request(url+path)
+ req = urllib.request.Request(url+path)
else:
- req = urllib2.Request(url)
+ req = urllib.request.Request(url)
if 'user' in dir() and 'passwd' in dir():
- passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
+ passman = urllib.request.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url+path, user, passwd)
- authhandler = urllib2.HTTPBasicAuthHandler(passman)
- opener = urllib2.build_opener(authhandler)
- urllib2.install_opener(opener)
- response = urllib2.urlopen(req)
+ authhandler = urllib.request.HTTPBasicAuthHandler(passman)
+ opener = urllib.request.build_opener(authhandler)
+ urllib.request.install_opener(opener)
+ response = urllib.request.urlopen(req)
the_page = response.readline()
conn = the_page.split()
ActiveConn = conn[2]
@@ -90,18 +90,18 @@ try:
perfdata = 'ActiveConn:%s,reading:%s,writing:%s,waiting:%s' % (ActiveConn,reading,writing,waiting)
except Exception:
- print "NGINX STATUS unknown: Error while getting Connection"
+ print("NGINX STATUS unknown: Error while getting Connection")
sys.exit(3)
if 'warning' in dir() and 'critical' in dir():
if ActiveConn >= warning:
- print 'WARNING - %s|%s' % (output,perfdata)
+ print('WARNING - %s|%s' % (output,perfdata))
sys.exit(2)
elif ActiveConn >= critical:
- print 'CRITICAL - %s|%s' % (output,perfdata)
+ print('CRITICAL - %s|%s' % (output,perfdata))
sys.exit(1)
else:
- print 'OK - %s|%s' % (output,perfdata)
+ print('OK - %s|%s' % (output,perfdata))
sys.exit(0)
else:
- print 'OK - %s|%s' % (output,perfdata)
+ print('OK - %s|%s' % (output,perfdata))
sys.exit(0)
--
2.25.2