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 -*-
#####################################################################
# (c) 2006-2011 by Sven Velt and team(ix) GmbH, Nuernberg, Germany #
# sv@teamix.net #
# (c) 2016 by Sven Velt, Germany #
# sven-mymonplugins@velt.biz #
# (c) 2016- by Sven Velt, Germany #
# sven-mymonplugins@velt.biz #
# #
# This file is part of "velt.biz - My Monitoring Plugins" #
# a fork of "team(ix) Monitoring Plugins" in 2015 #
@ -31,25 +31,24 @@ import struct
import sys
try:
from monitoringplugin import SNMPMonitoringPlugin
from MyMonPlugin import MonitoringPlugin
except ImportError:
print '=========================='
print 'AIKS! Python import error!'
print '==========================\n'
print 'Could not find "monitoringplugin.py"!\n'
print 'Did you download "%s"' % os.path.basename(sys.argv[0])
print 'without "monitoringplugin.py"?\n'
print 'Please go back to'
print 'https://gogs.velt.biz/velt.biz/MyMonPlugins and download it,'
print 'or even better:'
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('==========================')
print('AIKS! Python import error!')
print('==========================\n')
print('Could not find class "MonitoringPlugin"!\n')
print('Did you download "%s"' % os.path.basename(sys.argv[0]))
print('without "MyMonPlugin/"?\n')
print('Please go back to')
print('https://gogs.velt.biz/velt.biz/MyMonPlugins and:')
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')
sys.exit(127)
def get_ipv4_address(iface):
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')
@ -74,7 +73,8 @@ plugin.parse_cmdlineoptions()
# Get IP from interface
try:
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:
plugin.back2nagios(2, 'Interface "%s" does not exist!' % plugin.options.iface)
elif errno == 99:
@ -120,7 +120,7 @@ else:
else:
plugin.add_multilineoutput('OK - "%s" resolves to "%s"' % (dns, ip_dns))
if len(failed_dns) == 0:
plugin.add_returncode(0)
plugin.add_output('All DNS objects have a correct IP')