Improve overview and experiment naming
[khatus.git] / x3 / src / lib / khatus_msg.ml
CommitLineData
c6a7396e
SK
1module Time = Khatus_time
2
3type content =
4 | Alert of {priority : [`low | `med | `hi]; subject : string; body : string}
5 | Data of {key : string list; value : string}
6 | Cache of
7 { mtime : Time.t
8 ; node : string
9 ; modul : string
10 ; key : string list
11 ; value : string
12 }
13 | Error of string
14 | Log of {location : string; level : [`info | `error]; msg : string}
15 | Status_bar of string
16
17type t =
18 {node : string; modul : string; content : content}
19
6f35286a
SK
20type 'a data_handler =
21 node:string -> modul:string -> key:string list -> value:string -> 'a
22
c6a7396e
SK
23let sep_1 = "|"
24let sep_2 = ":"
25
26let to_string {node; modul; content} =
27 match content with
28 | Alert {priority; subject; body} ->
29 let priority =
30 match priority with
31 | `hi -> "hi"
32 | `med -> "med"
33 | `low -> "low"
34 in
35 String.concat sep_1 [node; modul; "alert"; priority; subject; body]
36 | Data {key; value} ->
37 let key = String.concat sep_2 key in
38 String.concat sep_1 [node; modul; "data"; key; value]
39 | Cache {mtime; node=node'; modul=modul'; key; value} ->
40 let key = String.concat sep_2 key in
41 let mtime = Time.to_string mtime in
42 String.concat
43 sep_1
44 [node; modul; "cache"; mtime; node'; modul'; key; value]
45 | Error text ->
46 String.concat sep_1 [node; modul; "error"; text]
47 | Log {location; level; msg} ->
48 let level =
49 match level with
50 | `info -> "info"
51 | `error -> "error"
52 in
53 String.concat sep_1 [node; modul; "log"; location; level; msg]
54 | Status_bar text ->
55 String.concat sep_1 [node; modul; "status_bar"; text]
56
6f35286a 57let handle_data t ~f ~otherwise =
c6a7396e 58 match t with
6f35286a
SK
59 | {content = Data {key; value}; node; modul} ->
60 f ~node ~modul ~key ~value
c6a7396e
SK
61 | {content = Alert _; _}
62 | {content = Cache _; _}
63 | {content = Error _; _}
64 | {content = Log _; _}
65 | {content = Status_bar _; _}
66 ->
6f35286a 67 otherwise
This page took 0.021145 seconds and 4 git commands to generate.