X-Git-Url: https://git.xandkar.net/?p=khatus.git;a=blobdiff_plain;f=src%2Fawk%2Fexe%2Fmonitor_energy.awk;h=518d68701ba2604a84fe70e0f741fcbd72a61290;hp=0d3f33906a18b0e2c4d482310bab8f6187f11df2;hb=8482fea64a51f9a9b97895c974a88a986b42aa15;hpb=e103315c72597a9cc9fffaaff11e04b30d1c6416 diff --git a/src/awk/exe/monitor_energy.awk b/src/awk/exe/monitor_energy.awk index 0d3f339..518d687 100755 --- a/src/awk/exe/monitor_energy.awk +++ b/src/awk/exe/monitor_energy.awk @@ -8,37 +8,40 @@ BEGIN { bat_alert_spec[5] = "hi|Energy_CRITICALLY_Low|CHARGE NOW!!! GO GO GO!!!" } -$1 == "OK" && \ +$1 == Node && \ $2 == "khatus_sensor_energy" && \ -$3 == "line_power" { +$3 == "data" && \ +$4 == "line_power" { line_power_prev = line_power_curr - line_power_curr = $4 + line_power_curr = $5 if (line_power_curr == "no" && line_power_prev != "no") { - msg_out_ok_alert("low", "PowerUnplugged", "") + msg_out_alert_low("PowerUnplugged", "") } } -$1 == "OK" && \ +$1 == Node && \ $2 == "khatus_sensor_energy" && \ -$3 == "battery_state" { +$3 == "data" && \ +$4 == "battery_state" { battery_state_prev = battery_state_curr - battery_state_curr = $4 + battery_state_curr = $5 } -$1 == "OK" && \ +$1 == Node && \ $2 == "khatus_sensor_energy" && \ -$3 == "battery_percentage" { +$3 == "data" && \ +$4 == "battery_percentage" { # TODO: Re-think the spec - can't rely on order of keys - battery_percentage = util_ensure_numeric($4) + battery_percentage = num_ensure_numeric($5) if (battery_state_curr == "discharging") { for (threshold in bat_alert_spec) { - threshold = util_ensure_numeric(threshold) + threshold = num_ensure_numeric(threshold) if (battery_percentage <= threshold && !_alerted[threshold]) { - split(bat_alert_spec[threshold], msg, "|") - priority = msg[1] - subject = msg[2] - body = sprintf("%d%% %s", battery_percentage, msg[3]) - msg_out_ok_alert(priority, subject, body) + split(bat_alert_spec[threshold], alert, "|") + priority = alert[1] + subject = alert[2] + body = sprintf("%d%% %s", battery_percentage, alert[3]) + msg_out_alert(priority, subject, body) _alerted[threshold]++ } }