Add memory sensor
[khatus.git] / x2 / src / awk / lib / msg.awk
... / ...
CommitLineData
1BEGIN {
2 FS1 = "|" # Fields separator, level 1 (record to fields)
3 FS2 = ":" # Fields separator, level 2 (field to subfields
4
5 OFS = FS1
6 Kfs = FS2
7}
8
9function 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
42# -----------------------------------------------------------------------------
43# alert
44# -----------------------------------------------------------------------------
45function msg_out_alert_low(subject, body) {
46 msg_out_alert("low", subject, body)
47}
48
49function msg_out_alert_med(subject, body) {
50 msg_out_alert("med", subject, body)
51}
52
53function msg_out_alert_hi(subject, body) {
54 msg_out_alert("hi", subject, body)
55}
56
57function msg_out_alert(priority, subject, body) {
58 # priority : "low" | "med" | "hi"
59 # subject : string without spaces
60 # body : anything
61 print(Node, Module, "alert", priority, subject, body)
62}
63
64# -----------------------------------------------------------------------------
65# log
66# -----------------------------------------------------------------------------
67function msg_out_log_info(location, msg) {
68 msg_out_log("info", location, msg)
69}
70
71function msg_out_log_error(location, msg) {
72 msg_out_log("error", location, msg)
73}
74
75function msg_out_log(level, location, msg) {
76 print(Node, Module, "log", location, level, msg) > "/dev/stderr"
77}
78
79# -----------------------------------------------------------------------------
80# status_bar
81# -----------------------------------------------------------------------------
82function msg_out_status_bar(bar) {
83 print(Node, Module, "status_bar", bar)
84}
85
86# -----------------------------------------------------------------------------
87# data
88# -----------------------------------------------------------------------------
89function msg_out_data(key, val) {
90 print(Node, Module, "data", key, val)
91}
This page took 0.024065 seconds and 4 git commands to generate.