Propagate controller errors as alerts
[khatus.git] / bin / khatus_actuator
1 #! /usr/bin/awk -f
2
3 BEGIN {
4 n_ignored = split(opt_ignore_alerts_from, ignored, "[ \t\n]+")
5 for (i = 1; i <= n_ignored; i++) {
6 ignored_alert_sources[ignored[i]] = 1
7 }
8 }
9
10 /^STATUS_BAR / { shift(); handle_status_bar(); next }
11 /^ALERT / { shift(); handle_alert() ; next }
12 /^ERROR / { shift(); handle_error() ; next }
13
14 function handle_status_bar() {
15 system("xsetroot -name \" " $0 "\" ")
16 }
17
18 function handle_alert( src, priority, subject, sep, body, urgency, dbg) {
19 src = $1
20 priority = $2
21 subject = $3
22 shift()
23 shift()
24 shift()
25 body = $0
26 sep = body ? "\n" : ""
27 body = body sep "--" src
28
29 urgency = priority
30 sub("hi" , "critical", urgency)
31 sub("med", "normal" , urgency)
32
33 dbg["priority"] = priority
34 dbg["urgency"] = urgency
35 dbg["subject"] = subject
36 dbg["body"] = body
37 debug("ALERT properties", dbg)
38
39 if (src in ignored_alert_sources) {
40 debug("ALERT ignoring from " src, ignored_alert_sources)
41 } else {
42 debug("ALERT sending from " src, ignored_alert_sources)
43 notify_send(urgency, subject, body)
44 }
45 }
46
47 function handle_error() {
48 notify_send("normal", "Khatus_Error", $0)
49 }
50
51 function notify_send(urgency, subject, body, cmd) {
52 cmd = \
53 sprintf(\
54 "DISPLAY=%s notify-send -u %s %s \" %s\"",
55 display, urgency, subject, body \
56 )
57 system(cmd)
58 }
59
60 function shift() {
61 sub("^" $1 " +", "")
62 }
63
64 function debug(msg, data, sep, vals, key, payload) {
65 sep = ""
66 vals = ""
67 for (key in data) {
68 vals = sprintf("%s%s%s: \"%s\"", vals, sep, key, data[key])
69 sep = ", "
70 }
71 payload = sprintf("[%s] [%s] [%s]", pid, msg, vals)
72 print payload > "/dev/stderr"
73 }
This page took 0.069201 seconds and 4 git commands to generate.