Skip to content

Instantly share code, notes, and snippets.

@tonvanbart
Last active February 7, 2021 21:42
Show Gist options
  • Save tonvanbart/ffd57669bb3981613989b2b389966123 to your computer and use it in GitHub Desktop.
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
#!/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:])
@tonvanbart
Copy link
Author

get all statuses in a single REST call instead of looping.

@tonvanbart
Copy link
Author

Can also be done with curl and jq:

curl http://jarvis-dist-1:8083/connectors\?expand\=status | jq '.[] | "\(.status.name) \(.status.connector.state)"' 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment