Add memory sensor
[khatus.git] / x2 / src / awk / exe / monitor_energy.awk
... / ...
CommitLineData
1BEGIN {
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
11{
12 delete msg
13 msg_parse(msg, $0)
14}
15
16msg["node"] == Node && \
17msg["module"] == "khatus_sensor_energy" && \
18msg["type"] == "data" && \
19msg["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", "")
24 }
25}
26
27msg["node"] == Node && \
28msg["module"] == "khatus_sensor_energy" && \
29msg["type"] == "data" && \
30msg["key"] == "battery_state" {
31 battery_state_prev = battery_state_curr
32 battery_state_curr = msg["val"]
33}
34
35msg["node"] == Node && \
36msg["module"] == "khatus_sensor_energy" && \
37msg["type"] == "data" && \
38msg["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, "|")
46 priority = alert[1]
47 subject = alert[2]
48 body = sprintf("%d%% %s", battery_percentage, alert[3])
49 msg_out_alert(priority, subject, body)
50 _alerted[threshold]++
51 }
52 }
53 } else {
54 delete _alerted
55 }
56}
This page took 0.022119 seconds and 4 git commands to generate.