Code

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