~ubuntu-branches/debian/lenny/smokeping/lenny

« back to all changes in this revision

Viewing changes to doc/ParseConfig.pm.txt

  • Committer: Bazaar Package Importer
  • Author(s): Niko Tyni
  • Date: 2006-10-26 21:45:56 UTC
  • mfrom: (1.2.2 upstream) (2.1.5 edgy)
  • Revision ID: james.westby@ubuntu.com-20061026214556-5jnpiesx4vdijmu6
* debian/patches/15_clean_makefile.dpatch:
  + remove unneeded and potentially unsecure include paths.
* debian/patches: selected patches from the upstream SVN repository
  + 40_password.dpatch: skip reading the password file when running as a CGI.
  + 50_ldap.dpatch: Make the 'scope' option in the LDAP probe actually work.
  + 60_fping.dpatch:
    * Support the '-S' (set source address, see #198486) fping option.
    * Don't try to execute fping when running as a CGI.
  + 70_syslog.dpatch: Don't die silently if syslogd is unavailable.
    (Closes: #395056)
* Remove all the autogenerated documentation at clean time, to properly
  undo the effects of the 'build' target.
* Install example configuration files for documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
ISG::ParseConfig(3)         SmokePing         ISG::ParseConfig(3)
2
 
 
3
 
 
4
 
 
5
 
SSYYNNOOPPSSIISS
6
 
        use ISG::ParseConfig;
7
 
 
8
 
        my $parser = ISG::ParseConfig->new(\%grammar);
9
 
        my $cfg = $parser->parse('app.cfg') or die "ERROR: $parser->{err}\n";
10
 
        my $pod = $parser->makepod();
11
 
        my $ex = $parser->maketmpl('TOP','SubNode');
12
 
 
13
 
DDEESSCCRRIIPPTTIIOONN
14
 
       ISG::ParseConfig is a module to parse configuration files.
15
 
       The configuration may consist of multiple-level sections
16
 
       with assignments and tabular data. The parsed data will be
17
 
       returned as a hash containing the whole configuration.
18
 
       ISG::ParseConfig uses a grammar that is supplied upon cre-
19
 
       ation of a ISG::ParseConfig object to parse the configura-
20
 
       tion file and return helpful error messages in case of
21
 
       syntax errors. Using the mmaakkeeppoodd methode you can generate
22
 
       documentation of the configuration file format.
23
 
 
24
 
       The mmaakkeettmmppll method can generate a template configuration
25
 
       file.  If your grammar contains regexp matches, the tem-
26
 
       plate will not be all that helpful as ParseConfig is not
27
 
       smart enough to give you sensible template data based in
28
 
       regular expressions.
29
 
 
30
 
       GGrraammmmaarr DDeeffiinniittiioonn
31
 
 
32
 
       The grammar is a multiple-level hash of hashes, which fol-
33
 
       lows the structure of the configuration. Each section or
34
 
       variable is represented by a hash with the same structure.
35
 
       Each hash contains special keys starting with an under-
36
 
       score such as '_sections', '_vars', '_sub' or '_re' to
37
 
       denote meta data with information about that section or
38
 
       variable. Other keys are used to structure the hash
39
 
       according to the same nesting structure of the configura-
40
 
       tion itself. The starting hash given as parameter to 'new'
41
 
       contains the "root section".
42
 
 
43
 
       _S_p_e_c_i_a_l _S_e_c_t_i_o_n _K_e_y_s
44
 
 
45
 
       _sections   Array containing the list of sub-sections of
46
 
                   this section. Each sub-section must then be
47
 
                   represented by a sub-hash in this hash with
48
 
                   the same name of the sub-section.
49
 
 
50
 
                   The sub-section can also be a regular expres-
51
 
                   sion denoted by the syntax '/re/', where re is
52
 
                   the regular-expression. In case a regular
53
 
                   expression is used, a sub-hash named with the
54
 
                   same '/re/' must be included in this hash.
55
 
 
56
 
       _recursive  Array containing the list of those sub-sec-
57
 
                   tions that are _r_e_c_u_r_s_i_v_e, ie.  that can con-
58
 
                   tain a new sub-section with the same syntax as
59
 
                   themselves.
60
 
 
61
 
                   The same effect can be accomplished with cir-
62
 
                   cular references in the grammar tree or a
63
 
                   suitable __ddyynn section subroutine (see below},
64
 
                   so this facility is included just for conve-
65
 
                   nience.
66
 
 
67
 
       _vars       Array containing the list of variables
68
 
                   (assignments) in this section.  Analogous to
69
 
                   sections, regular expressions can be used.
70
 
 
71
 
       _mandatory  Array containing the list of mandatory sec-
72
 
                   tions and variables.
73
 
 
74
 
       _inherited  Array containing the list of the variables
75
 
                   that should be assigned the same value as in
76
 
                   the parent section if nothing is specified
77
 
                   here.
78
 
 
79
 
       _table      Hash containing the table grammar (see Special
80
 
                   Table Keys). If not specified, no table is
81
 
                   allowed in this section. The grammar of the
82
 
                   columns if specified by sub-hashes named with
83
 
                   the column number.
84
 
 
85
 
       _text       Section contains free-form text. Only sections
86
 
                   and @includes statements will be interpreted,
87
 
                   the rest will be added in the returned hash
88
 
                   under '_text' as string.
89
 
 
90
 
                   __tteexxtt is a hash reference which can contain a
91
 
                   __rree and a __rree__eerrrroorr key which will be used to
92
 
                   scrutanize the text ... if the hash is empty,
93
 
                   all text will be accepted.
94
 
 
95
 
       _order      If defined, a '_order' element will be put in
96
 
                   every hash containing the sections with a num-
97
 
                   ber that determines the order in which the
98
 
                   sections were defined.
99
 
 
100
 
       _doc        Describes what this section is about
101
 
 
102
 
       _dyn        A subroutine reference (function pointer) that
103
 
                   will be called when a new section of this syn-
104
 
                   tax is encountered. The subroutine will get
105
 
                   three arguments: the syntax of the section
106
 
                   name (string or regexp), the actual name
107
 
                   encountered (this will be the same as the
108
 
                   first argument for non-regexp sections) and a
109
 
                   reference to the grammar tree of the section.
110
 
                   This subroutine can then modify the grammar
111
 
                   tree dynamically.
112
 
 
113
 
       _S_p_e_c_i_a_l _V_a_r_i_a_b_l_e _K_e_y_s
114
 
 
115
 
       _re         Regular expression upon which the value will
116
 
                   be checked.
117
 
 
118
 
       _re_error   String containing the returned error in case
119
 
                   the regular expression doesn't match (if not
120
 
                   specified, a generic 'syntax error' message
121
 
                   will be returned).
122
 
 
123
 
       _sub        A function pointer. It called for every value,
124
 
                   with the value passed as its first argument.
125
 
                   If the function returns a defined value it is
126
 
                   assumed that the test was not successful and
127
 
                   an error is generated with the returned string
128
 
                   as content.
129
 
 
130
 
       _default    A default value that will be assigned to the
131
 
                   variable if none is specified or inherited.
132
 
 
133
 
       _doc        Describtion of the variable.
134
 
 
135
 
       _example    A one line example for the content of this
136
 
                   variable.
137
 
 
138
 
       _dyn        A subroutine reference (function pointer) that
139
 
                   will be called when the variable is assigned
140
 
                   some value in the config file. The subroutine
141
 
                   will get three arguments: the name of the
142
 
                   variable, the value assigned and a reference
143
 
                   to the grammar tree of this section.  This
144
 
                   subroutine can then modify the grammar tree
145
 
                   dynamically.
146
 
 
147
 
                   Note that no ___d_y_n_(_) call is made for default
148
 
                   and inherited values of the variable.
149
 
 
150
 
       _S_p_e_c_i_a_l _T_a_b_l_e _K_e_y_s
151
 
 
152
 
       _columns    Number of columns. If not specified, it will
153
 
                   not be enforced.
154
 
 
155
 
       _key        If defined, the specified column number will
156
 
                   be used as key in a hash in the returned hash.
157
 
                   If not defined, the returned hash will contain
158
 
                   a '_table' element with the contents of the
159
 
                   table as array. The rows of the tables are
160
 
                   stored as arrays.
161
 
 
162
 
       _sub        they work analog to the description in the
163
 
                   previous section.
164
 
 
165
 
       _doc        describes the content of the column.
166
 
 
167
 
       _example    example for the content of this column
168
 
 
169
 
       _S_p_e_c_i_a_l _T_e_x_t _K_e_y_s
170
 
 
171
 
       _re         Regular expression upon which the text will be
172
 
                   checked (everything as a single line).
173
 
 
174
 
       _re_error   String containing the returned error in case
175
 
                   the regular expression doesn't match (if not
176
 
                   specified, a generic 'syntax error' message
177
 
                   will be returned).
