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 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 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 10 # This script is free software: you can redistribute and/or modify it under the
11 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 23 from struct import pack
24 24 from hashlib import sha1
25 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 28 from ssl import CertificateError, \
29 29 create_default_context as create_default_SSL_context, \
30 30 _create_unverified_context as create_unverified_SSL_context
... ... @@ -33,7 +33,7 @@ from argparse import ArgumentParser as StandardArgumentParser, FileType, \
33 33 _StoreAction as StoreAction, _StoreConstAction as StoreConstAction
34 34  
35 35 # Constants (no need to change but allows for easy customization)
36   -VERSION="1.1"
  36 +VERSION="1.2"
37 37 PROG_NAME=os.path.splitext(os.path.basename(__file__))[0]
38 38 PROG_VERSION=PROG_NAME + ' ' + VERSION
39 39 HTTP_AGENT=PROG_NAME + '/' + VERSION
... ... @@ -404,7 +404,7 @@ def nagios_exit(status, message, data=None):
404 404 if isinstance(v,list) else v) for k,v in data ])
405 405 else:
406 406 perfdata = ''
407   - print 'OTP %s: %s%s' % (status[0], message, perfdata)
  407 + print('OTP %s: %s%s' % (status[0], message, perfdata))
408 408 sys.exit(status[1])
409 409  
410 410  
... ... @@ -412,9 +412,9 @@ if __name__ == '__main__':
412 412 try:
413 413 args = parse_args()
414 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 416 except (KeyboardInterrupt, EOFError) as e:
417   - print
  417 + print()
418 418 nagios_exit(NAGIOS_UNKNOWN,'initialization aborted')
419 419  
420 420 message = args.func.__name__ + ' authentication'
... ...
plugins/check_temperature
1   -#! /usr/bin/env python
  1 +#! /usr/bin/env python3
2 2 #
3 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 10 # This script is free software: you can redistribute and/or modify it under the
11 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 27 import logging
28 28  
29 29 # Constants (no need to change but allows for easy customization)
30   -VERSION="1.2"
  30 +VERSION="1.3"
31 31 PROG_NAME=splitext(basename(__file__))[0]
32 32 PROG_VERSION=PROG_NAME + ' ' + VERSION
33 33  
... ... @@ -397,7 +397,7 @@ def parse_args():
397 397 parser.add_argument('-l', '--logfile', action=SetLogFile,
398 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 402 cpuparser = ArgumentParser(add_help=False)
403 403 cpuparser.add_argument('-f', '--file', default=CPU_SENSOR_DEV,
... ... @@ -469,7 +469,7 @@ def nagios_exit(status, message, data=None):
469 469 if isinstance(v,list) else v) for k,v in data ])
470 470 else:
471 471 perfdata = ''
472   - print 'Temperature %s: %s%s' % (status[0], message, perfdata)
  472 + print('Temperature %s: %s%s' % (status[0], message, perfdata))
473 473 exit(status[1])
474 474  
475 475  
... ... @@ -478,9 +478,9 @@ if __name__ == '__main__':
478 478 try:
479 479 args = parse_args()
480 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 482 except (KeyboardInterrupt, EOFError) as e:
483   - print
  483 + print()
484 484 nagios_exit(NAGIOS_UNKNOWN,'initialization aborted')
485 485  
486 486 try:
... ...