Code

M4 requirement for developer platform
[nagiosplug.git] / doc / developer-guidelines.sgml
1 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V4.1//EN" >
2 <book>
3   <title>Nagios Plug-in Developer Guidelines</title>
5   <bookinfo>
6     <authorgroup>
7       <author>
8         <affiliation>
9           <orgname>Nagios Plugins Development Team</orgname>
10         </affiliation>
11       </author>
12     </authorgroup>
14     <pubdate>2006</pubdate>
15     <title>Nagios plug-in development guidelines</title>
16         
17     <revhistory>
18        <revision>
19           <revnumber>$Revision$</revnumber>
20           <date>$Date$</date>
21        </revision>
22     </revhistory>
24         <copyright>
25                 <year>2000 - 2006</year> 
26                 <holder>Nagios Plugins Development Team</holder>
27         </copyright>
29 </bookinfo>
32 <preface id="preface"><title>Preface</title>
33     <para>The purpose of this guidelines is to provide a reference for
34     the plug-in developers and encourage the standarization of the
35     different kind of plug-ins: C, shell, perl, python, etc.</para>
37         <para>Nagios Plug-in Development Guidelines Copyright (C) 2000-2006
38         (Nagios Plugins Team)</para>
40         <para>Permission is granted to make and distribute verbatim
41         copies of this manual provided the copyright notice and this
42         permission notice are preserved on all copies.</para>
44         <para>The plugins themselves are copyrighted by their respective
45         authors.</para>
46 </preface>
48 <article>
49 <section id="DevRequirements"><title>Development platform requirements</title>
50         <para>
51         Nagios plugins are developed to the GNU standard, so any OS which is supported by GNU
52         should run the plugins. While the requirements for compiling the Nagios plugins release 
53         is very small, to develop from CVS needs additional software to be installed. These are the 
54         minimum levels of software required:
56         <literallayout>
57         gnu make 3.79
58         automake 1.9.2
59         autoconf 2.58
60         gnu m4 1.4.2
61         </literallayout>
63         To compile from CVS, after you have checked out the code, run:
64         <literallayout>
65         tools/setup
66         ./configure
67         make
68         make install
69         </literallayout>
70         </para>
72         <para>Note: gettext is no longer a developer platform requirement. A lot of the files in lib/ and m4/
73         are synced with the coreutils project and we use the same levels of gettext that they
74         distribute.
75         </para>
76         <para>Note: gnu libtool, which must be at version 1.5.22 or above, has files installed into CVS, so is not 
77         a development platform requirement.
78         </para>
79 </section>
81 <section id="PlugOutput"><title>Plugin Output for Nagios</title>
82         
83                 <para>You should always print something to STDOUT that tells if the 
84                 service is working or why it is failing. Try to keep the output short - 
85                 probably less that 80 characters. Remember that you ideally would like 
86                 the entire output to appear in a pager message, which will get chopped
87                 off after a certain length.</para>
89                 <section><title>Print only one line of text</title>
90                 <para>Nagios will only grab the first line of text from STDOUT
91                 when it notifies contacts about potential problems. If you print
92                 multiple lines, you're out of luck. Remember, keep it short and
93                 to the point.</para>
95                 <para>Output should be in the format:</para>
96                 <literallayout>
97                 SERVICE STATUS: Information text
98                 </literallayout>
99                 <para>However, note that this is not a requirement of the API, so you cannot depend on this
100                 being an accurate reflection of the status of the service - the status should always 
101                 be determined by the return code.</para>
102                 </section>
104                 <section><title>Verbose output</title>
105                 <para>Use the -v flag for verbose output. You should allow multiple
106                 -v options for additional verbosity, up to a maximum of 3. The standard
107                 type of output should be:</para>
109                 <table id="verboselevels"><title>Verbose output levels</title>
110                         <tgroup cols="2">
111                                 <thead>
112                                         <row>
113                                                 <entry><para>Verbosity level</para></entry>
114                                                 <entry><para>Type of output</para></entry>
115                                         </row>
116                                 </thead>
117                                 <tbody>
118                                         <row>
119                                                 <entry align="center"><para>0</para></entry>
120                                                 <entry><para>Single line, minimal output. Summary</para></entry>
121                                         </row>
122                                         <row>
123                                                 <entry align="center"><para>1</para></entry>
124                                                 <entry><para>Single line, additional information (eg list processes that fail)</para></entry>
125                                         </row>
126                                         <row>
127                                                 <entry align="center"><para>2</para></entry>
128                                                 <entry><para>Multi line, configuration debug output (eg ps command used)</para></entry>
129                                         </row>
130                                         <row>
131                                                 <entry align="center"><para>3</para></entry>
132                                                 <entry><para>Lots of detail for plugin problem diagnosis</para></entry>
133                                         </row>
134                                 </tbody>
135                         </tgroup>
136                 </table>
137                 </section>
139                 <section><title>Screen Output</title>
140                 <para>The plug-in should print the diagnostic and just the
141                 synopsis part of the help message.  A well written plugin would
142                 then have --help as a way to get the verbose help.</para>
143                 <para>Code and output should try to respect the 80x25 size of a
144                 crt (remember when fixing stuff in the server room!)</para>
145                 </section>
146                 
147                 <section><title>Plugin Return Codes</title>
148                 <para>The return codes below are based on the POSIX spec of returning
149                 a positive value.  Netsaint prior to v0.0.7 supported non-POSIX
150                 compliant return code of "-1" for unknown.  Nagios supports POSIX return
151                 codes by default.</para>
153                 <para>Note: Some plugins will on occasion print on STDOUT that an error
154                 occurred and error code is 138 or 255 or some such number.  These
155                 are usually caused by plugins using system commands and having not 
156                 enough checks to catch unexpected output.  Developers should include a
157                 default catch-all for system command output that returns an UNKNOWN
158                 return code.</para>
159                 
160                 <table id="ReturnCodes"><title>Plugin Return Codes</title>
161                         <tgroup cols="3">
162                                 <thead>
163                                         <row>
164                                                 <entry><para>Numeric Value</para></entry>
165                                                 <entry><para>Service Status</para></entry>
166                                                 <entry><para>Status Description</para></entry>
167                                         </row>
168                                 </thead>
169                                 <tbody>
170                                         <row>
171                                                 <entry align="center"><para>0</para></entry>
172                                                 <entry valign="middle"><para>OK</para></entry>
173                                                 <entry><para>The plugin was able to check the service and it 
174                                                 appeared to be functioning properly</para></entry>
175                                         </row>
176                                         <row>
177                                                 <entry align="center"><para>1</para></entry>
178                                                 <entry valign="middle"><para>Warning</para></entry>
179                                                 <entry><para>The plugin was able to check the service, but it 
180                                                 appeared to be above some "warning" threshold or did not appear 
181                                                 to be working properly</para></entry>
182                                         </row>
183                                         <row>
184                                                 <entry align="center"><para>2</para></entry>
185                                                 <entry valign="middle"><para>Critical</para></entry>
186                                                 <entry><para>The plugin detected that either the service was not 
187                                                 running or it was above some "critical" threshold</para></entry>
188                                         </row>
189                                         <row>
190                                                 <entry align="center"><para>3</para></entry>
191                                                 <entry valign="middle"><para>Unknown</para></entry>
192                                                 <entry><para>Invalid command line arguments were supplied to the 
193                                                 plugin or low-level failures internal to the plugin (such as unable to fork,
194                                                 or open a tcp socket) that prevent it from performing the specified
195                                                 operation. Higher-level errors (such as name resolution errors,
196                                                 socket timeouts, etc) are outside of the control of plugins and should
197                                                 generally NOT be reported as UNKNOWN states.
198                                                 </para></entry>
199                                         </row>
200                                 </tbody>
201                         </tgroup>
202                 </table>
204       
205                 </section>
207                 <section id="thresholdformat"><title>Threshold and ranges</title>
208                 <para>A range is defined as a start and end point (inclusive) on a numeric scale (possibly
209                 negative or positive infinity).
210                 </para>
211                 <para>A threshold is a range with an alert level (either warning or critical). Use the
212                 set_thresholds(thresholds *, char *, char *) function to set the thresholds.
213                 </para>
214                 <para>The theory is that the plugin will do some sort of check which returns
215                 back a numerical value, or metric, which is then compared to the warning and 
216                 critical thresholds. Use the get_status(double, thresholds *) function to
217                 compare the value against the thresholds.</para>
218                 <para>This is the generalised format for ranges:</para>
220                 <literallayout>
221                 [@]start:end
222                 </literallayout>
223         
224                 <para>Notes:</para>
225                 <orderedlist>
226                 <listitem><para>start &le; end</para>
227                         </listitem>
228                 <listitem><para>start and ":" is not required if start=0</para>
229                         </listitem>
230                 <listitem><para>if range is of format "start:" and end is not specified, 
231                         assume end is infinity</para>
232                         </listitem>
233                 <listitem><para>to specify negative infinity, use "~"</para>
234                         </listitem>
235                 <listitem><para>alert is raised if metric is outside start and end range
236                         (inclusive of endpoints)</para>
237                         </listitem>
238                 <listitem><para>if range starts with "@", then alert if inside this range
239                         (inclusive of endpoints)</para>
240                         </listitem>
241                 </orderedlist>
242                 
243                 <para>Note: Not all plugins are coded to expect ranges in this format yet.
244                 There will be some work in providing multiple metrics.</para>
246                 <table id="ExampleRanges"><title>Example ranges</title>
247                         <tgroup cols="2">
248                                 <thead>
249                                         <row>
250                                                 <entry><para>Range definition</para></entry>
251                                                 <entry><para>Generate an alert if x...</para></entry>
252                                         </row>
253                                 </thead>
254                                 <tbody>
255                                         <row>
256                                                 <entry>10</entry>
257                                                 <entry>&lt; 0 or &gt; 10, (outside the range of {0 .. 10})</entry>
258                                         </row>
259                                         <row>
260                                                 <entry>10:</entry>
261                                                 <entry>&lt; 10, (outside {10 .. &infin;})</entry>
262                                         </row>
263                                         <row>
264                                                 <entry>~:10</entry>
265                                                 <entry>&gt; 10, (outside the range of {-&infin; .. 10})</entry>
266                                         </row>
267                                         <row>
268                                                 <entry>10:20</entry>
269                                                 <entry>&lt; 10 or &gt; 20, (outside the range of {10 .. 20})</entry>
270                                         </row>
271                                         <row>
272                                                 <entry>@10:20</entry>
273                                                 <entry>&ge; 10 and &le; 20, (inside the range of {10 .. 20})</entry>
274                                         </row>
275                                         <row>
276                                                 <entry>10</entry>
277                                                 <entry>&lt; 0 or &gt; 10, (outside the range of {0 .. 10})</entry>
278                                         </row>
279                                 </tbody>
280                         </tgroup>
281                 </table>
282                 <table id="CommandLineExamples"><title>Command line examples</title>
283                         <tgroup cols="2">
284                                 <thead>
285                                         <row>
286                                                 <entry><para>Command line</para></entry>
287                                                 <entry><para>Meaning</para></entry>
288                                         </row>
289                                 </thead>
290                                 <tbody>
291                                         <row>
292                                                 <entry>check_stuff -w10 -c20</entry>
293                                                 <entry>Critical if "stuff" is over 20, else warn if over 10 (will be critical if "stuff" is less than 0)</entry>
294                                         </row>
295                                         <row>
296                                                 <entry>check_stuff -w~:10 -c~:20</entry>
297                                                 <entry>Same as above. Negative "stuff" is OK</entry>
298                                         </row>
299                                         <row>
300                                                 <entry>check_stuff -w10: -c20</entry>
301                                                 <entry>Critical if "stuff" is over 20, else warn if "stuff" is below 10 (will be critical if "stuff" is less than 0)</entry>
302                                         </row>
303                                         <row>
304                                                 <entry>check_stuff -c1:</entry>
305                                                 <entry>Critical if "stuff" is less than 1</entry>
306                                         </row>
307                                         <row>
308                                                 <entry>check_stuff -w~:0 -c10</entry>
309                                                 <entry>Critical if "stuff" is above 10; Warn if "stuff" is above zero</entry>
310                                         </row>
311                                         <row>
312                                                 <entry>check_stuff -c5:6</entry>
313                                                 <entry>The only noncritical range is 5:6</entry>
314                                         </row>
315                                         <row>
316                                                 <entry>check_stuff -c10:20</entry>
317                                                 <entry>Critical if "stuff" is 10 to 20</entry>
318                                         </row>
319                                 </tbody>
320                         </tgroup>
321                 </table>
322                 </section>
324                 <section><title>Performance data</title>
325                 <para>Performance data is defined by Nagios as "everything after the | of the plugin output" -
326                 please refer to Nagios documentation for information on capturing this data to logfiles.
327                 However, it is the responsibility of the plugin writer to ensure the 
328                 performance data is in a "Nagios plugins" format.
329                 This is the expected format:</para>
331                 <literallayout>
332                 'label'=value[UOM];[warn];[crit];[min];[max]
333                 </literallayout>
335                 <para>Notes:</para>
336                 <orderedlist>
337                 <listitem><para>space separated list of label/value pairs</para>
338                         </listitem>
339                 <listitem><para>label can contain any characters</para>
340                         </listitem>
341                 <listitem><para>the single quotes for the label are optional. Required if 
342                         spaces, = or ' are in the label</para>
343                         </listitem>
344                 <listitem><para>label length is arbitrary, but ideally the first 19 characters
345                         are unique (due to a limitation in RRD). Be aware of a limitation in the
346                         amount of data that NRPE returns to Nagios</para>
347                         </listitem>
348                 <listitem><para>to specify a quote character, use two single quotes</para>
349                         </listitem>
350                 <listitem><para>warn, crit, min or max may be null (for example, if the threshold is 
351                         not defined or min and max do not apply). Trailing unfilled semicolons can be
352                         dropped</para>
353                         </listitem>
354                 <listitem><para>min and max are not required if UOM=%</para>
355                         </listitem>
356                 <listitem><para>value, min and max in class [-0-9.]. Must all be the
357                         same UOM</para>
358                         </listitem>
359                 <listitem><para>warn and crit are in the range format (see 
360                         <xref linkend="thresholdformat">). Must be the same UOM</para>
361                         </listitem>
362                 <listitem><para>UOM (unit of measurement) is one of:</para>
363                         <orderedlist>
364                         <listitem><para>no unit specified - assume a number (int or float) 
365                                 of things (eg, users, processes, load averages)</para>
366                                 </listitem>
367                         <listitem><para>s - seconds (also us, ms)</para></listitem>
368                         <listitem><para>% - percentage</para></listitem>
369                         <listitem><para>B - bytes (also KB, MB, TB)</para></listitem>
370                         <listitem><para>c - a continous counter (such as bytes
371                                 transmitted on an interface)</para></listitem>
372                         </orderedlist>
373                         </listitem>
374                 </orderedlist>
376                 <para>It is up to third party programs to convert the Nagios plugins 
377                 performance data into graphs.</para>
378                 </section>
380         <section><title>Translations</title>
381         <para>If possible, use translation tools for all output to respect the user's language 
382                 settings. See <xref linkend="translationsdevelopers"> for guidelines 
383                 for the core plugins. 
384         </para>
385         </section>
386 </section>
388 <section id="SysCmdAuxFiles"><title>System Commands and Auxiliary Files</title>
390                 <section><title>Don't execute system commands without specifying their
391                 full path</title>
392                 <para>Don't use exec(), popen(), etc. to execute external
393                 commands without explicity using the full path of the external
394                 program.</para>
396                 <para>Doing otherwise makes the plugin vulnerable to hijacking
397                 by a trojan horse earlier in the search path. See the main
398                 plugin distribution for examples on how this is done.</para>
399                 </section>
401                 <section><title>Use spopen() if external commands must be executed</title>
403             <para>If you have to execute external commands from within your
404         plugin and you're writing it in C, use the spopen() function
405                 that Karl DeBisschop has written.</para>
407                 <para>The code for spopen() and spclose() is included with the
408                 core plugin distribution.</para>
409                 </section>
411                 <section><title>Don't make temp files unless absolutely required</title>
413                 <para>If temp files are needed, make sure that the plugin will
414                 fail cleanly if the file can't be written (e.g., too few file
415                 handles, out of disk space, incorrect permissions, etc.) and
416                 delete the temp file when processing is complete.</para>
417                 </section>
419         <section><title>Don't be tricked into following symlinks</title>
421                 <para>If your plugin opens any files, take steps to ensure that
422                 you are not following a symlink to another location on the
423                 system.</para>
424                 </section>
426                 <section><title>Validate all input</title>
428                 <para>use routines in utils.c or utils.pm and write more as needed</para>
429                 </section>
431 </section>
432         
436 <section id="PerlPlugin"><title>Perl Plugins</title>
438                 <para>Perl plugins are coded a little more defensively than other
439                 plugins because of embedded Perl.  When configured as such, embedded
440                 Perl Nagios (ePN) requires stricter use of the some of Perl's features.
441                 This section outlines some of the steps needed to use ePN
442                 effectively.</para>
443           
444                 <orderedlist>
445                         
446                         <listitem><para> Do not use BEGIN and END blocks since they will be called 
447                         only once (when Nagios starts and shuts down) with Embedded Perl (ePN).  In 
448                         particular, do not use BEGIN blocks to initialize variables.</para>
449                         </listitem>
450           
451                         <listitem><para>To use utils.pm, you need to provide a full path to the
452                         module in order for it to work.</para>
453                         
454           <literallayout>
455           e.g.
456                 use lib "/usr/local/nagios/libexec";
457                 use utils qw(...);
458           </literallayout>
459                         </listitem>
461                         <listitem><para>Perl scripts should be called with "-w"</para>
462                         </listitem>
463                         
464                         <listitem><para>All Perl plugins must compile cleanly under "use strict" - i.e. at
465                         least explicitly package names as in "$main::x" or predeclare every
466                         variable. </para>
467                         
469                         <para>Explicitly initialize each variable in use.  Otherwise with
470                         caching enabled, the plugin will not be recompiled each time, and
471                         therefore Perl will not reinitialize all the variables.  All old
472                         variable values will still be in effect.</para>
473                         </listitem>
474                         
475                         <listitem><para>Do not use &gt;DATA&lt; handles (these simply do not compile under ePN).</para>
476                         </listitem>
478                         <listitem><para>Do not use global variables in named subroutines. This is bad practise anyway, but with ePN the
479                         compiler will report an error "&lt;global_var&gt; will not stay shared ..". Values used by
480                         subroutines should be passed in the argument list.</para> 
481                         </listitem>
483                         <listitem><para>If writing to a file (perhaps recording
484                         performance data) explicitly close close it.  The plugin never
485                         calls <emphasis role="strong">exit</emphasis>; that is caught by
486                         p1.pl, so output streams are never closed.</para>
487                         </listitem>
488                 
489                         <listitem><para>As in <xref linkend="runtime"> all plugins need 
490                         to monitor their runtime, specially if they are using network
491                         resources.  Use of the <emphasis>alarm</emphasis> is recommended
492                         noting that some Perl modules (eg LWP) manage timers, so that an alarm
493                         set by a plugin using such a module is overwritten by the module.
494                         (workarounds are cunning (TM) or using the module timer)
495                         Plugins may import a default time out ($TIMEOUT) from utils.pm.
496                         </para>
497                         </listitem>
499                         <listitem><para>Perl plugins should import %ERRORS from utils.pm
500                         and then "exit $ERRORS{'OK'}" rather than "exit 0"
501                         </para>
502                         </listitem>
503                         
504                 </orderedlist>
505           
506 </section>
508 <section id="runtime"><title>Runtime Timeouts</title>
510                 <para>Plugins have a very limited runtime - typically 10 sec.
511                 As a result, it is very important for plugins to maintain internal
512                 code to exit if runtime exceeds a threshold. </para>
514                 <para>All plugins should timeout gracefully, not just networking
515                 plugins. For instance, df may lock if you have automounted
516                 drives and your network fails - but on first glance, who'd think
517                 df could lock up like that.  Plus, it should just be more error
518                 resistant to be able to time out rather than consume
519                 resources.</para>
520                 
521                 <section><title>Use DEFAULT_SOCKET_TIMEOUT</title>
523                 <para>All network plugins should use DEFAULT_SOCKET_TIMEOUT to timeout</para>
525                 </section>
527                 
528                 <section><title>Add alarms to network plugins</title>
530                 <para>If you write a plugin which communicates with another
531                 networked host, you should make sure to set an alarm() in your
532                 code that prevents the plugin from hanging due to abnormal
533                 socket closures, etc. Nagios takes steps to protect itself
534                 against unruly plugins that timeout, but any plugins you create
535                 should be well behaved on their own.</para>
537                 </section>
539                 
541 </section>
543 <section id="PlugOptions"><title>Plugin Options</title>
544         
545                 <para>A well written plugin should have --help as a way to get 
546                 verbose help. Code and output should try to respect the 80x25 size of a
547                 crt (remember when fixing stuff in the server room!)</para>
548                 
549                 <section><title>Option Processing</title>
551                 <para>For plugins written in C, we recommend the C standard
552                 getopt library for short options. Getopt_long is always available.
553                 </para>
555                 <para>For plugins written in Perl, we recommend Getopt::Long module.</para>
557                 <para>Positional arguments are strongly discouraged.</para>
559                 <para>There are a few reserved options that should not be used
560                 for other purposes:</para>
562                 <literallayout>
563           -V version (--version)
564           -h help (--help)
565           -t timeout (--timeout)
566           -w warning threshold (--warning)
567           -c critical threshold (--critical)
568           -H hostname (--hostname)
569           -v verbose (--verbose)
570                 </literallayout>
572                 <para>In addition to the reserved options above, some other standard options are:</para>
574                 <literallayout>
575           -C SNMP community (--community)
576           -a authentication password (--authentication)
577           -l login name (--logname)
578           -p port or password (--port or --passwd/--password)monitors operational
579           -u url or username (--url or --username)
580                 </literallayout>
581           
582                 <para>Look at check_pgsql and check_procs to see how I currently
583                 think this can work.  Standard options are:</para>
585           
586                 <para>The option -V or --version should be present in all
587                 plugins. For C plugins it should result in a call to print_revision, a
588                 function in utils.c which takes two character arguments, the
589                 command name and the plugin revision.</para>
591                 <para>The -? option, or any other unparsable set of options,
592                 should print out a short usage statement. Character width should
593                 be 80 and less and no more that 23 lines should be printed (it
594                 should display cleanly on a dumb terminal in a server
595                 room).</para>
597                 <para>The option -h or --help should be present in all plugins.
598                 In C plugins, it should result in a call to print_help (or
599                 equivalent).  The function print_help should call print_revision, 
600                 then print_usage, then should provide detailed
601                 help. Help text should fit on an 80-character width display, but
602                 may run as many lines as needed.</para>
604                 <para>The option -v or --verbose should be present in all plugins.
605                 The user should be allowed to specify -v multiple times to increase
606                 the verbosity level, as described in <xref linkend="verboselevels">.</para>
607     </section>
609     <section>
610       <title>Plugins with more than one type of threshold, or with
611       threshold ranges</title>
613       <para>Old style was to do things like -ct for critical time and
614       -cv for critical value. That goes out the window with POSIX
615       getopt. The allowable alternatives are:</para>
617       <orderedlist>
618         <listitem>
619           <para>long options like -critical-time (or -ct and -cv, I
620           suppose).</para>
621         </listitem>
623         <listitem>
624           <para>repeated options like `check_load -w 10 -w 6 -w 4 -c
625           16 -c 10 -c 10`</para>
626         </listitem>
628         <listitem>
629           <para>for brevity, the above can be expressed as `check_load
630           -w 10,6,4 -c 16,10,10`</para>
631         </listitem>
633         <listitem>
634           <para>ranges are expressed with colons as in `check_procs -C
635           httpd -w 1:20 -c 1:30` which will warn above 20 instances,
636           and critical at 0 and above 30</para>
637         </listitem>
639         <listitem>
640           <para>lists are expressed with commas, so Jacob's check_nmap
641           uses constructs like '-p 1000,1010,1050:1060,2000'</para>
642         </listitem>
644         <listitem>
645           <para>If possible when writing lists, use tokens to make the
646           list easy to remember and non-order dependent - so
647           check_disk uses '-c 10000,10%' so that it is clear which is
648           the precentage and which is the KB values (note that due to
649           my own lack of foresight, that used to be '-c 10000:10%' but
650           such constructs should all be changed for consistency,
651           though providing reverse compatibility is fairly
652           easy).</para>
653         </listitem>
655       </orderedlist>
657       <para>As always, comments are welcome - making this consistent
658       without a host of long options was quite a hassle, and I would
659       suspect that there are flaws in this strategy. 
660       </para>
661     </section>
662 </section>
664 <section id="Testcases"><title>Test cases</title>
665 <para>
666 Tests are the best way of knowing if the plugins work as expected. Please
667 create and update test cases where possible.
668 </para>
670 <para>
671 To run a test, from the top level directory, run "make test". This will run 
672 all the current tests and report an overall success rate.
673 </para>
675 <para>
676 See the <ulink url="http://tinderbox.altinity.org">Nagios Plugins Tinderbox server</ulink>
677 for the daily test results.
678 </para>
680 <section><title>Test cases for plugins</title>
681 <para>These use perl's Test::More. To do a one time test, run "cd plugins && perl t/check_disk.t".
682 </para>
684 <para>There will somtimes be failures seen in this output which are known failures that
685 need to be fixed. As long as the return code is 0, it will be reported as "test pass".
686 (If you have a fix so that the specific test passes, that will be gratefully received!)
687 </para>
689 <para>
690 If you want a summary test, run: "cd plugins && prove t/check_disk.t".
691 This runs the test in a summary format.
692 </para>
694 <para>
695 For a good and amusing tutorial on using Test::More, see this 
696 <ulink url="http://search.cpan.org/~mschwern/Test-Simple-0.62/lib/Test/Tutorial.pod">
697 link</ulink>
698 </para>
700 </section>
702 <section><title>Testing the C library functions</title>
703 <para>
704 We use <ulink url="http://jc.ngo.org.uk/trac-bin/trac.cgi/wiki/LibTap">the libtap library</ulink>, which gives 
705 perl's TAP
706 (Test Anything Protocol) output. This is used by the FreeBSD team for their regression testing.
707 </para>
709 <para>
710 To run tests using the libtap library, download the latest tar ball and extract. 
711 There is a problem with tap-1.01 where 
712 <ulink url="http://jc.ngo.org.uk/trac-bin/trac.cgi/ticket/25">pthread support doesn't appear to work</ulink>
713 properly on non-FreeBSD systems. Install with 'CPPFLAGS="-UHAVE_LIBPTHREAD" ./configure && make && make check && make install'. 
714 </para>
716 <para>
717 When you run Nagios Plugins' configure, it will look for the tap library and will automatically
718 setup the tests. Run "make test" to run all the tests.
719 </para>
720 </section>
722 </section>
723 <section id="CodingGuidelines"><title>Coding guidelines</title>
724         <para>See <ulink url="http://www.gnu.org/prep/standards_toc.html">GNU
725         Coding standards</ulink> for general guidelines.</para>
726         <section><title>C coding</title>
727         
728         <para>Variables should be declared at the beginning of code blocks and 
729         not inline because of portability with older compilers.</para>
731         <para>You should use /* */ for comments and not // as some compilers
732         do not handle the latter form.</para>
733         </section>
735         <section><title>Crediting sources</title>
736         <para>If you have copied a routine from another source, make sure the licence
737         from your source allows this. Add a comment referencing the ACKNOWLEDGEMENTS
738         file, where you can put more detail about the source.</para>
739         <para>For contributed code, do not add any named credits in the source code 
740         - contributors should be added into the THANKS.in file instead. 
741         </para>
742         </section>
744         <section><title>CVS comments</title>
745         <para>When adding CVS comments at commit time, you can use the following prefixes:
746         <variablelist>
747           <varlistentry><term>- comment</term>
748           <listitem>
749             <para>for a comment that can be removed from the Changelog</para>
750           </listitem>
751           </varlistentry>
752           <varlistentry><term>* comment</term>
753           <listitem>
754             <para>for an important amendment to be included into a features list</para>
755           </listitem>
756           </varlistentry>
757         </variablelist>
758         </para>
759         <para>If the change is due to a contribution, please quote the contributor's name 
760         and, if applicable, add the SourceForge Tracker number. Don't forget to 
761 update the THANKS.in file.</para>
762         </section>
764         <section id="translationsdevelopers"><title>Translations for developers</title>
765         <para>To make the job easier for translators, please follow these guidelines:</para>
766         <orderedlist>
767           <listitem><para>
768             Before creating new strings, check the po/nagios-plugins.pot file to 
769             see if a similar string
770             already exists
771           </para></listitem>
772           <listitem><para>
773             For help texts, break into individual options so that these can be reused
774             between plugins
775           </para></listitem>
776           <listitem><para>Try to avoid linefeeds unless you are working on a block of text</para></listitem>
777           <listitem><para>Short help is not translated</para></listitem>
778           <listitem><para>Long help has options in English language, but text translated</para></listitem>
779           <listitem><para>"Copyright" kept in English</para></listitem>
780           <listitem><para>Copyright holder names kept in original text</para></listitem>
781           <listitem><para>Debugging output does not need to be translated</para></listitem>
782         </orderedlist>
783         </section>
785         <section><title>Translations for translators</title>
786         <para>To create an up to date list of translatable strings, run: tools/gen_locale.sh</para>
787         </section>
789 </section>
791 <section id="SubmittingChanges"><title>Submission of new plugins and patches</title>
793         <section id="Patches"><title>Patches</title>
794         <para>If you have a bug patch, please supply a unified or context diff against the
795         version you are using. For new features, please supply a diff against
796         the CVS HEAD version.</para>
798         <para>Patches should be submitted via 
799         <ulink url="http://sourceforge.net/tracker/?group_id=29880&amp;atid=397599">SourceForge's
800         tracker system for Nagiosplug patches</ulink> 
801         and be announced to the nagiosplug-devel mailing list.</para>
803         <para>Submission of a patch implies that the submmitter acknowledges that they
804         are the author of the code (or have permission from the author to release the code)
805         and agree that the code can be released under the GPL. The copyright for the changes will 
806         then revert to the Nagios Plugin Development Team - this is required so that any copyright 
807         infringements can be investigated quickly without contacting a huge list of copyright holders.
808         Credit will always be given for any patches through a THANKS file in the distribution.</para>
809         </section>
811         <section id="Newplugins"><title>New plugins</title>
813         <para>If you would like others to use your plugins, please add it to
814         the official 3rd party plugin repository, 
815         <ulink url="http://www.nagiosexchange.org">NagiosExchange</ulink>.
816         </para>
818         <para>We are not accepting requests for inclusion of plugins into 
819         our distribution at the moment, but when we do, these are the minimum
820         requirements:
821         </para>
823       <orderedlist>
824         <listitem>
825           <para>Include copyright and license information in all files</para>
826         </listitem>
827         <listitem>
828           <para>The standard command options are supported (--help, --version,
829           --timeout, --warning, --critical)</para>
830         </listitem>
831         <listitem>
832           <para>It is determined to be not redundant (for instance, we would not 
833                 add a new version of check_disk just because someone had provide 
834                 a plugin that had perf checking - we would incorporate the features 
835                 into an exisiting plugin)</para>
836         </listitem>
837         <listitem>
838           <para>One of the developers has had the time to audit the code and declare
839                 it ready for core</para>
840         </listitem>
841         <listitem>
842           <para>It should also follow code format guidelines, and use functions from
843 utils (perl or c or sh) rather than using its own</para>
844         </listitem>
845         <listitem>
846           <para>Includes patches to configure.in if required (via the EXTRAS list if 
847           it will only work on some platforms)</para>
848         </listitem>
849         <listitem>
850           <para>If possible, please submit a test harness. Documentation on sample
851           tests coming soon</para>
852         </listitem>
853       </orderedlist>
855         </section>
857 </section>
858 </article>
859   
860 </book>