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!!!"
16 msg
["node"] == Node
&& \
17 msg
["module"] ==
"khatus_sensor_energy" && \
18 msg
["type"] ==
"data" && \
19 msg
["key"] ==
"line_power" {
20 line_power_prev = line_power_curr
21 line_power_curr = msg
["val"]
22 if (line_power_curr ==
"no" && line_power_prev
!= "no") {
23 msg_out_alert_low
("PowerUnplugged", "")
27 msg
["node"] == Node
&& \
28 msg
["module"] ==
"khatus_sensor_energy" && \
29 msg
["type"] ==
"data" && \
30 msg
["key"] ==
"battery_state" {
31 battery_state_prev = battery_state_curr
32 battery_state_curr = msg
["val"]
35 msg
["node"] == Node
&& \
36 msg
["module"] ==
"khatus_sensor_energy" && \
37 msg
["type"] ==
"data" && \
38 msg
["key"] ==
"battery_percentage" {
39 # TODO: Re-think the spec - can't rely on order of keys
40 battery_percentage = num_ensure_numeric
(msg
["val"])
41 if (battery_state_curr ==
"discharging") {
42 for (threshold in bat_alert_spec
) {
43 threshold = num_ensure_numeric
(threshold
)
44 if (battery_percentage
<= threshold
&& !_alerted
[threshold
]) {
45 split(bat_alert_spec
[threshold
], alert
, "|")
48 body =
sprintf("%d%% %s", battery_percentage
, alert
[3])
49 msg_out_alert
(priority
, subject
, body
)