Imported Upstream version 1.7.0
[platform/upstream/augeas.git] / lenses / xymon_alerting.aug
1 (*
2 Module: Xymon_Alerting
3   Parses xymon alerting files 
4
5 Author: Francois Maillard <fmaillard@gmail.com>
6
7 About: Reference
8   This lens tries to keep as close as possible to `man 5 alerts.cfg` where possible.
9
10 About: License
11    This file is licenced under the LGPL v2+, like the rest of Augeas.
12
13 About: Lens Usage
14    To be documented
15
16 About: Not supported
17    File inclusion are not followed
18
19 About: Configuration files
20    This lens applies to /etc/xymon/alerts.d/*.cfg and /etc/xymon/alerts.cfg. See <filter>.
21
22 About: Examples
23    The <Test_Xymon_Alerting> file contains various examples and tests.
24 *)
25
26 module Xymon_Alerting =
27     autoload xfm
28
29     (************************************************************************
30      * Group:                 USEFUL PRIMITIVES
31      *************************************************************************)
32
33     (* View: store_word *)
34     let store_word  = store /[^ =\t\n#]+/
35
36     (* View: comparison The greater and lesser than operators *)
37     let comparison  = store /[<>]/
38
39     (* View: equal *)
40     let equal       = Sep.equal
41
42     (* View: ws *)
43     let ws          = Sep.space
44
45     (* View: eol *)
46     let eol         = Util.eol
47
48     (* View: ws_or_eol *)
49     let ws_or_eol   = del /([ \t]+|[ \t]*\n[ \t]*)/ " "
50
51     (* View: comment *)
52     let comment = Util.comment
53
54     (* View: empty *)
55     let empty   = Util.empty
56
57     (* View: include *)
58     let include         = [ key "include" . ws . store_word . eol ]
59
60     (************************************************************************
61      * Group:                 MACRO DEFINITION
62      *************************************************************************)
63
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 ]
67
68
69     (* View: flag
70          A flag value *)
71     let flag (kw:string) = Build.flag kw
72
73     (* View: kw_word
74          A key=value value *)
75     let kw_word (kw:regexp) = Build.key_value kw equal store_word
76
77     (************************************************************************
78      * Group:                 FILTERS 
79      *************************************************************************)
80
81     (* View: page
82          The (ex)?page filter definition *)
83     let page      = kw_word /(EX)?PAGE/
84
85     (* View: group
86          The (ex)?group filter definition *)
87     let group     = kw_word /(EX)?GROUP/
88
89     (* View: host
90          The (ex)?host filter definition *)
91     let host      = kw_word /(EX)?HOST/
92
93     (* View: service
94          The (ex)?service filter definition *)
95     let service   = kw_word /(EX)?SERVICE/
96
97     (* View: color
98          The color filter definition *)
99     let color     = kw_word "COLOR"
100
101     (* View: time
102          The time filter definition *)
103     let time      = kw_word "TIME"
104
105     (* View: duration
106          The duration filter definition *)
107     let duration  = [ key "DURATION" . [ label "operator" . comparison ] . [ label "value" . store_word ] ]
108     (* View: recover
109          The recover filter definition *)
110     let recover   = flag "RECOVER"
111     (* View: notice
112          The notice filter definition *)
113     let notice    = flag "NOTICE"
114
115     (* View: rule_filter
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
119
120     (* View: filters
121          One or more filters *)
122     let filters = [ label "filters" . Build.opt_list rule_filter ws ]
123
124     (* View: filters_opt
125          Zero, one or more filters *)
126     let filters_opt = [ label "filters" . (ws . Build.opt_list rule_filter ws)? ]
127
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 ]
131
132     (* View: flag_filters_opt
133          A <flag> with optional filters *) 
134     let flag_filters_opt (kw:string) = [ key kw . filters_opt ]
135
136     (************************************************************************
137      * Group:                 RECIPIENTS
138      *************************************************************************)
139
140     (* View: mail
141          The mail recipient definition *)
142     let mail      = [ key "MAIL" . ws . store_word . filters_opt ]
143
144     (* View: script
145          The script recipient definition *)
146     let script    = [ key "SCRIPT" . ws . [ label "script" . store_word ]
147                   . ws . [ label "recipient" . store_word ] . filters_opt ]
148
149     (* View: ignore
150          The ignore recipient definition *)
151     let ignore    = flag_filters_opt "IGNORE"
152
153     (* View: format
154          The format recipient definition *)
155     let format    = kw_word_filters_opt "FORMAT"
156
157     (* View: repeat
158          The repeat recipient definition *)
159     let repeat    = kw_word_filters_opt "REPEAT"
160
161     (* View: unmatched
162          The unmatched recipient definition *)
163     let unmatched = flag_filters_opt "UNMATCHED"
164
165     (* View: stop
166          The stop recipient definition *)
167     let stop      = flag_filters_opt "STOP"
168
169     (* View: macro
170          The macro recipient definition *)
171     let macro     = [ key /\$[^ =\t\n#\/]+/ . filters_opt ]
172
173     (* View: recipient
174          Recipients are made out of any of the above recipient definitions *)
175     let recipient = mail | script | ignore | format | repeat | unmatched
176                   | stop | macro
177
178     let recipients = [ label "recipients" . Build.opt_list recipient ws_or_eol ]
179
180
181     (************************************************************************
182      * Group:                 RULES
183      *************************************************************************)
184
185     (* View: rule
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 ] 
188
189     (* View: lns
190          The Xymon_Alerting lens *)
191     let lns = ( rule | macrodefinition | include | empty | comment )*
192
193     (* Variable: filter *)
194     let filter = incl "/etc/xymon/alerts.d/*.cfg"
195                . incl "/etc/xymon/alerts.cfg"
196                . Util.stdexcl
197
198     let xfm = transform lns filter
199