Imported Upstream version 1.7.0
[platform/upstream/augeas.git] / lenses / chrony.aug
1 (*
2 Module: Chrony
3   Parses the chrony config file
4
5 Author: Pat Riehecky <riehecky@fnal.gov>
6
7 About: Reference
8   This lens tries to keep as close as possible to chrony config syntax
9
10   See http://chrony.tuxfamily.org/manual.html#Configuration-file
11
12 About: License
13   This file is licenced under the LGPL v2+, like the rest of Augeas.
14
15 About: Lens Usage
16   To be documented
17
18 About: Configuration files
19   This lens applies to /etc/chrony.conf
20
21   See <filter>.
22 *)
23
24 module Chrony =
25   autoload xfm
26
27 (************************************************************************
28  * Group: Import provided expressions
29  ************************************************************************)
30     (* View: empty *)
31     let empty   = Util.empty
32
33     (* View: eol *)
34     let eol     = Util.eol
35
36     (* View: space *)
37     let space   = Sep.space
38
39     (* Variable: email_addr *)
40     let email_addr = Rx.email_addr
41
42     (* Variable: word *)
43     let word       = Rx.word
44
45     (* Variable: integer *)
46     let integer    = Rx.relinteger
47
48     (* Variable: decimal *)
49     let decimal    = Rx.reldecimal
50
51     (* Variable: ip *)
52     let ip         = Rx.ip
53
54     (* Variable: path *)
55     let path       = Rx.fspath
56
57 (************************************************************************
58  * Group: Create required expressions
59  ************************************************************************)
60     (* Variable: number *)
61     let number = integer | decimal
62
63     (* Variable: address_re *)
64     let address_re = Rx.ip | Rx.hostname
65
66     (*
67        View: comment
68             from 4.2.1 of the upstream doc
69             Chrony comments start with: ! ; # or % and must be on their own line
70     *)
71     let comment = Util.comment_generic /[ \t]*[!;#%][ \t]*/ "# "
72
73     (* Variable: no_space
74          No spaces or comment characters
75     *)
76     let no_space   = /[^ \t\r\n!;#%]+/
77
78     (* Variable: cmd_options
79          Server/Peer/Pool options with values
80     *)
81     let cmd_options = "key"
82                     | /maxdelay((dev)?ratio)?/
83                     | /(min|max)poll/
84                     | /(min|max)samples/
85                     | "maxsources"
86                     | "polltarget"
87                     | "port"
88                     | "presend"
89                     | "version"
90
91     (* Variable: cmd_flags
92          Server/Peer/Pool options without values
93     *)
94     let cmd_flags = "auto_offline"|"iburst"|"noselect"|"offline"|"prefer"
95                     |"require"|"trust"
96
97     (* Variable: ntp_source
98          Server/Peer/Pool key names
99     *)
100     let ntp_source = "server"|"peer"|"pool"
101
102     (* Variable: allowdeny_types
103          Key names for access configuration
104     *)
105     let allowdeny_types = "allow"|"deny"|"cmdallow"|"cmddeny"
106
107     (* Variable: local_options
108          local options with values
109     *)
110     let local_options = "stratum"|"distance"
111
112     (* Variable: local_flags
113          local options without values
114     *)
115     let local_flags = "orphan"
116
117     (* Variable: ratelimit_options
118          Rate limiting options with values
119     *)
120     let ratelimit_options = "interval"|"burst"|"leak"
121
122     (* Variable: refclock_options
123          refclock options with values
124     *)
125     let refclock_options = "refid"|"lock"|"poll"|"dpoll"|"filter"|"rate"
126                             |"minsamples"|"maxsamples"|"offset"|"delay"
127                             |"precision"|"maxdispersion"
128
129     (* Variable: refclock_flags
130          refclock options without values
131     *)
132     let refclock_flags = "noselect"|"prefer"|"require"|"trust"
133
134     (* Variable: flags
135          Options without values
136     *)
137     let flags = "dumponexit"
138               | "generatecommandkey"
139               | "lock_all"
140               | "manual"
141               | "noclientlog"
142               | "rtconutc"
143               | "rtcsync"
144
145     (* Variable: log_flags
146         log has a specific options list
147     *)
148     let log_flags = /measurements|statistics|tracking|rtc|refclocks|tempcomp/
149
150     (* Variable: simple_keys
151          Options with single values
152     *)
153     let simple_keys = "acquisitionport" | "bindacqaddress"
154                     | "bindaddress" | "bindcmdaddress" | "clientloglimit"
155                     | "combinelimit" | "commandkey"
156                     | "cmdport" | "corrtimeratio" | "driftfile"
157                     | "dumpdir" | "hwclockfile" | "include" | "keyfile"
158                     | "leapsecmode" | "leapsectz" | "linux_freq_scale"
159                     | "linux_hz" | "logbanner" | "logchange" | "logdir"
160                     | "maxdistance" | "maxdrift"
161                     | "maxclockerror" | "maxsamples" | "maxslewrate"
162                     | "maxupdateskew" | "minsamples" | "minsources" | "pidfile"
163                     | "port" | "reselectdist" | "rtcautotrim" | "rtcdevice"
164                     | "rtcfile" | "sched_priority" | "stratumweight" | "user"
165
166 (************************************************************************
167  * Group: Make some sub-lenses for use in later lenses
168  ************************************************************************)
169     (* View: host_flags *)
170     let host_flags = [ space . key cmd_flags ]
171     (* View: host_options *)
172     let host_options = [ space . key cmd_options . space . store integer ]
173     (* View: log_flag_list *)
174     let log_flag_list = [ space . key log_flags ]
175     (* View: store_address *)
176     let store_address = [ label "address" . store address_re ]
177
178 (************************************************************************
179  * Group: Lenses for parsing out sections
180  ************************************************************************)
181     (* View: all_flags
182         options without any arguments
183     *)
184     let all_flags = [ Util.indent . key flags . eol ]
185
186     (* View: kv
187         options with only one arg can be directly mapped to key = value
188     *)
189     let kv = [ Util.indent . key simple_keys . space . (store no_space) . eol ]
190
191     (* Property: Options with multiple values
192     
193       Each of these gets their own parsing block
194       - server|peer|pool <address> <options>
195       - allow|deny|cmdallow|cmddeny [all] [<address[/subnet]>]
196       - log <options>
197       - broadcast <interval> <address> <optional port>
198       - fallbackdrift <min> <max>
199       - initstepslew <threshold> <addr> <optional extra addrs>
200       - local <options>
201       - mailonchange <emailaddress> <threshold>
202       - makestep <threshold> <limit>
203       - maxchange <threshold> <delay> <limit>
204       - ratelimit|cmdratelimit <options>
205       - refclock <driver> <parameter> <options>
206       - smoothtime <maxfreq> <maxwander> <options>
207       - tempcomp <sensorfile> <interval> (<t0> <k0> <k1> <k2> | <pointfile> )
208     *)
209
210     (* View: host_list
211         Find all NTP sources and their flags/options
212     *)
213     let host_list = [ Util.indent . key ntp_source
214                          . space . store address_re
215                          . ( host_flags | host_options )*
216                          . eol ]
217
218     (* View: allowdeny
219         allow/deny/cmdallow/cmddeny has a specific syntax
220     *)
221     let allowdeny = [ Util.indent . key allowdeny_types
222                         . [ space . key "all" ]?
223                         . ( space . store ( no_space - "all" ) )?
224                         . eol ]
225
226     (* View: log_list
227         log has a specific options list
228     *)
229     let log_list = [ Util.indent . key "log" . log_flag_list+ . eol ]
230
231     (* View: bcast
232          broadcast has specific syntax
233     *)
234     let bcast = [ Util.indent . key "broadcast"
235                       . space . [ label "interval" . store integer ]
236                       . space . store_address
237                       . ( space . [ label "port" . store integer ] )?
238                       . eol ]
239
240     (* View: fdrift
241          fallbackdrift has specific syntax
242     *)
243     let fdrift = [ Util.indent . key "fallbackdrift"
244                       . space . [ label "min" . store integer ]
245                       . space . [ label "max" . store integer ]
246                       . eol ]
247
248     (* View: istepslew
249          initstepslew has specific syntax
250     *)
251     let istepslew = [ Util.indent . key "initstepslew" 
252                          . space . [ label "threshold" . store number ]
253                          . ( space . store_address )+
254                          . eol ]
255
256     (* View: local
257          local has specific syntax
258     *)
259     let local = [ Util.indent . key "local"
260                       . ( space . ( [ key local_flags ]
261                          | [ key local_options . space . store no_space ] )
262                         )*
263                       . eol ]
264
265     (* View: email
266          mailonchange has specific syntax
267     *)
268     let email = [ Util.indent . key "mailonchange" . space
269                      . [ label "emailaddress" . store email_addr ]
270                      . space
271                      . [ label "threshold" . store number ]
272                      . eol ]
273
274     (* View: makestep
275          makestep has specific syntax
276     *)
277     let makestep = [ Util.indent . key "makestep"
278                       . space
279                       . [ label "threshold" . store number ]
280                       . space
281                       . [ label "limit" . store integer ]
282                       . eol ]
283
284     (* View: maxchange
285          maxchange has specific syntax
286     *)
287     let maxchange = [ Util.indent . key "maxchange"
288                       . space
289                       . [ label "threshold" . store number ]
290                       . space
291                       . [ label "delay" . store integer ]
292                       . space
293                       . [ label "limit" . store integer ]
294                       . eol ]
295
296     (* View: ratelimit
297          ratelimit/cmdratelimit has specific syntax
298     *)
299     let ratelimit = [ Util.indent . key /(cmd)?ratelimit/
300                       . [ space . key ratelimit_options
301                               . space . store no_space ]*
302                       . eol ]
303     (* View: refclock
304          refclock has specific syntax
305     *)
306     let refclock = [ Util.indent . key "refclock"
307                       . space
308                       . [ label "driver" . store word ]
309                       . space
310                       . [ label "parameter" . store no_space ]
311                       . ( space . ( [ key refclock_flags ]
312                          | [ key refclock_options . space . store no_space ] )
313                         )*
314                       . eol ]
315
316     (* View: smoothtime
317          smoothtime has specific syntax
318     *)
319     let smoothtime = [ Util.indent . key "smoothtime"
320                       . space
321                       . [ label "maxfreq" . store number ]
322                       . space
323                       . [ label "maxwander" . store number ]
324                       . ( space . [ key "leaponly" ] )?
325                       . eol ]
326
327     (* View: tempcomp
328          tempcomp has specific syntax
329     *)
330     let tempcomp = [ Util.indent . key "tempcomp"
331                       . space
332                       . [ label "sensorfile" . store path ]
333                       . space
334                       . [ label "interval" . store number ]
335                       . space
336                       . ( [ label "t0" . store number ] . space
337                               . [ label "k0" . store number ] . space
338                               . [ label "k1" . store number ] . space
339                               . [ label "k2" . store number ]
340                               | [ label "pointfile" . store path ] )
341                       . eol ]
342
343 (************************************************************************
344  * Group: Final lense summary
345  ************************************************************************)
346 (* View: settings
347  *   All supported chrony settings
348  *)
349 let settings = host_list | allowdeny | log_list | bcast | fdrift | istepslew
350              | local | email | makestep | maxchange | refclock | smoothtime
351              | ratelimit | tempcomp | kv | all_flags
352
353 (*
354  * View: lns
355  *   The crony lens
356  *)
357 let lns = ( empty | comment | settings )*
358
359 (* View: filter
360  *   The files parsed by default
361  *)
362 let filter = incl "/etc/chrony.conf"
363
364 let xfm = transform lns filter
365