src/awk/exe/bar.awk \
src/awk/lib/cache.awk \
src/awk/lib/str.awk \
- src/awk/lib/msg_in.awk \
- src/awk/lib/msg_out.awk \
+ src/awk/lib/msg.awk \
src/awk/lib/num.awk
$(BUILD_AWK_EXE)
bin/khatus_actuate_alert_to_notify_send: \
src/awk/exe/actuate_alert_to_notify_send.awk \
src/awk/lib/str.awk \
- src/awk/lib/msg_in.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
bin/khatus_actuate_device_add_to_automount: \
src/awk/exe/actuate_device_add_to_automount.awk \
src/awk/lib/str.awk \
- src/awk/lib/msg_in.awk \
- src/awk/lib/msg_out.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
bin/khatus_actuate_status_bar_to_xsetroot_name: \
src/awk/exe/actuate_status_bar_to_xsetroot_name.awk \
src/awk/lib/str.awk \
- src/awk/lib/msg_in.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
bin/khatus_monitor_devices: \
src/awk/exe/monitor_devices.awk \
src/awk/lib/str.awk \
- src/awk/lib/msg_in.awk \
- src/awk/lib/msg_out.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
bin/khatus_monitor_energy: \
src/awk/exe/monitor_energy.awk \
src/awk/lib/str.awk \
- src/awk/lib/msg_in.awk \
- src/awk/lib/msg_out.awk \
+ src/awk/lib/msg.awk \
src/awk/lib/num.awk
$(BUILD_AWK_EXE)
bin/khatus_monitor_errors: \
src/awk/exe/monitor_errors.awk \
src/awk/lib/str.awk \
- src/awk/lib/msg_in.awk \
- src/awk/lib/msg_out.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
bin/khatus_parse_bluetoothctl_show: \
src/awk/exe/parse_bluetoothctl_show.awk \
- src/awk/lib/msg_out.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
bin/khatus_parse_df_pcent: \
src/awk/exe/parse_df_pcent.awk \
- src/awk/lib/msg_out.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
bin/khatus_parse_fan_file: \
src/awk/exe/parse_fan_file.awk \
- src/awk/lib/msg_out.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
bin/khatus_parse_free: \
src/awk/exe/parse_free.awk \
- src/awk/lib/msg_out.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
bin/khatus_parse_ip_addr: \
src/awk/exe/parse_ip_addr.awk \
- src/awk/lib/msg_out.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
bin/khatus_parse_iwconfig: \
src/awk/exe/parse_iwconfig.awk \
- src/awk/lib/msg_out.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
bin/khatus_parse_loadavg_file: \
src/awk/exe/parse_loadavg_file.awk \
- src/awk/lib/msg_out.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
bin/khatus_parse_metar_d_output: \
src/awk/exe/parse_metar_d_output.awk \
- src/awk/lib/msg_out.awk \
+ src/awk/lib/msg.awk \
src/awk/lib/str.awk
$(BUILD_AWK_EXE)
bin/khatus_parse_mpd_status_currentsong: \
src/awk/exe/parse_mpd_status_currentsong.awk \
- src/awk/lib/msg_out.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
bin/khatus_parse_pactl_list_sinks: \
src/awk/exe/parse_pactl_list_sinks.awk \
- src/awk/lib/msg_out.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
bin/khatus_parse_ps: \
src/awk/exe/parse_ps.awk \
- src/awk/lib/msg_out.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
bin/khatus_parse_sys_block_stat: \
src/awk/exe/parse_sys_block_stat.awk \
- src/awk/lib/msg_out.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
bin/khatus_parse_udevadm_monitor_block: \
src/awk/exe/parse_udevadm_monitor_block.awk \
- src/awk/lib/msg_out.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
bin/khatus_parse_upower: \
src/awk/exe/parse_upower.awk \
- src/awk/lib/msg_out.awk
+ src/awk/lib/msg.awk
$(BUILD_AWK_EXE)
#-----------------------------------------------------------------------------
Display = Display ? Display : ":0"
}
+{
+ delete msg
+ msg_parse(msg, $0)
+}
-
-$3 == "alert" {
- delete msg
- msg_in_parse(msg, $0)
+msg["type"] == "alert" {
body = msg["body"]
sep = body ? "\n" : ""
body = body sep "--" msg["node"] ":" msg["module"]
Execute_On_Mount = Execute_On_Mount ? Execute_On_Mount : ""
}
-$1 == Node && \
-$2 == "khatus_sensor_devices" && \
-$3 == "data" && \
-$4 == "add" && \
-$5 ~ /[0-9]$/ {
- mount_device($5)
+{
+ delete msg
+ msg_parse(msg, $0)
+}
+
+msg["node"] == Node && \
+msg["module"] == "khatus_sensor_devices" && \
+msg["type"] == "data" && \
+msg["key"] == "add" && \
+msg["val"] ~ /[0-9]$/ {
+ mount_device(msg["val"])
}
function mount_device(path, cmd, line, lines, line_count, status, i,
-$1 == Node && \
-$2 == "khatus_bar" && \
-$3 == "status_bar" {
- delete msg
- msg_in_parse(msg, $0)
+{
+ delete msg
+ msg_parse(msg, $0)
+}
+
+msg["node"] == Node && \
+msg["module"] == "khatus_bar" && \
+msg["type"] == "status_bar" {
system("xsetroot -name \"" msg["status_bar"] "\"")
next
}
# -----------------------------------------------------------------------------
# Input
# -----------------------------------------------------------------------------
-$3 == "data" {
- delete msg
- msg_in_parse(msg, $0)
+{
+ delete msg
+ msg_parse(msg, $0)
+}
+
+msg["type"] == "data" {
cache_update(msg["node"], msg["module"], msg["key"], msg["val"])
}
-$1 == Node && \
-$2 == "khatus_sensor_datetime" && \
-$3 == "data" {
+msg["node"] == Node && \
+msg["module"] == "khatus_sensor_datetime" && \
+msg["type"] == "data" {
# Code for bar_make_status is expected to be passed as an
# additional source file, using -f flag.
msg_out_status_bar(bar_make_status())
-$2 == "khatus_sensor_devices" && \
-$3 == "data" \
{
- delete msg
- msg_in_parse(msg, $0)
+ delete msg
+ msg_parse(msg, $0)
+}
+
+msg["module"] == "khatus_sensor_devices" && \
+msg["type"] == "data" \
+{
msg_out_alert_low( \
"BlockDeviceEvent",
msg["key"] " " msg["val"] " on " msg["node"]\
bat_alert_spec[5] = "hi|Energy_CRITICALLY_Low|CHARGE NOW!!! GO GO GO!!!"
}
-$1 == Node && \
-$2 == "khatus_sensor_energy" && \
-$3 == "data" && \
-$4 == "line_power" {
+{
+ delete msg
+ msg_parse(msg, $0)
+}
+
+msg["node"] == Node && \
+msg["module"] == "khatus_sensor_energy" && \
+msg["type"] == "data" && \
+msg["key"] == "line_power" {
line_power_prev = line_power_curr
- line_power_curr = $5
+ line_power_curr = msg["val"]
if (line_power_curr == "no" && line_power_prev != "no") {
msg_out_alert_low("PowerUnplugged", "")
}
}
-$1 == Node && \
-$2 == "khatus_sensor_energy" && \
-$3 == "data" && \
-$4 == "battery_state" {
+msg["node"] == Node && \
+msg["module"] == "khatus_sensor_energy" && \
+msg["type"] == "data" && \
+msg["key"] == "battery_state" {
battery_state_prev = battery_state_curr
- battery_state_curr = $5
+ battery_state_curr = msg["val"]
}
-$1 == Node && \
-$2 == "khatus_sensor_energy" && \
-$3 == "data" && \
-$4 == "battery_percentage" {
+msg["node"] == Node && \
+msg["module"] == "khatus_sensor_energy" && \
+msg["type"] == "data" && \
+msg["key"] == "battery_percentage" {
# TODO: Re-think the spec - can't rely on order of keys
- battery_percentage = num_ensure_numeric($5)
+ battery_percentage = num_ensure_numeric(msg["val"])
if (battery_state_curr == "discharging") {
for (threshold in bat_alert_spec) {
threshold = num_ensure_numeric(threshold)
-$3 == "error" {
- delete msg
- msg_in_parse(msg, $0)
+{
+ delete msg
+ msg_parse(msg, $0)
+}
+
+msg["type"] == "error" {
subject = "ERROR_IN_" msg["node"] ":" msg["module"]
msg_out_alert_hi(subject, msg["line"])
}
Kfs = FS2
}
+function msg_parse(msg, line, status, fields, type) {
+ split(line, fields, FS1)
+ msg["node"] = fields[1]
+ msg["module"] = fields[2]
+ type = fields[3]
+ msg["type"] = type
+
+ status = 1
+ if (type == "data") {
+ msg["key"] = fields[4]
+ msg["val"] = str_tail(str_join(fields, 1, 4, FS1) FS1, line)
+ } else if (type == "error") {
+ msg["line"] = str_tail(str_join(fields, 1, 3, FS1) FS1, line)
+ } else if (type == "alert") {
+ msg["priority"] = fields[4]
+ msg["subject"] = fields[5]
+ msg["body"] = str_tail(str_join(fields, 1, 5, FS1) FS1, line)
+ } else if (type == "log") {
+ msg["location"] = fields[4]
+ msg["level"] = fields[5]
+ msg["msg"] = str_tail(str_join(fields, 1, 5, FS1) FS1, line)
+ } else if (type == "status_bar") {
+ msg["status_bar"] = str_tail(str_join(fields, 1, 3, FS1) FS1, line)
+ } else {
+ msg_out_log_error(\
+ "msg_parse",
+ "Unexpected msg type: " type " in given input line: " line \
+ )
+ status = 0
+ }
+ return status
+}
+
# -----------------------------------------------------------------------------
# alert
# -----------------------------------------------------------------------------
+++ /dev/null
-BEGIN {
- FS1 = "|" # Fiels separator, level 1 (record to fields)
- FS2 = ":" # Fiels separator, level 2 (field to subfields)
-
- FS = FS1
- Kfs = FS2
-}
-
-function msg_in_parse(msg, line, fields, type) {
- split(line, fields, FS1)
- msg["node"] = fields[1]
- msg["module"] = fields[2]
- type = fields[3]
- msg["type"] = type
-
- if (type == "data") {
- msg["key"] = fields[4]
- msg["val"] = str_tail(str_join(fields, 1, 4, FS1) FS1, line)
- } else if (type == "error") {
- msg["line"] = str_tail(str_join(fields, 1, 3, FS1) FS1, line)
- } else if (type == "alert") {
- msg["priority"] = fields[4]
- msg["subject"] = fields[5]
- msg["body"] = str_tail(str_join(fields, 1, 5, FS1) FS1, line)
- } else if (type == "log") {
- msg["location"] = fields[4]
- msg["level"] = fields[5]
- msg["msg"] = str_tail(str_join(fields, 1, 5, FS1) FS1, line)
- } else if (type == "status_bar") {
- msg["status_bar"] = str_tail(str_join(fields, 1, 3, FS1) FS1, line)
- } else {
- msg_out_log_error(\
- "msg_in_parse",
- "Unexpected msg type: " type " in given input line: " line \
- )
- exit 1
- }
-}