Last active
February 7, 2021 21:42
-
-
Save tonvanbart/ffd57669bb3981613989b2b389966123 to your computer and use it in GitHub Desktop.
Python script to check the status of all Kafka connectors on a given host
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# check the status of Kafka connectors on a given host | |
import urllib2 | |
import json | |
import sys, getopt | |
def main(argv): | |
hostname = "" | |
try: | |
opts, args = getopt.getopt(argv, "h:") | |
except getopt.GetoptError: | |
explain() | |
sys.exit(2) | |
for opt, arg in opts: | |
if opt == '-h': | |
hostname = arg | |
if (hostname == ""): | |
print("Host name not specified\n") | |
explain() | |
sys.exit() | |
# base_url = "http://jarvis-dist-1:8083/connectors/" | |
url = "http://" + hostname + "/connectors?expand=status" | |
status_json = urllib2.urlopen(url).read() | |
status = json.loads(status_json) | |
print("\nChecking {} connectors on {}:\n".format(len(status), hostname)) | |
for stat in status: | |
print(stat + " : " + status[stat]["status"]["connector"]["state"]) | |
print("\nDone.") | |
def explain(): | |
print("Usage: kcst -h <host name>") | |
print("Checks the status of Kafka connectors on <host name>") | |
print("hostname is a host and optionally port") | |
print("Example: kcst.py -h jarvis-dist-1:8083") | |
if (__name__ == "__main__"): | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can also be done with
curl
andjq
: