Re-use AWK components
[khatus.git] / src / awk / exe / actuate_alert_to_notify_send.awk
diff --git a/src/awk/exe/actuate_alert_to_notify_send.awk b/src/awk/exe/actuate_alert_to_notify_send.awk
new file mode 100755 (executable)
index 0000000..eae5cb5
--- /dev/null
@@ -0,0 +1,32 @@
+BEGIN {
+    # Set the correct value as any other AWK variable:
+    #
+    #   khatus_actuate_alert_to_notify_send -v Display="$CORRECT_DISPLAY"
+    #
+    Display = Display ? Display : ":0"
+}
+
+$1 == "OK" && \
+$2 == "alert" {
+    priority = $3
+    subject  = $4
+
+    # Not just using $5 for body - because body might contain a character
+    # identical to FS
+    len_line = length($0)
+    len_head = length($1 FS $2 FS $3 FS $4 FS $5 FS)
+    len_body = len_line - len_head
+    body = substr($0, len_head + 1, len_body)
+
+    urgency = priority
+    sub("hi" , "critical", urgency)
+    sub("med", "normal"  , urgency)
+
+    cmd = \
+        sprintf(\
+            "DISPLAY=%s notify-send -u %s %s \" %s\"",
+            Display, urgency, subject, body \
+        )
+    system(cmd)
+    next
+}
This page took 0.024737 seconds and 4 git commands to generate.