2to3: check_apaches plus manual work
This commit is contained in:
parent
195b0c5b90
commit
407d99c45d
|
@ -1,10 +1,10 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
# (c) 2007-2011 by Sven Velt and team(ix) GmbH, Nuernberg, Germany #
|
# (c) 2007-2011 by Sven Velt and team(ix) GmbH, Nuernberg, Germany #
|
||||||
# sv@teamix.net #
|
# sv@teamix.net #
|
||||||
# (c) 2016 by Sven Velt, Germany #
|
# (c) 2016- by Sven Velt, Germany #
|
||||||
# sven-mymonplugins@velt.biz #
|
# sven-mymonplugins@velt.biz #
|
||||||
# #
|
# #
|
||||||
# This file is part of "velt.biz - My Monitoring Plugins" #
|
# This file is part of "velt.biz - My Monitoring Plugins" #
|
||||||
|
@ -28,26 +28,30 @@
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import urllib2
|
import urllib.request, urllib.error, urllib.parse
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from monitoringplugin import MonitoringPlugin
|
from MyMonPlugin import MonitoringPlugin
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print '=========================='
|
print('==========================')
|
||||||
print 'AIKS! Python import error!'
|
print('AIKS! Python import error!')
|
||||||
print '==========================\n'
|
print('==========================\n')
|
||||||
print 'Could not find "monitoringplugin.py"!\n'
|
print('Could not find class "MonitoringPlugin"!\n')
|
||||||
print 'Did you download "%s"' % os.path.basename(sys.argv[0])
|
print('Did you download "%s"' % os.path.basename(sys.argv[0]))
|
||||||
print 'without "monitoringplugin.py"?\n'
|
print('without "MyMonPlugin/"?\n')
|
||||||
print 'Please go back to'
|
print('Please go back to')
|
||||||
print 'https://gogs.velt.biz/velt.biz/MyMonPlugins and download it,'
|
print('https://gogs.velt.biz/velt.biz/MyMonPlugins and:')
|
||||||
print 'or even better:'
|
print('- get a full archive at http://gogs.velt.biz/velt.biz/MyMonPlugins/releases')
|
||||||
print 'get a full archive at http://gogs.velt.biz/velt.biz/MyMonPlugins/releases'
|
print('- or a master snapshot at http://gogs.velt.biz/velt.biz/MyMonPlugins/archive/master.tar.gz\n')
|
||||||
print 'or a master snapshot at http://gogs.velt.biz/velt.biz/MyMonPlugins/archive/master.tar.gz\n'
|
|
||||||
sys.exit(127)
|
sys.exit(127)
|
||||||
|
|
||||||
|
|
||||||
plugin = MonitoringPlugin(pluginname='check_apaches', tagforstatusline='APACHE', description='Check Apache workers', version='0.1')
|
plugin = MonitoringPlugin(
|
||||||
|
pluginname='check_apaches',
|
||||||
|
tagforstatusline='APACHE',
|
||||||
|
description='Check Apache workers',
|
||||||
|
version='0.1',
|
||||||
|
)
|
||||||
|
|
||||||
plugin.add_cmdlineoption('-H', '', 'host', 'Hostname/IP to check', default='localhost')
|
plugin.add_cmdlineoption('-H', '', 'host', 'Hostname/IP to check', default='localhost')
|
||||||
plugin.add_cmdlineoption('-p', '', 'port', 'port to connect', default=None)
|
plugin.add_cmdlineoption('-p', '', 'port', 'port to connect', default=None)
|
||||||
|
@ -76,20 +80,22 @@ if plugin.options.httpauth:
|
||||||
httpauth = plugin.options.httpauth.split(':')
|
httpauth = plugin.options.httpauth.split(':')
|
||||||
if len(httpauth) != 2:
|
if len(httpauth) != 2:
|
||||||
plugin.back2nagios(3, 'Wrong format of authentication data! Need "USERNAME:PASSWORD", got "' + plugin.options.httpauth + '"')
|
plugin.back2nagios(3, 'Wrong format of authentication data! Need "USERNAME:PASSWORD", got "' + plugin.options.httpauth + '"')
|
||||||
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
|
passman = urllib.request.HTTPPasswordMgrWithDefaultRealm()
|
||||||
passman.add_password(None, url, httpauth[0], httpauth[1])
|
passman.add_password(None, url, httpauth[0], httpauth[1])
|
||||||
authhandler = urllib2.HTTPBasicAuthHandler(passman)
|
authhandler = urllib.request.HTTPBasicAuthHandler(passman)
|
||||||
opener = urllib2.build_opener(authhandler)
|
opener = urllib.request.build_opener(authhandler)
|
||||||
urllib2.install_opener(opener)
|
urllib.request.install_opener(opener)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = urllib2.urlopen(url).read()
|
data = urllib.request.urlopen(url).read()
|
||||||
except urllib2.HTTPError, e:
|
except urllib.error.HTTPError as e:
|
||||||
plugin.back2nagios(2, 'Could not read data! ' + str(e))
|
plugin.back2nagios(2, 'Could not read data! ' + str(e))
|
||||||
except urllib2.URLError, e:
|
except urllib.error.URLError as e:
|
||||||
plugin.back2nagios(2, 'Could not connect to server!')
|
plugin.back2nagios(2, 'Could not connect to server!')
|
||||||
|
|
||||||
plugin.verbose(2, 'Got data:\n' + data)
|
data = data.decode()
|
||||||
|
plugin.verbose(2, 'Got data:')
|
||||||
|
plugin.verbose(2, data)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
idle = int(re.search('Idle(?:Workers|Servers): (\d+)\n', data).group(1))
|
idle = int(re.search('Idle(?:Workers|Servers): (\d+)\n', data).group(1))
|
||||||
|
|
Loading…
Reference in a new issue