diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..c305092 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,3 @@ +[MESSAGES CONTROL] +disable=consider-using-f-string, + invalid-name, diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..c2bd798 --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,12 @@ +pipeline: + test-pylint: + group: test + image: pipelinecomponents/pylint + commands: + - pylint check_livestatus + + test-flake8: + group: test + image: pipelinecomponents/flake8 + commands: + - flake8 check_livestatus diff --git a/check_livestatus b/check_livestatus index 1a3390e..4f523be 100755 --- a/check_livestatus +++ b/check_livestatus @@ -14,7 +14,7 @@ DEFAULT_HOST = '127.0.0.1' DEFAULT_PORT = 6557 DEFAULT_TIMEOUT = 2 -### MAIN #### +# MAIN parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( @@ -82,7 +82,9 @@ options = parser.parse_args() # Initialize log log = logging.getLogger() -logformat = logging.Formatter("%(asctime)s - " + os.path.basename(sys.argv[0]) + " - %(levelname)s - %(message)s") +logformat = logging.Formatter( + "%(asctime)s - " + os.path.basename(sys.argv[0]) + + " - %(levelname)s - %(message)s") if options.debug: log.setLevel(logging.DEBUG) @@ -111,7 +113,8 @@ try: livestatus = socket.socket(socket.AF_INET, socket.SOCK_STREAM) livestatus.connect((options.host, options.port)) else: - parser.error('You must provide Livestatus UNIX socket path or host & port') + parser.error( + 'You must provide Livestatus UNIX socket path or host & port') sys.exit(3) livestatus.settimeout(options.timeout) @@ -121,23 +124,25 @@ try: status = None if rawdata: data = json.loads(rawdata) - assert isinstance(data, list) and len(data) == 2, "Invalid Livestatus return:\n%s" % data + assert isinstance(data, list) and len(data) == 2, \ + "Invalid Livestatus return:\n%s" % data status = dict( (data[0][idx], value) for idx, value in enumerate(data[1]) ) -except Exception: +except Exception: # pylint: disable=broad-except print( - 'UNKNOWN - Fail to retreive status from Livestatus from %s\n\nException:\n%s' % + 'UNKNOWN - Fail to retreive status from Livestatus ' + 'from %s\n\nException:\n%s' % (peer, traceback.format_exc()) ) sys.exit(2) if isinstance(status, dict) and 'num_hosts' in status: - print('OK - %s host(s) found\n' % status['num_hosts']) - for key in sorted(status.keys()): - print('%s: %s' % (key, status[key])) - sys.exit(0) + print('OK - %s host(s) found\n' % status['num_hosts']) + for key in sorted(status.keys()): + print('%s: %s' % (key, status[key])) + sys.exit(0) print('UNKNOWN - Invalid Livestatus return\n\n%s' % data) sys.exit(3)