178
 
 
179
 
       _sub        they work analog to the description in the
180
 
                   previous section.
181
 
 
182
 
       _doc        Ditto.
183
 
 
184
 
       _example    Potential multi line example for the content
185
 
                   of this text section
186
 
 
187
 
       CCoonnffiigguurraattiioonn SSyynnttaaxx
188
 
 
189
 
       _G_e_n_e_r_a_l _S_y_n_t_a_x
190
 
 
191
 
       '#' denotes a comment up to the end-of-line, empty lines
192
 
       are allowed and space at the beginning and end of lines is
193
 
       trimmed.
194
 
 
195
 
       '\' at the end of the line marks a continued line on the
196
 
       next line. A single space will be inserted between the
197
 
       concatenated lines.
198
 
 
199
 
       '@include filename' is used to include another file.
200
 
 
201
 
       '@define a some value' will replace all occurences of 'a'
202
 
       in the following text with 'some value'.
203
 
 
204
 
       Fields in tables that contain white space can be enclosed
205
 
       in either "'" or """.  Whitespace can also be escaped with
206
 
       "\". Quotes inside quotes are allowed but must be escaped
207
 
       with a backslash as well.
208
 
 
209
 
       _S_e_c_t_i_o_n_s
210
 
 
211
 
       ISG::ParseConfig supports hierarchical configurations
212
 
       through sections, whose syntax is as follows:
213
 
 
214
 
       Level 1        *** section name ***
215
 
 
216
 
       Level 2        + section name
217
 
 
218
 
       Level 3        ++ section name
219
 
 
220
 
       Level n, n>1   +..+ section name (number of '+' determines
221
 
                      level)
222
 
 
223
 
       _A_s_s_i_g_n_m_e_n_t_s
224
 
 
225
 
       Assignements take the form: 'variable = value', where
226
 
       value can be any string (can contain whitespaces and spe-
227
 
       cial characters). The spaces before and after the equal
228
 
       sign are optional.
229
 
 
230
 
       _T_a_b_u_l_a_r _D_a_t_a
231
 
 
232
 
       The data is interpreted as one or more columns separated
233
 
       by spaces.
234
 
 
235
 
       EExxaammppllee
236
 
 
237
 
       _C_o_d_e
238
 
 
239
 
 
240
 
 
241
 
 
242
 
 
243
 
 
244
 
 
245
 
 
246
 
 
247
 
 
248
 
 
249
 
 
250
 
 
251
 
 
252
 
 
253
 
 
254
 
 
255
 
 
256
 
 
257
 
 
258
 
 
259
 
 
260
 
 
261
 
 
262
 
 
263
 
 
264
 
 
265
 
        my $parser = ISG::ParseConfig->new({
266
 
          _sections => [ 'network', 'hosts' ],
267
 
          network => {
268
 
             _vars     => [ 'dns' ],
269
 
             _sections => [ "/$RE_IP/" ],
270
 
             dns       => {
271
 
                _doc => "address of the dns server",
272
 
                _example => "ns1.oetiker.xs",
273
 
                _re => $RE_HOST,
274
 
                _re_error =>
275
 
                   'dns must be an host name or ip address',
276
 
                },
277
 
             "/$RE_IP/" => {
278
 
                _doc    => "Ip Adress",
279
 
                _example => '10.2.3.2',
280
 
                _vars   => [ 'netmask', 'gateway' ],
281
 
                netmask => {
282
 
                   _doc => "Netmask",
283
 
                   _example => "255.255.255.0",
284
 
                   _re => $RE_IP,
285
 
                   _re_error =>
286
 
                      'netmask must be a dotted ip address'
287
 
                   },
288
 
                gateway => {
289
 
                   _doc => "Default Gateway address in IP notation",
290
 
                   _example => "10.22.12.1",
291
 
                   _re => $RE_IP,
292
 
                   _re_error =>
293
 
                      'gateway must be a dotted ip address' },
294
 
                },
295
 
             },
296
 
          hosts => {
297
 
             _doc => "Details about the hosts",
298
 
             _table  => {
299
 
                 _doc => "Description of all the Hosts",
300
 
                _key => 0,
301
 
                _columns => 3,
302
 
                0 => {
303
 
                   _doc => "Ethernet Address",
304
 
                   _example => "0:3:3:d:a:3:dd:a:cd",
305
 
                   _re => $RE_MAC,
306
 
                   _re_error =>
307
 
                      'first column must be an ethernet mac address',
308
 
                   },
309
 
                1 => {
310
 
                   _doc => "IP Address",
311
 
                   _example => "10.11.23.1",
312
 
                   _re => $RE_IP,
313
 
                   _re_error =>
314
 
                      'second column must be a dotted ip address',
315
 
                   },
316
 
                2 => {
317
 
                   _doc => "Host Name",
318
 
                   _example => "tardis",
319
 
                    },
320
 
                },
321
 
             },
322
 
          });
323
 
 
324
 
        my $cfg = $parser->parse('test.cfg') or
325
 
          die "ERROR: $parser->{err}\n";
326
 
        print Dumper($cfg);
327
 
        print $praser->makepod;
328
 
 
329
 
       _C_o_n_f_i_g_u_r_a_t_i_o_n
330
 
 
331
 
        *** network ***
332
 
 
333
 
          dns      = 129.132.7.87
334
 
 
335
 
        + 129.132.7.64
336
 
 
337
 
          netmask  = 255.255.255.192
338
 
          gateway  = 129.132.7.65
339
 
 
340
 
        *** hosts ***
341
 
 
342
 
          00:50:fe:bc:65:11     129.132.7.97    plain.hades
343
 
          00:50:fe:bc:65:12     129.132.7.98    isg.ee.hades
344
 
          00:50:fe:bc:65:14     129.132.7.99    isg.ee.hades
345
 
 
346
 
       _R_e_s_u_l_t
347
 
 
348
 
        {
349
 
          'hosts' => {
350
 
                       '00:50:fe:bc:65:11' => [
351
 
                                                '00:50:fe:bc:65:11',
352
 
                                                '129.132.7.97',
353
 
                                                'plain.hades'
354
 
                                              ],
355
 
                       '00:50:fe:bc:65:12' => [
356
 
                                                '00:50:fe:bc:65:12',
357
 
                                                '129.132.7.98',
358
 
                                                'isg.ee.hades'
359
 
                                              ],
360
 
                       '00:50:fe:bc:65:14' => [
361
 
                                                '00:50:fe:bc:65:14',
362
 
                                                '129.132.7.99',
363
 
                                                'isg.ee.hades'
364
 
                                              ]
365
 
                     },
366
 
          'network' => {
367
 
                         '129.132.7.64' => {
368
 
                                             'netmask' => '255.255.255.192',
369
 
                                             'gateway' => '129.132.7.65'
370
 
                                           },
371
 
                         'dns' => '129.132.7.87'
372
 
                       }
373
 
        };
374
 
 
375
 
CCOOPPYYRRIIGGHHTT
376
 
       Copyright (c) 2000, 2001 by ETH Zurich. All rights
377
 
       reserved.
378
 
 
379
 
LLIICCEENNSSEE
380
 
       This program is free software; you can redistribute it
381
 
       and/or modify it under the terms of the GNU General Public
382
 
       License as published by the Free Software Foundation;
383
 
       either version 2 of the License, or (at your option) any
384
 
       later version.
385
 
 
386
 
       This program is distributed in the hope that it will be
387
 
       useful, but WITHOUT ANY WARRANTY; without even the implied
388
 
       warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
389
 
       PURPOSE.  See the GNU General Public License for more
390
 
       details.
391
 
 
392
 
       You should have received a copy of the GNU General Public
393
 
       License along with this program; if not, write to the Free
394
 
       Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
395
 
       02139, USA.
396
 
 
397
 
AAUUTTHHOORR
398
 
       David Schweikert <dws@ee.ethz.ch>
399
 
       Tobias Oetiker <oetiker@ee.ethz.ch>
400
 
 
401
 
HHIISSTTOORRYY
402
 
        2001-05-11 ds 1.2 Initial Version for policy 0.3
403
 
        2001-09-04 ds 1.3 Remove space before comments, more strict variable definition
404
 
        2001-09-19 to 1.4 Added _sub error parsing and _doc self documentation
405
 
        2001-10-20 to     Improved Rendering of _doc information
406
 
        2002-01-09 to     Added Documentation to the _text section documentation
407
 
        2002-01-28 to     Fixed quote parsing in tables
408
 
        2002-03-12 ds 1.5 Implemented @define, make makepod return a string and not an array
409
 
        2002-08-28 to     Added maketmpl methode
410
 
        2002-10-10 ds 1.6 More verbatim _text sections
411
 
        2004-02-09 to 1.7 Added _example propperty for pod and template generation
412
 
        2004-08-17 to 1.8 Allow special input files like "program|"
413
 
        2005-01-10 ds 1.9 Implemented _dyn, _default, _recursive, and _inherited (Niko Tyni)
414
 
 
415
 
 
416
 
 
417
 
1.38                        2005-01-10        ISG::ParseConfig(3)