feat: add docker_container widget type
This commit is contained in:
@@ -285,6 +285,27 @@ def run_widget(w: dict) -> tuple:
|
||||
alive = process_alive(proc)
|
||||
return name, "system", "online" if alive else "offline", None, "", proc
|
||||
|
||||
if wtype == "docker_container":
|
||||
container = w.get("container", "")
|
||||
if not container:
|
||||
return name, "container", "unknown", None, "", "no container name"
|
||||
try:
|
||||
r = subprocess.run(
|
||||
["docker", "inspect", "--format", "{{.State.Status}}", container],
|
||||
capture_output=True, text=True, timeout=10)
|
||||
st = r.stdout.strip().lower()
|
||||
if st == "running":
|
||||
status = "online"
|
||||
elif st in ("restarting", "paused"):
|
||||
status = "degraded"
|
||||
else:
|
||||
status = "offline"
|
||||
except FileNotFoundError:
|
||||
st, status = "docker not found", "offline"
|
||||
except subprocess.TimeoutExpired:
|
||||
st, status = "timeout", "offline"
|
||||
return name, "container", status, None, "", st
|
||||
|
||||
if wtype == "custom_cmd":
|
||||
cmd = w["cmd"]
|
||||
timeout = w.get("timeout", 30)
|
||||
|
||||
Reference in New Issue
Block a user