3 Parses xymon alerting files
5 Author: Francois Maillard <fmaillard@gmail.com>
8 This lens tries to keep as close as possible to `man 5 alerts.cfg` where possible.
11 This file is licenced under the LGPL v2+, like the rest of Augeas.
17 File inclusion are not followed
19 About: Configuration files
20 This lens applies to /etc/xymon/alerts.d/*.cfg and /etc/xymon/alerts.cfg. See <filter>.
23 The <Test_Xymon_Alerting> file contains various examples and tests.
26 module Xymon_Alerting =
29 (************************************************************************
30 * Group: USEFUL PRIMITIVES
31 *************************************************************************)
33 (* View: store_word *)
34 let store_word = store /[^ =\t\n#]+/
36 (* View: comparison The greater and lesser than operators *)
37 let comparison = store /[<>]/
49 let ws_or_eol = del /([ \t]+|[ \t]*\n[ \t]*)/ " "
52 let comment = Util.comment
55 let empty = Util.empty
58 let include = [ key "include" . ws . store_word . eol ]
60 (************************************************************************
61 * Group: MACRO DEFINITION
62 *************************************************************************)
64 (* View: macrodefinition
65 A string that starts with $ and that is assigned something *)
66 let macrodefinition = [ key /\$[^ =\t\n#\/]+/ . Sep.space_equal . store Rx.space_in . eol ]
71 let flag (kw:string) = Build.flag kw
75 let kw_word (kw:regexp) = Build.key_value kw equal store_word
77 (************************************************************************
79 *************************************************************************)
82 The (ex)?page filter definition *)
83 let page = kw_word /(EX)?PAGE/
86 The (ex)?group filter definition *)
87 let group = kw_word /(EX)?GROUP/
90 The (ex)?host filter definition *)
91 let host = kw_word /(EX)?HOST/
94 The (ex)?service filter definition *)
95 let service = kw_word /(EX)?SERVICE/
98 The color filter definition *)
99 let color = kw_word "COLOR"
102 The time filter definition *)
103 let time = kw_word "TIME"
106 The duration filter definition *)
107 let duration = [ key "DURATION" . [ label "operator" . comparison ] . [ label "value" . store_word ] ]
109 The recover filter definition *)
110 let recover = flag "RECOVER"
112 The notice filter definition *)
113 let notice = flag "NOTICE"
116 Filters are made out of any of the above filter definitions *)
117 let rule_filter = page | group | host | service
118 | color | time | duration | recover | notice
121 One or more filters *)
122 let filters = [ label "filters" . Build.opt_list rule_filter ws ]
125 Zero, one or more filters *)
126 let filters_opt = [ label "filters" . (ws . Build.opt_list rule_filter ws)? ]
128 (* View: kw_word_filters_opt
129 A <kw_word> entry with optional filters *)
130 let kw_word_filters_opt (kw:string) = [ key kw . equal . store_word . filters_opt ]
132 (* View: flag_filters_opt
133 A <flag> with optional filters *)
134 let flag_filters_opt (kw:string) = [ key kw . filters_opt ]
136 (************************************************************************
138 *************************************************************************)
141 The mail recipient definition *)
142 let mail = [ key "MAIL" . ws . store_word . filters_opt ]
145 The script recipient definition *)
146 let script = [ key "SCRIPT" . ws . [ label "script" . store_word ]
147 . ws . [ label "recipient" . store_word ] . filters_opt ]
150 The ignore recipient definition *)
151 let ignore = flag_filters_opt "IGNORE"
154 The format recipient definition *)
155 let format = kw_word_filters_opt "FORMAT"
158 The repeat recipient definition *)
159 let repeat = kw_word_filters_opt "REPEAT"
162 The unmatched recipient definition *)
163 let unmatched = flag_filters_opt "UNMATCHED"
166 The stop recipient definition *)
167 let stop = flag_filters_opt "STOP"
170 The macro recipient definition *)
171 let macro = [ key /\$[^ =\t\n#\/]+/ . filters_opt ]
174 Recipients are made out of any of the above recipient definitions *)
175 let recipient = mail | script | ignore | format | repeat | unmatched
178 let recipients = [ label "recipients" . Build.opt_list recipient ws_or_eol ]
181 (************************************************************************
183 *************************************************************************)
186 Rules are made of rule_filter and then recipients sperarated by a whitespace *)
187 let rule = [ seq "rules" . filters . ws_or_eol . recipients . eol ]
190 The Xymon_Alerting lens *)
191 let lns = ( rule | macrodefinition | include | empty | comment )*
193 (* Variable: filter *)
194 let filter = incl "/etc/xymon/alerts.d/*.cfg"
195 . incl "/etc/xymon/alerts.cfg"
198 let xfm = transform lns filter