Commit c1cfdd7d2195452c822428e05414ff2433573978

Authored by Frederik Lindenaar
1 parent bbad51d9

updated plugins to python3

made specifying which temperatur for plugins/check_temperature mandatory
plugins/check_otp
1 -#! /usr/bin/env python 1 +#! /usr/bin/env python3
2 # 2 #
3 # check_otp - Nagios check plugin for LinOTP/PrivacyIDEA OTP validation 3 # check_otp - Nagios check plugin for LinOTP/PrivacyIDEA OTP validation
4 # 4 #
5 -# Version 1.1, latest version, documentation and bugtracker available at: 5 +# Version 1.2, latest version, documentation and bugtracker available at:
6 # https://gitlab.lindenaar.net/scripts/nagios-plugins 6 # https://gitlab.lindenaar.net/scripts/nagios-plugins
7 # 7 #
8 -# Copyright (c) 2018 Frederik Lindenaar 8 +# Copyright (c) 2018 - 2024 Frederik Lindenaar
9 # 9 #
10 # This script is free software: you can redistribute and/or modify it under the 10 # This script is free software: you can redistribute and/or modify it under the
11 # terms of version 3 of the GNU General Public License as published by the Free 11 # terms of version 3 of the GNU General Public License as published by the Free
@@ -23,8 +23,8 @@ from time import time @@ -23,8 +23,8 @@ from time import time
23 from struct import pack 23 from struct import pack
24 from hashlib import sha1 24 from hashlib import sha1
25 from getpass import getpass 25 from getpass import getpass
26 -from urllib import urlencode  
27 -from urllib2 import Request, HTTPError, URLError, urlopen 26 +from urllib.parse import urlencode
  27 +from urllib.request import Request, HTTPError, URLError, urlopen
28 from ssl import CertificateError, \ 28 from ssl import CertificateError, \
29 create_default_context as create_default_SSL_context, \ 29 create_default_context as create_default_SSL_context, \
30 _create_unverified_context as create_unverified_SSL_context 30 _create_unverified_context as create_unverified_SSL_context
@@ -33,7 +33,7 @@ from argparse import ArgumentParser as StandardArgumentParser, FileType, \ @@ -33,7 +33,7 @@ from argparse import ArgumentParser as StandardArgumentParser, FileType, \
33 _StoreAction as StoreAction, _StoreConstAction as StoreConstAction 33 _StoreAction as StoreAction, _StoreConstAction as StoreConstAction
34 34
35 # Constants (no need to change but allows for easy customization) 35 # Constants (no need to change but allows for easy customization)
36 -VERSION="1.1" 36 +VERSION="1.2"
37 PROG_NAME=os.path.splitext(os.path.basename(__file__))[0] 37 PROG_NAME=os.path.splitext(os.path.basename(__file__))[0]
38 PROG_VERSION=PROG_NAME + ' ' + VERSION 38 PROG_VERSION=PROG_NAME + ' ' + VERSION
39 HTTP_AGENT=PROG_NAME + '/' + VERSION 39 HTTP_AGENT=PROG_NAME + '/' + VERSION
@@ -404,7 +404,7 @@ def nagios_exit(status, message, data=None): @@ -404,7 +404,7 @@ def nagios_exit(status, message, data=None):
404 if isinstance(v,list) else v) for k,v in data ]) 404 if isinstance(v,list) else v) for k,v in data ])
405 else: 405 else:
406 perfdata = '' 406 perfdata = ''
407 - print 'OTP %s: %s%s' % (status[0], message, perfdata) 407 + print('OTP %s: %s%s' % (status[0], message, perfdata))
408 sys.exit(status[1]) 408 sys.exit(status[1])
409 409
410 410
@@ -412,9 +412,9 @@ if __name__ == '__main__': @@ -412,9 +412,9 @@ if __name__ == '__main__':
412 try: 412 try:
413 args = parse_args() 413 args = parse_args()
414 except ArgumentParserError as e: 414 except ArgumentParserError as e:
415 - nagios_exit(NAGIOS_UNKNOWN,'error with setup: ' + e.message) 415 + nagios_exit(NAGIOS_UNKNOWN,'error with setup: ' + ','.join(e.args))
416 except (KeyboardInterrupt, EOFError) as e: 416 except (KeyboardInterrupt, EOFError) as e:
417 - print 417 + print()
418 nagios_exit(NAGIOS_UNKNOWN,'initialization aborted') 418 nagios_exit(NAGIOS_UNKNOWN,'initialization aborted')
419 419
420 message = args.func.__name__ + ' authentication' 420 message = args.func.__name__ + ' authentication'
plugins/check_temperature
1 -#! /usr/bin/env python 1 +#! /usr/bin/env python3
2 # 2 #
3 # check_temperature - Nagios temperature check for RaspberryPi-connected sensors 3 # check_temperature - Nagios temperature check for RaspberryPi-connected sensors
4 # 4 #
5 -# Version 1.2, latest version, documentation and bugtracker available at:  
6 -# https://gitlab.lindenaar.net/scripts/nagios-plugins 5 +# Version 1.3 latest version, documentation and bugtracker available at:
  6 +# https://gitlab.lindenaar.net/scripts/nagios-plugins
