cmd_sens_memory="khatus_sensor_memory $bin"
fork_watcher "$pipe" "$bin" "khatus_sensor_energy $bin"
+ fork_watcher "$pipe" "$bin" "khatus_sensor_devices $bin"
fork_poller "${opts['--interval_datetime']}" "$perf" "$pipe" "$bin" khatus_sensor_datetime
fork_poller "${opts['--interval_brightness']}" "$perf" "$pipe" "$bin" "$cmd_sens_screen_brightness"
fork_poller "${opts['--interval_weather']}" "$perf" "$pipe" "$bin" "$cmd_sens_weather"
--- /dev/null
+#! /usr/bin/awk -f
+
+BEGIN {
+ FS = msg_fs ? msg_fs : "|"
+ OFS = msg_fs ? msg_fs : "|"
+ Kfs = key_fs ? key_fs : ":"
+}
+
+$1 == "OK" && \
+$2 == "khatus_sensor_devices" \
+{
+ alert("low", "BlockDeviceEvent", $3 " " $4)
+}
+
+function alert(priority, subject, body) {
+ # priority : "low" | "med" | "hi"
+ # subject : no spaces
+ # body : anything
+ print("OK", "khatus_monitor_devices", "alert", priority, subject, body)
+}
--- /dev/null
+#! /usr/bin/awk -f
+
+BEGIN {
+ OFS = msg_fs ? msg_fs : "|"
+ Kfs = key_fs ? key_fs : ":"
+
+ Re_Begin = "^UDEV + \[ *[0-9]+\.[0-9]+\] +"
+}
+
+($0 ~ Re_Begin) {
+ handle_event($0)
+ next
+}
+
+function handle_event(payload, payload_parts, event,
+ path, n_path_parts,
+ devname \
+) {
+ sub(Re_Begin, "", payload)
+ split(payload, payload_parts, " +")
+ event = payload_parts[1]
+ path = payload_parts[2]
+ if (event == "add" || event == "change") {
+ devname = devname_lookup(path)
+ } else {
+ n_path_parts = split(path, path_parts, "/")
+ devname = path_parts[n_path_parts]
+ }
+ print(event, devname)
+}
+
+function devname_lookup(path, cmd, line_parts, devname) {
+ cmd = "udevadm info --path=" path
+ while (cmd | getline line) {
+ if (line ~ /^E: +DEVNAME/) {
+ split(line, line_parts, "=")
+ devname = line_parts[2]
+ break
+ }
+ }
+ close(cmd)
+ return devname
+}