Add actuator prototype
authorSiraaj Khandkar <siraaj@khandkar.net>
Fri, 3 Aug 2018 19:46:22 +0000 (15:46 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Fri, 3 Aug 2018 19:46:22 +0000 (15:46 -0400)
bin/khatus_actuator [new file with mode: 0755]

diff --git a/bin/khatus_actuator b/bin/khatus_actuator
new file mode 100755 (executable)
index 0000000..2e5d003
--- /dev/null
@@ -0,0 +1,73 @@
+#! /usr/bin/awk -f
+
+BEGIN {
+    n_ignored = split(opt_ignore_alerts_from, ignored, "[ \t\n]+")
+    for (i = 1; i <= n_ignored; i++) {
+        ignored_alert_sources[ignored[i]] = 1
+    }
+}
+
+/^STATUS_BAR / { shift(); handle_status_bar(); next }
+/^ALERT /      { shift(); handle_alert()     ; next }
+/^ERROR /      { shift(); handle_error()     ; next }
+
+function handle_status_bar() {
+    system("xsetroot -name \" " $0 "\" ")
+}
+
+function handle_alert(    src, priority, subject, sep, body, urgency, dbg) {
+    src = $1
+    priority = $2
+    subject  = $3
+    shift()
+    shift()
+    shift()
+    body = $0
+    sep = body ? "\n" : ""
+    body = body sep "--" src
+
+    urgency = priority
+    sub("hi" , "critical", urgency)
+    sub("med", "normal"  , urgency)
+
+    dbg["priority"]   = priority
+    dbg["urgency"]    = urgency
+    dbg["subject"]    = subject
+    dbg["body"]       = body
+    debug("ALERT properties", dbg)
+
+    if (src in ignored_alert_sources) {
+        debug("ALERT ignoring from " src, ignored_alert_sources)
+    } else {
+        debug("ALERT sending from " src, ignored_alert_sources)
+        notify_send(urgency, subject, body)
+    }
+}
+
+function handle_error() {
+    notify_send("normal", "Khatus_Error", $0)
+}
+
+function notify_send(urgency, subject, body,   cmd) {
+    cmd = \
+        sprintf(\
+            "DISPLAY=%s notify-send -u %s %s \" %s\"",
+            display, urgency, subject, body \
+        )
+    system(cmd)
+}
+
+function shift() {
+    sub("^" $1 " +", "")
+}
+
+function debug(msg, data,    sep, vals, key, payload) {
+    sep = ""
+    vals = ""
+    for (key in data) {
+        vals = sprintf("%s%s%s: \"%s\"", vals, sep, key, data[key])
+        sep = ", "
+    }
+    payload = sprintf("[%s] [%s] [%s]", pid, msg, vals)
+    print payload > "/dev/stderr"
+}
This page took 0.028631 seconds and 4 git commands to generate.