From: Siraaj Khandkar Date: Mon, 3 Sep 2018 19:33:38 +0000 (-0400) Subject: Normalize alert msg X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=e103315c72597a9cc9fffaaff11e04b30d1c6416;p=khatus.git Normalize alert msg --- diff --git a/Makefile b/Makefile index c63c61e..5dbefc2 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,6 @@ install: clean: rm -f $(AWK_EXECUTABLES) - bin/khatus_bar: \ src/awk/exe/bar.awk \ src/awk/lib/cache.awk \ @@ -60,8 +59,7 @@ bin/khatus_actuate_alert_to_notify_send: \ bin/khatus_actuate_device_add_to_automount: \ src/awk/exe/actuate_device_add_to_automount.awk \ src/awk/lib/msg_in.awk \ - src/awk/lib/msg_out.awk \ - src/awk/lib/alert.awk + src/awk/lib/msg_out.awk $(BUILD_AWK_EXE) bin/khatus_actuate_status_bar_to_xsetroot_name: \ @@ -72,23 +70,20 @@ bin/khatus_actuate_status_bar_to_xsetroot_name: \ bin/khatus_monitor_devices: \ src/awk/exe/monitor_devices.awk \ src/awk/lib/msg_in.awk \ - src/awk/lib/msg_out.awk \ - src/awk/lib/alert.awk + src/awk/lib/msg_out.awk $(BUILD_AWK_EXE) bin/khatus_monitor_energy: \ src/awk/exe/monitor_energy.awk \ src/awk/lib/msg_in.awk \ src/awk/lib/msg_out.awk \ - src/awk/lib/alert.awk \ src/awk/lib/util.awk $(BUILD_AWK_EXE) bin/khatus_monitor_errors: \ src/awk/exe/monitor_errors.awk \ src/awk/lib/msg_in.awk \ - src/awk/lib/msg_out.awk \ - src/awk/lib/alert.awk + src/awk/lib/msg_out.awk $(BUILD_AWK_EXE) bin/khatus_parse_bluetoothctl_show: \ diff --git a/src/awk/exe/actuate_alert_to_notify_send.awk b/src/awk/exe/actuate_alert_to_notify_send.awk index f11b2f4..2cebbff 100755 --- a/src/awk/exe/actuate_alert_to_notify_send.awk +++ b/src/awk/exe/actuate_alert_to_notify_send.awk @@ -7,10 +7,12 @@ BEGIN { } $1 == "OK" && \ -$3 == "alert" { +$3 ~ /^alert/ { src = $2 - priority = $4 - subject = $5 + key = $3 + split(key, key_parts, Kfs) + priority = key_parts[2] + subject = key_parts[3] # Not just using $6 for body - because body might contain a character # identical to FS diff --git a/src/awk/exe/actuate_device_add_to_automount.awk b/src/awk/exe/actuate_device_add_to_automount.awk index 9db7e9e..d1a56aa 100755 --- a/src/awk/exe/actuate_device_add_to_automount.awk +++ b/src/awk/exe/actuate_device_add_to_automount.awk @@ -28,15 +28,15 @@ function mount_device(path, cmd, line, lines, line_count, status, i, path_mnt=line sub("^Mounted " path_dev " at ", "", path_mnt) sub("\.$", "", path_mnt) - alert("low", "successfully-mounted", path_dev " to " path_mnt) + msg_out_ok_alert("low", "successfully-mounted", path_dev " to " path_mnt) if (Execute_On_Mount) { system(Execute_On_Mount " '" path_mnt "'") } } else { - alert("hi", "unexpected-success-line", line) + msg_out_ok_alert("hi", "unexpected-success-line", line) } } } else { - alert("hi", "failed-to-mount-device", path) + msg_out_ok_alert("hi", "failed-to-mount-device", path) } } diff --git a/src/awk/exe/monitor_devices.awk b/src/awk/exe/monitor_devices.awk index a37a30c..d43f67c 100755 --- a/src/awk/exe/monitor_devices.awk +++ b/src/awk/exe/monitor_devices.awk @@ -1,5 +1,5 @@ $1 == "OK" && \ $2 == "khatus_sensor_devices" \ { - alert("low", "BlockDeviceEvent", $3 " " $4) + msg_out_ok_alert("low", "BlockDeviceEvent", $3 " " $4) } diff --git a/src/awk/exe/monitor_energy.awk b/src/awk/exe/monitor_energy.awk index 0730ec7..0d3f339 100755 --- a/src/awk/exe/monitor_energy.awk +++ b/src/awk/exe/monitor_energy.awk @@ -14,7 +14,7 @@ $3 == "line_power" { line_power_prev = line_power_curr line_power_curr = $4 if (line_power_curr == "no" && line_power_prev != "no") { - alert("low", "PowerUnplugged", "") + msg_out_ok_alert("low", "PowerUnplugged", "") } } @@ -38,7 +38,7 @@ $3 == "battery_percentage" { priority = msg[1] subject = msg[2] body = sprintf("%d%% %s", battery_percentage, msg[3]) - alert(priority, subject, body) + msg_out_ok_alert(priority, subject, body) _alerted[threshold]++ } } diff --git a/src/awk/exe/monitor_errors.awk b/src/awk/exe/monitor_errors.awk index a096db7..13130cc 100755 --- a/src/awk/exe/monitor_errors.awk +++ b/src/awk/exe/monitor_errors.awk @@ -6,5 +6,5 @@ len_head = length($1 FS $2 FS) len_body = len_line - len_head body = substr($0, len_head + 1, len_body) - alert("hi", "ERROR_IN_" src, body) + msg_out_ok_alert("hi", "ERROR_IN_" src, body) } diff --git a/src/awk/lib/alert.awk b/src/awk/lib/alert.awk deleted file mode 100755 index 5e14146..0000000 --- a/src/awk/lib/alert.awk +++ /dev/null @@ -1,6 +0,0 @@ -function alert(priority, subject, body) { - # priority : "low" | "med" | "hi" - # subject : string without spaces - # body : anything - print("OK", Module, "alert", priority, subject, body) -} diff --git a/src/awk/lib/msg_out.awk b/src/awk/lib/msg_out.awk index 1a0f813..6f5f945 100755 --- a/src/awk/lib/msg_out.awk +++ b/src/awk/lib/msg_out.awk @@ -3,6 +3,15 @@ BEGIN { Kfs = Key_fs ? Key_fs : ":" } +function msg_out_ok_alert(priority, subject, body, key, val) { + # priority : "low" | "med" | "hi" + # subject : string without spaces + # body : anything + key = "alert" Kfs priority Kfs subject + val = body + msg_out_ok(key, val) +} + function msg_out_ok(key, val) { msg_out("OK", key, val, "/dev/stdout") }