7 # 7 #
8 -# Copyright (c) 2017 - 2019 Frederik Lindenaar 8 +# Copyright (c) 2017 - 2024 Frederik Lindenaar
9 # 9 #
10 # This script is free software: you can redistribute and/or modify it under the 10 # This script is free software: you can redistribute and/or modify it under the
11 # terms of version 3 of the GNU General Public License as published by the Free 11 # terms of version 3 of the GNU General Public License as published by the Free
@@ -27,7 +27,7 @@ from argparse import ArgumentParser as StandardArgumentParser, FileType, \ @@ -27,7 +27,7 @@ from argparse import ArgumentParser as StandardArgumentParser, FileType, \
27 import logging 27 import logging
28 28
29 # Constants (no need to change but allows for easy customization) 29 # Constants (no need to change but allows for easy customization)
30 -VERSION="1.2" 30 +VERSION="1.3"
31 PROG_NAME=splitext(basename(__file__))[0] 31 PROG_NAME=splitext(basename(__file__))[0]
32 PROG_VERSION=PROG_NAME + ' ' + VERSION 32 PROG_VERSION=PROG_NAME + ' ' + VERSION
33 33
@@ -397,7 +397,7 @@ def parse_args(): @@ -397,7 +397,7 @@ def parse_args():
397 parser.add_argument('-l', '--logfile', action=SetLogFile, 397 parser.add_argument('-l', '--logfile', action=SetLogFile,
398 help='send logging output to logfile') 398 help='send logging output to logfile')
399 399
400 - subparser = parser.add_subparsers(title='Supported temperature sensors') 400 + subparser = parser.add_subparsers(title='Supported temperature sensors', required=True)
401 401
402 cpuparser = ArgumentParser(add_help=False) 402 cpuparser = ArgumentParser(add_help=False)
403 cpuparser.add_argument('-f', '--file', default=CPU_SENSOR_DEV, 403 cpuparser.add_argument('-f', '--file', default=CPU_SENSOR_DEV,
@@ -469,7 +469,7 @@ def nagios_exit(status, message, data=None): @@ -469,7 +469,7 @@ def nagios_exit(status, message, data=None):
469 if isinstance(v,list) else v) for k,v in data ]) 469 if isinstance(v,list) else v) for k,v in data ])
470 else: 470 else:
471 perfdata = '' 471 perfdata = ''
472 - print 'Temperature %s: %s%s' % (status[0], message, perfdata) 472 + print('Temperature %s: %s%s' % (status[0], message, perfdata))
473 exit(status[1]) 473 exit(status[1])
474 474
475 475
@@ -478,9 +478,9 @@ if __name__ == '__main__': @@ -478,9 +478,9 @@ if __name__ == '__main__':
478 try: 478 try:
479 args = parse_args() 479 args = parse_args()
480 except ArgumentParserError as e: 480 except ArgumentParserError as e:
481 - nagios_exit(NAGIOS_UNKNOWN,'error with setup: ' + e.message) 481 + nagios_exit(NAGIOS_UNKNOWN,'error with setup: ' + ','.join(e.args))
482 except (KeyboardInterrupt, EOFError) as e: 482 except (KeyboardInterrupt, EOFError) as e:
483 - print 483 + print()
484 nagios_exit(NAGIOS_UNKNOWN,'initialization aborted') 484 nagios_exit(NAGIOS_UNKNOWN,'initialization aborted')
485 485
486 try: 486 try: