2to3/manual: check_iface-dns.py

This commit is contained in:
Sven Velt 2020-12-29 22:33:22 +01:00
parent e396d5a4a4
commit f5bf5494c6

View file

@ -1,11 +1,11 @@
#!/usr/bin/env python #!/usr/bin/env python3
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
##################################################################### #####################################################################
# (c) 2006-2011 by Sven Velt and team(ix) GmbH, Nuernberg, Germany # # (c) 2006-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" #
# a fork of "team(ix) Monitoring Plugins" in 2015 # # a fork of "team(ix) Monitoring Plugins" in 2015 #
@ -31,25 +31,24 @@ import struct
import sys import sys
try: try:
from monitoringplugin import SNMPMonitoringPlugin 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)
def get_ipv4_address(iface): def get_ipv4_address(iface):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(sock.fileno(), 0x8915, struct.pack('256s', iface[:15]))[20:24]) return socket.inet_ntoa(fcntl.ioctl(sock.fileno(), 0x8915, struct.pack('256s', bytes(iface[:15], 'utf-8')))[20:24])
plugin = MonitoringPlugin(pluginname='check_iface-dns', tagforstatusline='IFACE-DNS', description='Check interface address vs. DNS', version='0.1') plugin = MonitoringPlugin(pluginname='check_iface-dns', tagforstatusline='IFACE-DNS', description='Check interface address vs. DNS', version='0.1')
@ -74,7 +73,8 @@ plugin.parse_cmdlineoptions()
# Get IP from interface # Get IP from interface
try: try:
ip_iface = get_ipv4_address(plugin.options.iface) ip_iface = get_ipv4_address(plugin.options.iface)
except IOError, (errno, strerror): except IOError as xxx_todo_changeme:
(errno, strerror) = xxx_todo_changeme.args
if errno == 19: if errno == 19:
plugin.back2nagios(2, 'Interface "%s" does not exist!' % plugin.options.iface) plugin.back2nagios(2, 'Interface "%s" does not exist!' % plugin.options.iface)
elif errno == 99: elif errno == 99:
@ -120,7 +120,7 @@ else:
else: else:
plugin.add_multilineoutput('OK - "%s" resolves to "%s"' % (dns, ip_dns)) plugin.add_multilineoutput('OK - "%s" resolves to "%s"' % (dns, ip_dns))
if len(failed_dns) == 0: if len(failed_dns) == 0:
plugin.add_returncode(0) plugin.add_returncode(0)
plugin.add_output('All DNS objects have a correct IP') plugin.add_output('All DNS objects have a correct IP')