Very simple, based on ChatGPT code script to display Health status of two Zammad instances.
Just put your heath url inside ZHealth_support.py and enjoy big green (or red) square with current error.
Save this as ZHealth_support.py
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Support module generated by PAGE version 8.0
# in conjunction with Tcl version 8.6
# Jan 29, 2024 11:11:36 AM EET platform: Windows NT
import sys
import tkinter as tk
import tkinter.ttk as ttk
from tkinter.constants import *
import requests
import json
import time
import ZHealth
_debug = True # False to eliminate debug printing from callback functions.
def poll_api():
# Replace the URLs below with the URLs of the REST APIs you want to poll
url1 = "https://XXXXXXXXXXXX/api/v1/monitoring/health_check?token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
url2 = "https://YYYYYYYYYYYY/api/v1/monitoring/health_check?token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
response1 = requests.get(url1)
response2 = requests.get(url2)
data1 = json.loads(response1.text)
data2 = json.loads(response2.text)
# Check if the 'healthy' key in the JSON string is True for both APIs
if data1["healthy"] and data2["healthy"]:
# If healthy is True for both APIs, fill Indicators with GREEN #00ff00 and set Messages clear.
_w1.Indicator1.configure(background="#00ff00")
_w1.Message1.configure(text='''NO ERROR right now''')
_w1.Indicator2.configure(background="#00ff00")
_w1.Message2.configure(text='''NO ERROR right now''')
else:
# If healthy is False for either API, print the 'issues' value for that API, set the color to Red #ff0000 and write Error message
if not data1["healthy"]:
# print("Helpdesk ERROR: {}".format(data1["issues"]))
_w1.Indicator1.configure(background="#ff0000")
_w1.Message1.configure(text=data1["issues"])
else:
_w1.Indicator1.configure(background="#00ff00")
if not data2["healthy"]:
# print("Support ERROR: {}".format(data2["issues"]))
_w1.Indicator2.configure(background="#ff0000")
_w1.Message2.configure(text=data2["issues"])
else:
_w1.Indicator2.configure(background="#00ff00")
# Wait for 15 seconds before polling again
root.after(15000, poll_api)
def main(*args):
'''Main entry point for the application.'''
global root
root = tk.Tk()
root.protocol( 'WM_DELETE_WINDOW' , root.destroy)
# Creates a toplevel widget.
global _top1, _w1
_top1 = root
_w1 = ZHealth.Toplevel1(_top1)
# Start polling the APIs
poll_api()
root.mainloop()
if __name__ == '__main__':
ZHealth.start_up()
And second script are GUI design, save it as ZHealth.py
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 8.0
# in conjunction with Tcl version 8.6
# Jan 29, 2024 11:27:10 AM EET platform: Windows NT
import sys
import tkinter as tk
import tkinter.ttk as ttk
from tkinter.constants import *
import os.path
_location = os.path.dirname(__file__)
import ZHealth_support
_bgcolor = '#d9d9d9'
_fgcolor = '#000000'
_tabfg1 = 'black'
_tabfg2 = 'white'
_bgmode = 'light'
_tabbg1 = '#d9d9d9'
_tabbg2 = 'gray40'
_style_code_ran = 0
def _style_code():
global _style_code_ran
if _style_code_ran: return
try: ZHealth_support.root.tk.call('source',
os.path.join(_location, 'themes', 'default.tcl'))
except: pass
style = ttk.Style()
style.theme_use('default')
style.configure('.', font = "TkDefaultFont")
if sys.platform == "win32":
style.theme_use('winnative')
_style_code_ran = 1
class Toplevel1:
def __init__(self, top=None):
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
top.geometry("600x450+390+190")
top.minsize(120, 1)
top.maxsize(1924, 1061)
top.resizable(1, 1)
top.title("Toplevel 0")
top.configure(background="#d9d9d9")
top.configure(highlightbackground="#d9d9d9")
top.configure(highlightcolor="#000000")
self.top = top
_style_code()
self.TSeparator1 = ttk.Separator(self.top)
self.TSeparator1.place(relx=0.483, rely=0.0, relheight=0.956)
self.TSeparator1.configure(orient="vertical")
self.Indicator2 = tk.Canvas(self.top)
self.Indicator2.place(relx=0.583, rely=0.2, relheight=0.318
, relwidth=0.288)
self.Indicator2.configure(background="#00ff00")
self.Indicator2.configure(borderwidth="4")
self.Indicator2.configure(highlightbackground="#d9d9d9")
self.Indicator2.configure(highlightcolor="#000000")
self.Indicator2.configure(insertbackground="#000000")
self.Indicator2.configure(relief="ridge")
self.Indicator2.configure(selectbackground="#d9d9d9")
self.Indicator2.configure(selectforeground="#000000")
self.TLabel1 = ttk.Label(self.top)
self.TLabel1.place(relx=0.033, rely=0.044, height=47, width=244)
self.TLabel1.configure(foreground="#0000ff")
self.TLabel1.configure(font="-family {Segoe UI} -size 12")
self.TLabel1.configure(relief="flat")
self.TLabel1.configure(anchor='center')
self.TLabel1.configure(justify='center')
self.TLabel1.configure(text='''Portal: ZAMMAD1 (internal)''')
self.TLabel1.configure(compound='center')
self.Indicator1 = tk.Canvas(self.top)
self.Indicator1.place(relx=0.1, rely=0.2, relheight=0.318
, relwidth=0.288)
self.Indicator1.configure(background="#00ff00")
self.Indicator1.configure(borderwidth="4")
self.Indicator1.configure(highlightbackground="#d9d9d9")
self.Indicator1.configure(highlightcolor="#000000")
self.Indicator1.configure(insertbackground="#000000")
self.Indicator1.configure(relief="ridge")
self.Indicator1.configure(selectbackground="#d9d9d9")
self.Indicator1.configure(selectforeground="black")
self.TLabel1_1 = ttk.Label(self.top)
self.TLabel1_1.place(relx=0.517, rely=0.044, height=47, width=244)
self.TLabel1_1.configure(foreground="#0000ff")
self.TLabel1_1.configure(font="-family {Segoe UI} -size 12")
self.TLabel1_1.configure(relief="flat")
self.TLabel1_1.configure(anchor='center')
self.TLabel1_1.configure(justify='center')
self.TLabel1_1.configure(text='''Portal: ZAMMAD2 (external)''')
self.TLabel1_1.configure(compound='center')
self.Message2 = tk.Label(self.top)
self.Message2.place(relx=0.55, rely=0.622, height=111, width=224)
self.Message2.configure(activebackground="#d9d9d9")
self.Message2.configure(activeforeground="black")
self.Message2.configure(anchor='nw')
self.Message2.configure(background="#d9d9d9")
self.Message2.configure(compound='left')
self.Message2.configure(disabledforeground="#a3a3a3")
self.Message2.configure(font="-family {Segoe UI} -size 9")
self.Message2.configure(foreground="#000000")
self.Message2.configure(highlightbackground="#d9d9d9")
self.Message2.configure(highlightcolor="#000000")
self.Message2.configure(justify='left')
self.Message2.configure(text='''No ERROR right now''')
self.Message2.configure(wraplength="224")
self.Message1 = tk.Label(self.top)
self.Message1.place(relx=0.067, rely=0.622, height=111, width=224)
self.Message1.configure(activebackground="#d9d9d9")
self.Message1.configure(activeforeground="black")
self.Message1.configure(anchor='nw')
self.Message1.configure(background="#d9d9d9")
self.Message1.configure(compound='left')
self.Message1.configure(disabledforeground="#a3a3a3")
self.Message1.configure(font="-family {Segoe UI} -size 9")
self.Message1.configure(foreground="#000000")
self.Message1.configure(highlightbackground="#d9d9d9")
self.Message1.configure(highlightcolor="#000000")
self.Message1.configure(text='''No ERROR right now''')
self.Message1.configure(wraplength="224")
def start_up():
ZHealth_support.main()
if __name__ == '__main__':
ZHealth_support.main()