Imported Upstream version 1.11.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 | decimal . /[eE]/ . integer
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 = "asymmetry"
82                     | "key"
83                     | /maxdelay((dev)?ratio)?/
84                     | /(min|max)poll/
85                     | /(min|max)samples/
86                     | "maxsources"
87                     | "mindelay"
88                     | "offset"
89                     | "polltarget"
90                     | "port"
91                     | "presend"
92                     | "version"
93
94     (* Variable: cmd_flags
95          Server/Peer/Pool options without values
96     *)
97     let cmd_flags = "auto_offline"|"iburst"|"noselect"|"offline"|"prefer"
98                   |"require"|"trust"|"xleave"|"burst"
99
100     (* Variable: ntp_source
101          Server/Peer/Pool key names
102     *)
103     let ntp_source = "server"|"peer"|"pool"
104
105     (* Variable: allowdeny_types
106          Key names for access configuration
107     *)
108     let allowdeny_types = "allow"|"deny"|"cmdallow"|"cmddeny"
109
110     (* Variable: hwtimestamp_options
111          HW timestamping options with values
112     *)
113     let hwtimestamp_options = "minpoll"|"precision"|"rxcomp"|"txcomp"
114                             |"rxfilter"
115
116     (* Variable: hwtimestamp_flags
117          HW timestamping options without values
118     *)
119     let hwtimestamp_flags = "nocrossts"
120
121     (* Variable: local_options
122          local options with values
123     *)
124     let local_options = "stratum"|"distance"
125
126     (* Variable: local_flags
127          local options without values
128     *)
129     let local_flags = "orphan"
130
131     (* Variable: ratelimit_options
132          Rate limiting options with values
133     *)
134     let ratelimit_options = "interval"|"burst"|"leak"
135
136     (* Variable: refclock_options
137          refclock options with values
138     *)
139     let refclock_options = "refid"|"lock"|"poll"|"dpoll"|"filter"|"rate"
140                             |"minsamples"|"maxsamples"|"offset"|"delay"
141                             |"precision"|"maxdispersion"|"stratum"|"width"
142
143     (* Variable: refclock_flags
144          refclock options without values
145     *)
146     let refclock_flags = "noselect"|"pps"|"prefer"|"require"|"tai"|"trust"
147
148     (* Variable: flags
149          Options without values
150     *)
151     let flags = "dumponexit"
152               | "generatecommandkey"
153               | "lock_all"
154               | "manual"
155               | "noclientlog"
156               | "rtconutc"
157               | "rtcsync"
158
159     (* Variable: log_flags
160         log has a specific options list
161     *)
162     let log_flags = "measurements"|"rawmeasurements"|"refclocks"|"rtc"
163                   |"statistics"|"tempcomp"|"tracking"
164
165     (* Variable: simple_keys
166          Options with single values
167     *)
168     let simple_keys = "acquisitionport" | "bindacqaddress"
169                     | "bindaddress" | "bindcmdaddress" | "clientloglimit"
170                     | "combinelimit" | "commandkey"
171                     | "cmdport" | "corrtimeratio" | "driftfile"
172                     | "dumpdir" | "hwclockfile" | "include" | "keyfile"
173                     | "leapsecmode" | "leapsectz" | "linux_freq_scale"
174                     | "linux_hz" | "logbanner" | "logchange" | "logdir"
175                     | "maxclockerror" | "maxdistance" | "maxdrift"
176                     | "maxjitter" | "maxsamples" | "maxslewrate"
177                     | "maxupdateskew" | "minsamples" | "minsources"
178                     | "ntpsigndsocket" | "pidfile"
179                     | "port" | "reselectdist" | "rtcautotrim" | "rtcdevice"
180                     | "rtcfile" | "sched_priority" | "stratumweight" | "user"
181
182 (************************************************************************
183  * Group: Make some sub-lenses for use in later lenses
184  ************************************************************************)
185     (* View: host_flags *)
186     let host_flags = [ space . key cmd_flags ]
187     (* View: host_options *)
188     let host_options = [ space . key cmd_options . space . store number ]
189     (* View: log_flag_list *)
190     let log_flag_list = [ space . key log_flags ]
191     (* View: store_address *)
192     let store_address = [ label "address" . store address_re ]
193
194 (************************************************************************
195  * Group: Lenses for parsing out sections
196  ************************************************************************)
197     (* View: all_flags
198         options without any arguments
199     *)
200     let all_flags = [ Util.indent . key flags . eol ]
201
202     (* View: kv
203         options with only one arg can be directly mapped to key = value
204     *)
205     let kv = [ Util.indent . key simple_keys . space . (store no_space) . eol ]
206
207     (* Property: Options with multiple values
208     
209       Each of these gets their own parsing block
210       - server|peer|pool <address> <options>
211       - allow|deny|cmdallow|cmddeny [all] [<address[/subnet]>]
212       - log <options>
213       - broadcast <interval> <address> <optional port>
214       - fallbackdrift <min> <max>
215       - hwtimestamp <interface> <options>
216       - initstepslew <threshold> <addr> <optional extra addrs>
217       - local <options>
218       - mailonchange <emailaddress> <threshold>
219       - makestep <threshold> <limit>
220       - maxchange <threshold> <delay> <limit>
221       - ratelimit|cmdratelimit <options>
222       - refclock <driver> <parameter> <options>
223       - smoothtime <maxfreq> <maxwander> <options>
224       - tempcomp <sensorfile> <interval> (<t0> <k0> <k1> <k2> | <pointfile> )
225     *)
226
227     (* View: host_list
228         Find all NTP sources and their flags/options
229     *)
230     let host_list = [ Util.indent . key ntp_source
231                          . space . store address_re
232                          . ( host_flags | host_options )*
233                          . eol ]
234
235     (* View: allowdeny
236         allow/deny/cmdallow/cmddeny has a specific syntax
237     *)
238     let allowdeny = [ Util.indent . key allowdeny_types
239                         . [ space . key "all" ]?
240                         . ( space . store ( no_space - "all" ) )?
241                         . eol ]
242
243     (* View: log_list
244         log has a specific options list
245     *)
246     let log_list = [ Util.indent . key "log" . log_flag_list+ . eol ]
247
248     (* View: bcast
249          broadcast has specific syntax
250     *)
251     let bcast = [ Util.indent . key "broadcast"
252                       . space . [ label "interval" . store integer ]
253                       . space . store_address
254                       . ( space . [ label "port" . store integer ] )?
255                       . eol ]
256
257     (* View: fdrift
258          fallbackdrift has specific syntax
259     *)
260     let fdrift = [ Util.indent . key "fallbackdrift"
261                       . space . [ label "min" . store integer ]
262                       . space . [ label "max" . store integer ]
263                       . eol ]
264
265     (* View: hwtimestamp
266          hwtimestamp has specific syntax
267     *)
268     let hwtimestamp = [ Util.indent . key "hwtimestamp"
269                       . space . [ label "interface" . store no_space ]
270                       . ( space . ( [ key hwtimestamp_flags ]
271                          | [ key hwtimestamp_options . space
272                              . store no_space ] )
273                         )*
274                       . eol ]
275     (* View: istepslew
276          initstepslew has specific syntax
277     *)
278     let istepslew = [ Util.indent . key "initstepslew" 
279                          . space . [ label "threshold" . store number ]
280                          . ( space . store_address )+
281                          . eol ]
282
283     (* View: local
284          local has specific syntax
285     *)
286     let local = [ Util.indent . key "local"
287                       . ( space . ( [ key local_flags ]
288                          | [ key local_options . space . store no_space ] )
289                         )*
290                       . eol ]
291
292     (* View: email
293          mailonchange has specific syntax
294     *)
295     let email = [ Util.indent . key "mailonchange" . space
296                      . [ label "emailaddress" . store email_addr ]
297                      . space
298                      . [ label "threshold" . store number ]
299                      . eol ]
300
301     (* View: makestep
302          makestep has specific syntax
303     *)
304     let makestep = [ Util.indent . key "makestep"
305                       . space
306                       . [ label "threshold" . store number ]
307                       . space
308                       . [ label "limit" . store integer ]
309                       . eol ]
310
311     (* View: maxchange
312          maxchange has specific syntax
313     *)
314     let maxchange = [ Util.indent . key "maxchange"
315                       . space
316                       . [ label "threshold" . store number ]
317                       . space
318                       . [ label "delay" . store integer ]
319                       . space
320                       . [ label "limit" . store integer ]
321                       . eol ]
322
323     (* View: ratelimit
324          ratelimit/cmdratelimit has specific syntax
325     *)
326     let ratelimit = [ Util.indent . key /(cmd)?ratelimit/
327                       . [ space . key ratelimit_options
328                               . space . store no_space ]*
329                       . eol ]
330     (* View: refclock
331          refclock has specific syntax
332     *)
333     let refclock = [ Util.indent . key "refclock"
334                       . space
335                       . [ label "driver" . store word ]
336                       . space
337                       . [ label "parameter" . store no_space ]
338                       . ( space . ( [ key refclock_flags ]
339                          | [ key refclock_options . space . store no_space ] )
340                         )*
341                       . eol ]
342
343     (* View: smoothtime
344          smoothtime has specific syntax
345     *)
346     let smoothtime = [ Util.indent . key "smoothtime"
347                       . space
348                       . [ label "maxfreq" . store number ]
349                       . space
350                       . [ label "maxwander" . store number ]
351                       . ( space . [ key "leaponly" ] )?
352                       . eol ]
353
354     (* View: tempcomp
355          tempcomp has specific syntax
356     *)
357     let tempcomp = [ Util.indent . key "tempcomp"
358                       . space
359                       . [ label "sensorfile" . store path ]
360                       . space
361                       . [ label "interval" . store number ]
362                       . space
363                       . ( [ label "t0" . store number ] . space
364                               . [ label "k0" . store number ] . space
365                               . [ label "k1" . store number ] . space
366                               . [ label "k2" . store number ]
367                               | [ label "pointfile" . store path ] )
368                       . eol ]
369
370 (************************************************************************
371  * Group: Final lense summary
372  ************************************************************************)
373 (* View: settings
374  *   All supported chrony settings
375  *)
376 let settings = host_list | allowdeny | log_list | bcast | fdrift | istepslew
377              | local | email | makestep | maxchange | refclock | smoothtime
378              | hwtimestamp | ratelimit | tempcomp | kv | all_flags
379
380 (*
381  * View: lns
382  *   The crony lens
383  *)
384 let lns = ( empty | comment | settings )*
385
386 (* View: filter
387  *   The files parsed by default
388  *)
389 let filter = incl "/etc/chrony.conf"
390
391 let xfm = transform lns filter
392