Commit | Line | Data |
---|---|---|
03c229bf SK |
1 | BEGIN { |
2 | # TODO: Read spec from a file | |
3 | bat_alert_spec[100] = "low|Energy_Bellow_Full|Must have perfection!" | |
4 | bat_alert_spec[50] = "low|Energy_Bellow_Half|Where is the charger?" | |
5 | bat_alert_spec[20] = "med|Energy_Low|Get the charger." | |
6 | bat_alert_spec[15] = "med|Energy_Low|Get the charger!" | |
7 | bat_alert_spec[10] = "hi|Energy_Low|Plug it in, ASAP!" | |
8 | bat_alert_spec[5] = "hi|Energy_CRITICALLY_Low|CHARGE NOW!!! GO GO GO!!!" | |
9 | } | |
10 | ||
8482fea6 | 11 | $1 == Node && \ |
03c229bf | 12 | $2 == "khatus_sensor_energy" && \ |
8482fea6 SK |
13 | $3 == "data" && \ |
14 | $4 == "line_power" { | |
03c229bf | 15 | line_power_prev = line_power_curr |
8482fea6 | 16 | line_power_curr = $5 |
03c229bf | 17 | if (line_power_curr == "no" && line_power_prev != "no") { |
8482fea6 | 18 | msg_out_alert_low("PowerUnplugged", "") |
03c229bf SK |
19 | } |
20 | } | |
21 | ||
8482fea6 | 22 | $1 == Node && \ |
03c229bf | 23 | $2 == "khatus_sensor_energy" && \ |
8482fea6 SK |
24 | $3 == "data" && \ |
25 | $4 == "battery_state" { | |
03c229bf | 26 | battery_state_prev = battery_state_curr |
8482fea6 | 27 | battery_state_curr = $5 |
03c229bf SK |
28 | } |
29 | ||
8482fea6 | 30 | $1 == Node && \ |
03c229bf | 31 | $2 == "khatus_sensor_energy" && \ |
8482fea6 SK |
32 | $3 == "data" && \ |
33 | $4 == "battery_percentage" { | |
03c229bf | 34 | # TODO: Re-think the spec - can't rely on order of keys |
8482fea6 | 35 | battery_percentage = num_ensure_numeric($5) |
03c229bf SK |
36 | if (battery_state_curr == "discharging") { |
37 | for (threshold in bat_alert_spec) { | |
8482fea6 | 38 | threshold = num_ensure_numeric(threshold) |
03c229bf | 39 | if (battery_percentage <= threshold && !_alerted[threshold]) { |
8482fea6 SK |
40 | split(bat_alert_spec[threshold], alert, "|") |
41 | priority = alert[1] | |
42 | subject = alert[2] | |
43 | body = sprintf("%d%% %s", battery_percentage, alert[3]) | |
44 | msg_out_alert(priority, subject, body) | |
03c229bf SK |
45 | _alerted[threshold]++ |
46 | } | |
47 | } | |
48 | } else { | |
49 | delete _alerted | |
50 | } | |
51 | } |