Commit | Line | Data |
---|---|---|
03c229bf | 1 | BEGIN { |
e23b85d7 SK |
2 | FS1 = "|" # Fields separator, level 1 (record to fields) |
3 | FS2 = ":" # Fields separator, level 2 (field to subfields | |
8482fea6 SK |
4 | |
5 | OFS = FS1 | |
6 | Kfs = FS2 | |
7 | } | |
8 | ||
81336934 SK |
9 | function msg_parse(msg, line, status, fields, type) { |
10 | split(line, fields, FS1) | |
11 | msg["node"] = fields[1] | |
12 | msg["module"] = fields[2] | |
13 | type = fields[3] | |
14 | msg["type"] = type | |
15 | ||
16 | status = 1 | |
17 | if (type == "data") { | |
18 | msg["key"] = fields[4] | |
19 | msg["val"] = str_tail(str_join(fields, 1, 4, FS1) FS1, line) | |
20 | } else if (type == "error") { | |
21 | msg["line"] = str_tail(str_join(fields, 1, 3, FS1) FS1, line) | |
22 | } else if (type == "alert") { | |
23 | msg["priority"] = fields[4] | |
24 | msg["subject"] = fields[5] | |
25 | msg["body"] = str_tail(str_join(fields, 1, 5, FS1) FS1, line) | |
26 | } else if (type == "log") { | |
27 | msg["location"] = fields[4] | |
28 | msg["level"] = fields[5] | |
29 | msg["msg"] = str_tail(str_join(fields, 1, 5, FS1) FS1, line) | |
30 | } else if (type == "status_bar") { | |
31 | msg["status_bar"] = str_tail(str_join(fields, 1, 3, FS1) FS1, line) | |
32 | } else { | |
33 | msg_out_log_error(\ | |
34 | "msg_parse", | |
35 | "Unexpected msg type: " type " in given input line: " line \ | |
36 | ) | |
37 | status = 0 | |
38 | } | |
39 | return status | |
40 | } | |
41 | ||
8482fea6 SK |
42 | # ----------------------------------------------------------------------------- |
43 | # alert | |
44 | # ----------------------------------------------------------------------------- | |
45 | function msg_out_alert_low(subject, body) { | |
46 | msg_out_alert("low", subject, body) | |
47 | } | |
48 | ||
49 | function msg_out_alert_med(subject, body) { | |
50 | msg_out_alert("med", subject, body) | |
03c229bf SK |
51 | } |
52 | ||
8482fea6 SK |
53 | function msg_out_alert_hi(subject, body) { |
54 | msg_out_alert("hi", subject, body) | |
55 | } | |
56 | ||
57 | function msg_out_alert(priority, subject, body) { | |
e103315c SK |
58 | # priority : "low" | "med" | "hi" |
59 | # subject : string without spaces | |
60 | # body : anything | |
8482fea6 SK |
61 | print(Node, Module, "alert", priority, subject, body) |
62 | } | |
63 | ||
64 | # ----------------------------------------------------------------------------- | |
65 | # log | |
66 | # ----------------------------------------------------------------------------- | |
67 | function msg_out_log_info(location, msg) { | |
68 | msg_out_log("info", location, msg) | |
e103315c SK |
69 | } |
70 | ||
8482fea6 SK |
71 | function msg_out_log_error(location, msg) { |
72 | msg_out_log("error", location, msg) | |
03c229bf SK |
73 | } |
74 | ||
8482fea6 SK |
75 | function msg_out_log(level, location, msg) { |
76 | print(Node, Module, "log", location, level, msg) > "/dev/stderr" | |
03c229bf SK |
77 | } |
78 | ||
8482fea6 SK |
79 | # ----------------------------------------------------------------------------- |
80 | # status_bar | |
81 | # ----------------------------------------------------------------------------- | |
82 | function msg_out_status_bar(bar) { | |
83 | print(Node, Module, "status_bar", bar) | |
03c229bf SK |
84 | } |
85 | ||
8482fea6 SK |
86 | # ----------------------------------------------------------------------------- |
87 | # data | |
88 | # ----------------------------------------------------------------------------- | |
89 | function msg_out_data(key, val) { | |
90 | print(Node, Module, "data", key, val) | |
03c229bf | 91 | } |