Do not rely on FS for msg parsing
[khatus.git] / src / awk / lib / msg.awk
similarity index 61%
rename from src/awk/lib/msg_out.awk
rename to src/awk/lib/msg.awk
index 24393c6..fba25e7 100644 (file)
@@ -6,6 +6,39 @@ BEGIN {
     Kfs = FS2
 }
 
+function msg_parse(msg, line,    status, fields, type) {
+    split(line, fields, FS1)
+    msg["node"]   = fields[1]
+    msg["module"] = fields[2]
+    type          = fields[3]
+    msg["type"]   = type
+
+    status = 1
+    if (type == "data") {
+        msg["key"] = fields[4]
+        msg["val"] = str_tail(str_join(fields, 1, 4, FS1) FS1, line)
+    } else if (type == "error") {
+        msg["line"] = str_tail(str_join(fields, 1, 3, FS1) FS1, line)
+    } else if (type == "alert") {
+        msg["priority"] = fields[4]
+        msg["subject"]  = fields[5]
+        msg["body"]     = str_tail(str_join(fields, 1, 5, FS1) FS1, line)
+    } else if (type == "log") {
+        msg["location"] = fields[4]
+        msg["level"]    = fields[5]
+        msg["msg"]      = str_tail(str_join(fields, 1, 5, FS1) FS1, line)
+    } else if (type == "status_bar") {
+        msg["status_bar"] = str_tail(str_join(fields, 1, 3, FS1) FS1, line)
+    } else {
+        msg_out_log_error(\
+            "msg_parse",
+            "Unexpected msg type: " type " in given input line: " line \
+        )
+        status = 0
+    }
+    return status
+}
+
 # -----------------------------------------------------------------------------
 # alert
 # -----------------------------------------------------------------------------
This page took 0.03263 seconds and 4 git commands to generate.