diff --git a/tlumon/main.glade b/tlumon/main.glade new file mode 100644 index 0000000..9280038 --- /dev/null +++ b/tlumon/main.glade @@ -0,0 +1,588 @@ + + + + + + False + Demo Environment Status + 440 + 250 + network-workgroup + + + + + + True + False + vertical + 21 + + + True + False + vertical + + + True + False + 4 + 1 + + + True + False + gtk-no + + + 0 + 0 + + + + + True + False + gtk-no + + + 0 + 1 + + + + + True + False + wan + 10 + + + 1 + 0 + + + + + True + False + lan + + + 1 + 1 + + + + + True + False + N/A + + + 3 + 0 + + + + + True + False + N/A + + + 3 + 1 + + + + + True + True + True + + + + True + False + network-wired + + + + + 2 + 0 + + + + + True + True + True + + + + True + False + network-wired + + + + + 2 + 1 + + + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + + + True + False + 7 + + + True + False + gtk-no + + + 0 + 0 + + + + + True + False + gtk-no + + + 0 + 1 + + + + + True + False + gtk-no + + + 0 + 2 + + + + + True + False + nginx + 10 + 0 + + + 1 + 0 + + + + + True + False + chronyd + 10 + 0 + + + 1 + 1 + + + + + True + False + atftp + 10 + 0 + + + 1 + 2 + + + + + True + False + gtk-no + 6 + + + 0 + 3 + + + + + True + False + mariadb + 10 + 0 + + + 1 + 3 + + + + + False + True + 0 + + + + + True + False + 7 + + + True + False + gtk-no + + + 0 + 0 + + + + + True + False + gtk-no + + + 0 + 1 + + + + + True + False + gtk-no + + + 0 + 2 + + + + + True + False + gtk-no + + + 0 + 3 + + + + + True + False + rmt-server + 10 + 0 + + + 1 + 0 + + + + + True + False + rmt sync timer + 10 + 0 + + + 1 + 1 + + + + + True + False + rmt mirror timer + 10 + 0 + + + 1 + 2 + + + + + True + False + rmt scc sync timer + 10 + 0 + + + 1 + 3 + + + + + False + True + 1 + + + + + True + False + 7 + + + True + False + gtk-no + + + 0 + 0 + + + + + True + False + gtk-no + + + 0 + 1 + + + + + True + False + gtk-no + + + 0 + 2 + + + + + True + False + dnsmasq + 10 + 0 + + + 1 + 0 + + + + + True + False + ??? + 10 + 0 + + + 1 + 1 + + + + + True + False + ??? + 10 + 0 + + + 1 + 2 + + + + + True + False + gtk-no + 6 + + + 0 + 3 + + + + + True + False + ??? + 10 + 0 + + + 1 + 3 + + + + + False + True + 2 + + + + + False + True + 1 + + + + + + + + + + False + Enter NIC Name + dialog + MainWindow + + + + + + False + vertical + 2 + + + False + end + + + gtk-cancel + True + True + True + True + True + + + True + True + 0 + + + + + gtk-ok + True + True + True + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + True + False + + + True + False + NIC Name + + + False + True + 0 + + + + + True + False + + + False + True + 1 + + + + + False + True + 1 + + + + + + cancel + ok + + + diff --git a/tlumon/tlumon b/tlumon/tlumon new file mode 100755 index 0000000..1f64e84 --- /dev/null +++ b/tlumon/tlumon @@ -0,0 +1,144 @@ +#!/usr/bin/env python3 +import gi + +gi.require_version("Gtk", "3.0") + +from gi.repository import Gtk +from gi.repository import Gio +import time +import threading +import logging +import subprocess +import psutil +import socket + +LOGLEVEL=logging.DEBUG +#LOGLEVEL=logging.WARNING + +SLEEPTIMER=2 + +class Main: + def __init__(self): + self.builder = Gtk.Builder() + self.builder.add_from_file("main.glade") + self.builder.connect_signals(self) + + self.windowMain = self.builder.get_object("MainWindow") + self.DialogChangeNIC = self.builder.get_object("dlg_nic_name") + #load nics to combobox + nics = Gtk.ListStore(str) + for interface in psutil.net_if_addrs().keys(): + if interface != "lo": + nics.append([interface]) + self.combobox = self.builder.get_object("cbox_nics") + self.combobox.set_model(nics) + renderer_text = Gtk.CellRendererText() + self.combobox.pack_start(renderer_text, True) + self.combobox.add_attribute(renderer_text, "text", 0) + + self.windowMain.connect("delete-event", Gtk.main_quit) + self.windowMain.show() + + self.icon_ok = Gio.ThemedIcon(name="gtk-yes") + self.icon_not_ok = Gio.ThemedIcon(name="gtk-no") + + self.lan_nic = "eth0" + self.wan_nic = "wlan0" + self.builder.get_object("lbl_wan").set_text(f"wan ({self.wan_nic})") + self.builder.get_object("lbl_lan").set_text(f"lan ({self.lan_nic})") + + self.service_checks = [ + "nginx", + "rmt-server", + "chronyd", + "rmt-server-sync.timer", + "rmt-server-mirror.timer", + "rmt-server-systems-scc-sync.timer", + "atftp", + "mariadb" + ] + + self.update() + + + def update(self): + logging.debug("Update triggered") + self.check_service() + self.check_ip() + timer_thread = threading.Thread(target=self.sleep) + timer_thread.daemon = True + timer_thread.start() + + def sleep(self): + time.sleep(SLEEPTIMER) + self.update() + + def check_service(self): + for service in self.service_checks: + logging.debug("Checking status of service %s", service) + image = self.builder.get_object("img_service_"+service) + result = subprocess.run(["systemctl", "is-active", service, "--quiet"]) + if result.returncode == 0: + logging.debug("%s is running", service) + image.set_from_gicon(self.icon_ok, Gtk.IconSize.DIALOG) + else: + logging.debug("%s is not running, exit code %i",service, result.returncode) + image.set_from_gicon(self.icon_not_ok, Gtk.IconSize.DIALOG) + + def check_ip(self): + #checking LAN network + logging.debug("Checking IP for LAN") + image = self.builder.get_object("img_ip_lan") + text = self.builder.get_object("lbl_lan_status") + ip = list(self.get_ip_address(self.lan_nic)) + if ip: + logging.debug("found : %s", " ".join(ip)) + image.set_from_gicon(self.icon_ok, Gtk.IconSize.DIALOG) + text.set_text(" ".join(ip)) + else: + logging.debug("no IP found") + image.set_from_gicon(self.icon_not_ok, Gtk.IconSize.DIALOG) + text.set_text("N/A") + + logging.debug("Checking IP for WAN") + ip = list(self.get_ip_address(self.wan_nic)) + image = self.builder.get_object("img_ip_wan") + text = self.builder.get_object("lbl_wan_status") + ip = list(self.get_ip_address("wlan0")) + if ip: + logging.debug("found : %s", " ".join(ip)) + image.set_from_gicon(self.icon_ok, Gtk.IconSize.DIALOG) + text.set_text(" ".join(ip)) + else: + logging.debug("no IP found") + image.set_from_gicon(self.icon_not_ok, Gtk.IconSize.DIALOG) + text.set_text("N/A") + + def get_ip_address(self, interface): + for snic in psutil.net_if_addrs()[interface]: + if snic.family == socket.AF_INET: + yield (snic.address) + + def change_nic(self, widget): + button = Gtk.Buildable.get_name(widget) + logging.debug("pressed %s", button) + response = self.DialogChangeNIC.run() + self.DialogChangeNIC.hide() + if response == Gtk.ResponseType.OK: + logging.debug("Ok was pressed") + tree_iter = self.combobox.get_active_iter() + if tree_iter is not None: + model = self.combobox.get_model() + name = model[tree_iter][:2][0] + if button == "btn_change_wan_nic": + self.wan_nic = namn + self.builder.get_object("lbl_wan").set_text(f"wan ({self.wan_nic})") + if button == "btn_change_lan_nic": + self.lan_nic = name + self.builder.get_object("lbl_lan").set_text(f"lan ({self.lan_nic})") + self.check_ip() + +if __name__ == '__main__': + logging.basicConfig(format='%(levelname)s:\t%(message)s', level=LOGLEVEL) + main = Main() + Gtk.main()