FAQ: Update CVS references
[monitoring-plugins.git] / doc / developer-guidelines.sgml
blob61b9f178a6bb5d4dfc9562fa05fa3df1d4b712e3
1 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V4.1//EN" >
2 <book>
3 <title>Nagios Plugin Development 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>2013</pubdate>
15 <title>Nagios Plugin Development Guidelines</title>
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 - 2013</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 plugin developers and encourage the standarization of the
35 different kind of plugins: C, shell, perl, python, etc.</para>
37 <para>Nagios Plugin Development Guidelines Copyright (C) 2000-2013
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>
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>Starting with version 3, Nagios will process plugins' multiline
87 output, which should be formatted as:</para>
88 <literallayout>
89 SERVICE STATUS: First line of output | First part of performance data
90 Any number of subsequent lines of output, but note that buffers
91 may have a limited size | Second part of performance data, which
92 may have continuation lines, too
93 </literallayout>
94 <para>Note, however, that the default configs still do not include
95 the output's continuation lines into the notifications sent when
96 Nagios notifies contacts about potential problems.
97 Thus, keep your output short and to the point.</para>
99 <para>Output should be in the format:</para>
100 <literallayout>
101 SERVICE STATUS: Information text
102 </literallayout>
103 <para>However, note that this is not a requirement of the API, so you cannot depend on this
104 being an accurate reflection of the status of the service - the status should always
105 be determined by the return code.</para>
106 </section>
108 <section><title>Verbose output</title>
109 <para>Use the -v flag for verbose output. You should allow multiple
110 -v options for additional verbosity, up to a maximum of 3. The standard
111 type of output should be:</para>
113 <table id="verboselevels"><title>Verbose output levels</title>
114 <tgroup cols="2">
115 <thead>
116 <row>
117 <entry><para>Verbosity level</para></entry>
118 <entry><para>Type of output</para></entry>
119 </row>
120 </thead>
121 <tbody>
122 <row>
123 <entry align="center"><para>0</para></entry>
124 <entry><para>Single line, minimal output. Summary</para></entry>
125 </row>
126 <row>
127 <entry align="center"><para>1</para></entry>
128 <entry><para>Single line, additional information (eg list processes that fail)</para></entry>
129 </row>
130 <row>
131 <entry align="center"><para>2</para></entry>
132 <entry><para>Multi line, configuration debug output (eg ps command used)</para></entry>
133 </row>
134 <row>
135 <entry align="center"><para>3</para></entry>
136 <entry><para>Lots of detail for plugin problem diagnosis</para></entry>
137 </row>
138 </tbody>
139 </tgroup>
140 </table>
141 </section>
143 <section><title>Screen Output</title>
144 <para>The plugin should print the diagnostic and just the
145 usage part of the help message. A well written plugin would
146 then have --help as a way to get the verbose help.</para>
148 <para>Code and output should try to respect the 80x25 size of a
149 crt (remember when fixing stuff in the server room!)</para>
150 </section>
152 <section><title>Plugin Return Codes</title>
153 <para>The return codes below are based on the POSIX spec of returning
154 a positive value. Netsaint prior to v0.0.7 supported non-POSIX
155 compliant return code of "-1" for unknown. Nagios supports POSIX return
156 codes by default.</para>
158 <para>Note: Some plugins will on occasion print on STDOUT that an error
159 occurred and error code is 138 or 255 or some such number. These
160 are usually caused by plugins using system commands and having not
161 enough checks to catch unexpected output. Developers should include a
162 default catch-all for system command output that returns an UNKNOWN
163 return code.</para>
165 <table id="ReturnCodes"><title>Plugin Return Codes</title>
166 <tgroup cols="3">
167 <thead>
168 <row>
169 <entry><para>Numeric Value</para></entry>
170 <entry><para>Service Status</para></entry>
171 <entry><para>Status Description</para></entry>
172 </row>
173 </thead>
174 <tbody>
175 <row>
176 <entry align="center"><para>0</para></entry>
177 <entry valign="middle"><para>OK</para></entry>
178 <entry><para>The plugin was able to check the service and it
179 appeared to be functioning properly</para></entry>
180 </row>
181 <row>
182 <entry align="center"><para>1</para></entry>
183 <entry valign="middle"><para>Warning</para></entry>
184 <entry><para>The plugin was able to check the service, but it
185 appeared to be above some "warning" threshold or did not appear
186 to be working properly</para></entry>
187 </row>
188 <row>
189 <entry align="center"><para>2</para></entry>
190 <entry valign="middle"><para>Critical</para></entry>
191 <entry><para>The plugin detected that either the service was not
192 running or it was above some "critical" threshold</para></entry>
193 </row>
194 <row>
195 <entry align="center"><para>3</para></entry>
196 <entry valign="middle"><para>Unknown</para></entry>
197 <entry><para>Invalid command line arguments were supplied to the
198 plugin or low-level failures internal to the plugin (such as unable to fork,
199 or open a tcp socket) that prevent it from performing the specified
200 operation. Higher-level errors (such as name resolution errors,
201 socket timeouts, etc) are outside of the control of plugins and should
202 generally NOT be reported as UNKNOWN states.
203 </para></entry>
204 </row>
205 </tbody>
206 </tgroup>
207 </table>
210 </section>
212 <section id="thresholdformat"><title>Threshold and ranges</title>
213 <para>A range is defined as a start and end point (inclusive) on a numeric scale (possibly
214 negative or positive infinity).
215 </para>
216 <para>A threshold is a range with an alert level (either warning or critical). Use the
217 set_thresholds(thresholds *, char *, char *) function to set the thresholds.
218 </para>
219 <para>The theory is that the plugin will do some sort of check which returns
220 back a numerical value, or metric, which is then compared to the warning and
221 critical thresholds. Use the get_status(double, thresholds *) function to
222 compare the value against the thresholds.</para>
223 <para>This is the generalised format for ranges:</para>
225 <literallayout>
226 [@]start:end
227 </literallayout>
229 <para>Notes:</para>
230 <orderedlist>
231 <listitem><para>start &le; end</para>
232 </listitem>
233 <listitem><para>start and ":" is not required if start=0</para>
234 </listitem>
235 <listitem><para>if range is of format "start:" and end is not specified,
236 assume end is infinity</para>
237 </listitem>
238 <listitem><para>to specify negative infinity, use "~"</para>
239 </listitem>
240 <listitem><para>alert is raised if metric is outside start and end range
241 (inclusive of endpoints)</para>
242 </listitem>
243 <listitem><para>if range starts with "@", then alert if inside this range
244 (inclusive of endpoints)</para>
245 </listitem>
246 </orderedlist>
248 <para>Note: Not all plugins are coded to expect ranges in this format yet.
249 There will be some work in providing multiple metrics.</para>
251 <table id="ExampleRanges"><title>Example ranges</title>
252 <tgroup cols="2">
253 <thead>
254 <row>
255 <entry><para>Range definition</para></entry>
256 <entry><para>Generate an alert if x...</para></entry>
257 </row>
258 </thead>
259 <tbody>
260 <row>
261 <entry>10</entry>
262 <entry>&lt; 0 or &gt; 10, (outside the range of {0 .. 10})</entry>
263 </row>
264 <row>
265 <entry>10:</entry>
266 <entry>&lt; 10, (outside {10 .. &infin;})</entry>
267 </row>
268 <row>
269 <entry>~:10</entry>
270 <entry>&gt; 10, (outside the range of {-&infin; .. 10})</entry>
271 </row>
272 <row>
273 <entry>10:20</entry>
274 <entry>&lt; 10 or &gt; 20, (outside the range of {10 .. 20})</entry>
275 </row>
276 <row>
277 <entry>@10:20</entry>
278 <entry>&ge; 10 and &le; 20, (inside the range of {10 .. 20})</entry>
279 </row>
280 </tbody>
281 </tgroup>
282 </table>
283 <table id="CommandLineExamples"><title>Command line examples</title>
284 <tgroup cols="2">
285 <thead>
286 <row>
287 <entry><para>Command line</para></entry>
288 <entry><para>Meaning</para></entry>
289 </row>
290 </thead>
291 <tbody>
292 <row>
293 <entry>check_stuff -w10 -c20</entry>
294 <entry>Critical if "stuff" is over 20, else warn if over 10 (will be critical if "stuff" is less than 0)</entry>
295 </row>
296 <row>
297 <entry>check_stuff -w~:10 -c~:20</entry>
298 <entry>Same as above. Negative "stuff" is OK</entry>
299 </row>
300 <row>
301 <entry>check_stuff -w10: -c20</entry>
302 <entry>Critical if "stuff" is over 20, else warn if "stuff" is below 10 (will be critical if "stuff" is less than 0)</entry>
303 </row>
304 <row>
305 <entry>check_stuff -c1:</entry>
306 <entry>Critical if "stuff" is less than 1</entry>
307 </row>
308 <row>
309 <entry>check_stuff -w~:0 -c10</entry>
310 <entry>Critical if "stuff" is above 10; Warn if "stuff" is above zero (will be critical if "stuff" is less than 0)</entry>
311 </row>
312 <row>
313 <entry>check_stuff -c5:6</entry>
314 <entry>Critical if "stuff" is less than 5 or more than 6</entry>
315 </row>
316 <row>
317 <entry>check_stuff -c@10:20</entry>
318 <entry>OK if stuff is less than 10 or higher than 20, otherwise critical </entry>
319 </row>
320 </tbody>
321 </tgroup>
322 </table>
323 </section>
325 <section><title>Performance data</title>
326 <para>Nagios 3 and newer will concatenate the parts following a "|" in a) the first
327 line output by the plugin, and b) in the second to last line, into a string it
328 passes to whatever performance data processing it has configured. (Note that it
329 currently does not insert additional whitespace between both, so the plugin needs
330 to provide some to prevent the last pair of a) and the first of b) getting run
331 together.) Please refer to the Nagios documentation for information on how to
332 configure such processing. However, it is the responsibility of the plugin writer
333 to ensure the performance data is in a "Nagios Plugins" format.
334 This is the expected format:</para>
336 <literallayout>
337 'label'=value[UOM];[warn];[crit];[min];[max]
338 </literallayout>
340 <para>Notes:</para>
341 <orderedlist>
342 <listitem><para>space separated list of label/value pairs</para>
343 </listitem>
344 <listitem><para>label can contain any characters except the equals sign or single quote (')</para>
345 </listitem>
346 <listitem><para>the single quotes for the label are optional. Required if
347 spaces are in the label</para>
348 </listitem>
349 <listitem><para>label length is arbitrary, but ideally the first 19 characters
350 are unique (due to a limitation in RRD). Be aware of a limitation in the
351 amount of data that NRPE returns to Nagios</para>
352 </listitem>
353 <listitem><para>to specify a quote character, use two single quotes</para>
354 </listitem>
355 <listitem><para>warn, crit, min or max may be null (for example, if the threshold is
356 not defined or min and max do not apply). Trailing unfilled semicolons can be
357 dropped</para>
358 </listitem>
359 <listitem><para>min and max are not required if UOM=%</para>
360 </listitem>
361 <listitem><para>value, min and max in class [-0-9.]. Must all be the
362 same UOM. value may be a literal "U" instead, this would indicate that the
363 actual value couldn't be determined</para>
364 </listitem>
365 <listitem><para>warn and crit are in the range format (see
366 <xref linkend="thresholdformat">). Must be the same UOM</para>
367 </listitem>
368 <listitem><para>UOM (unit of measurement) is one of:</para>
369 <orderedlist>
370 <listitem><para>no unit specified - assume a number (int or float)
371 of things (eg, users, processes, load averages)</para>
372 </listitem>
373 <listitem><para>s - seconds (also us, ms)</para></listitem>
374 <listitem><para>% - percentage</para></listitem>
375 <listitem><para>B - bytes (also KB, MB, TB)</para></listitem>
376 <listitem><para>c - a continous counter (such as bytes
377 transmitted on an interface)</para></listitem>
378 </orderedlist>
379 </listitem>
380 </orderedlist>
382 <para>It is up to third party programs to convert the Nagios Plugins
383 performance data into graphs.</para>
384 </section>
386 <section><title>Translations</title>
387 <para>If possible, use translation tools for all output to respect the user's language
388 settings. See <xref linkend="translationsdevelopers"> for guidelines
389 for the core plugins.
390 </para>
391 </section>
392 </section>
394 <section id="SysCmdAuxFiles"><title>System Commands and Auxiliary Files</title>
396 <section><title>Don't execute system commands without specifying their
397 full path</title>
398 <para>Don't use exec(), popen(), etc. to execute external
399 commands without explicity using the full path of the external
400 program.</para>
402 <para>Doing otherwise makes the plugin vulnerable to hijacking
403 by a trojan horse earlier in the search path. See the main
404 plugin distribution for examples on how this is done.</para>
405 </section>
407 <section><title>Use spopen() if external commands must be executed</title>
409 <para>If you have to execute external commands from within your
410 plugin and you're writing it in C, use the spopen() function
411 that Karl DeBisschop has written.</para>
413 <para>The code for spopen() and spclose() is included with the
414 core plugin distribution.</para>
415 </section>
417 <section><title>Don't make temp files unless absolutely required</title>
419 <para>If temp files are needed, make sure that the plugin will
420 fail cleanly if the file can't be written (e.g., too few file
421 handles, out of disk space, incorrect permissions, etc.) and
422 delete the temp file when processing is complete.</para>
423 </section>
425 <section><title>Don't be tricked into following symlinks</title>
427 <para>If your plugin opens any files, take steps to ensure that
428 you are not following a symlink to another location on the
429 system.</para>
430 </section>
432 <section><title>Validate all input</title>
434 <para>use routines in utils.c or utils.pm and write more as needed</para>
435 </section>
437 </section>
442 <section id="PerlPlugin"><title>Perl Plugins</title>
444 <para>Perl plugins are coded a little more defensively than other
445 plugins because of embedded Perl. When configured as such, embedded
446 Perl Nagios (ePN) requires stricter use of the some of Perl's features.
447 This section outlines some of the steps needed to use ePN
448 effectively.</para>
450 <orderedlist>
452 <listitem><para> Do not use BEGIN and END blocks since they will be called
453 only once (when Nagios starts and shuts down) with Embedded Perl (ePN). In
454 particular, do not use BEGIN blocks to initialize variables.</para>
455 </listitem>
457 <listitem><para>To use utils.pm, you need to provide a full path to the
458 module in order for it to work.</para>
460 <literallayout>
461 e.g.
462 use lib "/usr/local/nagios/libexec";
463 use utils qw(...);
464 </literallayout>
465 </listitem>
467 <listitem><para>Perl scripts should be called with "-w"</para>
468 </listitem>
470 <listitem><para>All Perl plugins must compile cleanly under "use strict" - i.e. at
471 least explicitly package names as in "$main::x" or predeclare every
472 variable. </para>
475 <para>Explicitly initialize each variable in use. Otherwise with
476 caching enabled, the plugin will not be recompiled each time, and
477 therefore Perl will not reinitialize all the variables. All old
478 variable values will still be in effect.</para>
479 </listitem>
481 <listitem><para>Do not use &gt;DATA&lt; handles (these simply do not compile under ePN).</para>
482 </listitem>
484 <listitem><para>Do not use global variables in named subroutines. This is bad practise anyway, but with ePN the
485 compiler will report an error "&lt;global_var&gt; will not stay shared ..". Values used by
486 subroutines should be passed in the argument list.</para>
487 </listitem>
489 <listitem><para>If writing to a file (perhaps recording
490 performance data) explicitly close close it. The plugin never
491 calls <emphasis role="strong">exit</emphasis>; that is caught by
492 p1.pl, so output streams are never closed.</para>
493 </listitem>
495 <listitem><para>As in <xref linkend="runtime"> all plugins need
496 to monitor their runtime, specially if they are using network
497 resources. Use of the <emphasis>alarm</emphasis> is recommended
498 noting that some Perl modules (eg LWP) manage timers, so that an alarm
499 set by a plugin using such a module is overwritten by the module.
500 (workarounds are cunning (TM) or using the module timer)
501 Plugins may import a default time out ($TIMEOUT) from utils.pm.
502 </para>
503 </listitem>
505 <listitem><para>Perl plugins should import %ERRORS from utils.pm
506 and then "exit $ERRORS{'OK'}" rather than "exit 0"
507 </para>
508 </listitem>
510 </orderedlist>
512 </section>
514 <section id="runtime"><title>Runtime Timeouts</title>
516 <para>Plugins have a very limited runtime - typically 10 sec.
517 As a result, it is very important for plugins to maintain internal
518 code to exit if runtime exceeds a threshold. </para>
520 <para>All plugins should timeout gracefully, not just networking
521 plugins. For instance, df may lock if you have automounted
522 drives and your network fails - but on first glance, who'd think
523 df could lock up like that. Plus, it should just be more error
524 resistant to be able to time out rather than consume
525 resources.</para>
527 <section><title>Use DEFAULT_SOCKET_TIMEOUT</title>
529 <para>All network plugins should use DEFAULT_SOCKET_TIMEOUT to timeout</para>
531 </section>
534 <section><title>Add alarms to network plugins</title>
536 <para>If you write a plugin which communicates with another
537 networked host, you should make sure to set an alarm() in your
538 code that prevents the plugin from hanging due to abnormal
539 socket closures, etc. Nagios takes steps to protect itself
540 against unruly plugins that timeout, but any plugins you create
541 should be well behaved on their own.</para>
543 </section>
547 </section>
549 <section id="PlugOptions"><title>Plugin Options</title>
551 <para>A well written plugin should have --help as a way to get
552 verbose help. Code and output should try to respect the 80x25 size of a
553 crt (remember when fixing stuff in the server room!)</para>
555 <section><title>Option Processing</title>
557 <para>For plugins written in C, we recommend the C standard
558 getopt library for short options. Getopt_long is always available.
559 </para>
561 <para>For plugins written in Perl, we recommend Getopt::Long module.</para>
563 <para>Positional arguments are strongly discouraged.</para>
565 <para>There are a few reserved options that should not be used
566 for other purposes:</para>
568 <literallayout>
569 -V version (--version)
570 -h help (--help)
571 -t timeout (--timeout)
572 -w warning threshold (--warning)
573 -c critical threshold (--critical)
574 -H hostname (--hostname)
575 -v verbose (--verbose)
576 </literallayout>
578 <para>In addition to the reserved options above, some other standard options are:</para>
580 <literallayout>
581 -C SNMP community (--community)
582 -a authentication password (--authentication)
583 -l login name (--logname)
584 -p port or password (--port or --passwd/--password)monitors operational
585 -u url or username (--url or --username)
586 </literallayout>
588 <para>Look at check_pgsql and check_procs to see how I currently
589 think this can work. Standard options are:</para>
592 <para>The option -V or --version should be present in all
593 plugins. For C plugins it should result in a call to print_revision, a
594 function in utils.c which takes two character arguments, the
595 command name and the plugin revision.</para>
597 <para>The -? option, or any other unparsable set of options,
598 should print out a short usage statement. Character width should
599 be 80 and less and no more that 23 lines should be printed (it
600 should display cleanly on a dumb terminal in a server
601 room).</para>
603 <para>The option -h or --help should be present in all plugins.
604 In C plugins, it should result in a call to print_help (or
605 equivalent). The function print_help should call print_revision,
606 then print_usage, then should provide detailed
607 help. Help text should fit on an 80-character width display, but
608 may run as many lines as needed.</para>
610 <para>The option -v or --verbose should be present in all plugins.
611 The user should be allowed to specify -v multiple times to increase
612 the verbosity level, as described in <xref linkend="verboselevels">.</para>
613 </section>
615 <section>
616 <title>Plugins with more than one type of threshold, or with
617 threshold ranges</title>
619 <para>Old style was to do things like -ct for critical time and
620 -cv for critical value. That goes out the window with POSIX
621 getopt. The allowable alternatives are:</para>
623 <orderedlist>
624 <listitem>
625 <para>long options like -critical-time (or -ct and -cv, I
626 suppose).</para>
627 </listitem>
629 <listitem>
630 <para>repeated options like `check_load -w 10 -w 6 -w 4 -c
631 16 -c 10 -c 10`</para>
632 </listitem>
634 <listitem>
635 <para>for brevity, the above can be expressed as `check_load
636 -w 10,6,4 -c 16,10,10`</para>
637 </listitem>
639 <listitem>
640 <para>ranges are expressed with colons as in `check_procs -C
641 httpd -w 1:20 -c 1:30` which will warn above 20 instances,
642 and critical at 0 and above 30</para>
643 </listitem>
645 <listitem>
646 <para>lists are expressed with commas, so Jacob's check_nmap
647 uses constructs like '-p 1000,1010,1050:1060,2000'</para>
648 </listitem>
650 <listitem>
651 <para>If possible when writing lists, use tokens to make the
652 list easy to remember and non-order dependent - so
653 check_disk uses '-c 10000,10%' so that it is clear which is
654 the precentage and which is the KB values (note that due to
655 my own lack of foresight, that used to be '-c 10000:10%' but
656 such constructs should all be changed for consistency,
657 though providing reverse compatibility is fairly
658 easy).</para>
659 </listitem>
661 </orderedlist>
663 <para>As always, comments are welcome - making this consistent
664 without a host of long options was quite a hassle, and I would
665 suspect that there are flaws in this strategy.
666 </para>
667 </section>
668 </section>
670 <section id="Testcases"><title>Test cases</title>
671 <para>
672 Tests are the best way of knowing if the plugins work as expected. Please
673 create and update test cases where possible.
674 </para>
676 <para>
677 To run a test, from the top level directory, run "make test". This will run
678 all the current tests and report an overall success rate.
679 </para>
681 <para>
682 See the <ulink url="http://tinderbox.opsera.com">Nagios Plugins Tinderbox server</ulink>
683 for the daily test results.
684 </para>
686 <section><title>Test cases for plugins</title>
687 <para>These use perl's Test::More. To do a one time test, run "cd plugins && perl t/check_disk.t".
688 </para>
690 <para>There will somtimes be failures seen in this output which are known failures that
691 need to be fixed. As long as the return code is 0, it will be reported as "test pass".
692 (If you have a fix so that the specific test passes, that will be gratefully received!)
693 </para>
695 <para>
696 If you want a summary test, run: "cd plugins && prove t/check_disk.t".
697 This runs the test in a summary format.
698 </para>
700 <para>
701 For a good and amusing tutorial on using Test::More, see this
702 <ulink url="http://search.cpan.org/~mschwern/Test-Simple-0.62/lib/Test/Tutorial.pod">
703 link</ulink>
704 </para>
706 </section>
708 <section><title>Testing the C library functions</title>
709 <para>
710 We use <ulink url="http://jc.ngo.org.uk/trac-bin/trac.cgi/wiki/LibTap">the libtap library</ulink>, which gives
711 perl's TAP
712 (Test Anything Protocol) output. This is used by the FreeBSD team for their regression testing.
713 </para>
715 <para>
716 To run tests using the libtap library, download the latest tar ball and extract.
717 There is a problem with tap-1.01 where
718 <ulink url="http://jc.ngo.org.uk/trac-bin/trac.cgi/ticket/25">pthread support doesn't appear to work</ulink>
719 properly on non-FreeBSD systems. Install with 'CPPFLAGS="-UHAVE_LIBPTHREAD" ./configure && make && make check && make install'.
720 </para>
722 <para>
723 When you run Nagios Plugins' configure, it will look for the tap library and will automatically
724 setup the tests. Run "make test" to run all the tests.
725 </para>
726 </section>
728 </section>
729 <section id="CodingGuidelines"><title>Coding guidelines</title>
730 <para>See <ulink url="http://www.gnu.org/prep/standards_toc.html">GNU
731 Coding standards</ulink> for general guidelines.</para>
732 <section><title>C coding</title>
734 <para>Variables should be declared at the beginning of code blocks and
735 not inline because of portability with older compilers.</para>
737 <para>You should use /* */ for comments and not // as some compilers
738 do not handle the latter form.</para>
740 <para>You should also avoid using the type "bool" and its values
741 "true" and "false". Instead use the "int" type and the plugins' own
742 "TRUE"/"FALSE" values to keep the code uniformly.</para>
743 </section>
745 <section><title>Crediting sources</title>
746 <para>If you have copied a routine from another source, make sure the licence
747 from your source allows this. Add a comment referencing the ACKNOWLEDGEMENTS
748 file, where you can put more detail about the source.</para>
749 <para>For contributed code, do not add any named credits in the source code
750 - contributors should be added into the THANKS.in file instead.
751 </para>
752 </section>
754 <section><title>Commit Messages</title>
755 <para>If the change is due to a contribution, please quote the contributor's name
756 and, if applicable, add the SourceForge Tracker number. Don't forget to
757 update the THANKS.in file.</para>
758 <para>If you have a change that is useful for noting in the next release, please
759 update the NEWS file.</para>
760 <para>All commits will be written to a ChangeLog at release time.
761 </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 Git "master" branch.</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>
812 <section id="Contributedplugins"><title>Contributed plugins</title>
813 <para>Plugins that have been contributed to the project and
814 distributed with the Nagios Plugin files are held in the contrib/ directory and are not installed
815 by default. These plugins are not officially supported by the team.
816 The current policy is that these plugins should be owned and maintained by the original
817 contributor, preferably hosted on <ulink url="http://exchange.nagios.org">Nagios Exchange</ulink>.
818 </para>
819 <para>If patches or bugs are raised to an contributed plugin, we will start communications with the
820 original contributor, but seek to remove the plugin from our distribution.
821 </para>
822 <para>The aim is to distribute only code that the Nagios Plugin team are responsible for.
823 </para>
824 </section>
826 <section id="Newplugins"><title>New plugins</title>
827 <para>If you would like others to use your plugins, please add it to
828 the official 3rd party plugin repository,
829 <ulink url="http://exchange.nagios.org">Nagios Exchange</ulink>.
830 </para>
832 <para>We are not accepting requests for inclusion of plugins into
833 our distribution at the moment, but when we do, these are the minimum
834 requirements:
835 </para>
837 <orderedlist>
838 <listitem>
839 <para>Include copyright and license information in all files. Copyright must be solely
840 granted to the Nagios Plugin Development Team</para>
841 </listitem>
842 <listitem>
843 <para>The standard command options are supported (--help, --version,
844 --timeout, --warning, --critical)</para>
845 </listitem>
846 <listitem>
847 <para>It is determined to be not redundant (for instance, we would not
848 add a new version of check_disk just because someone had provide
849 a plugin that had perf checking - we would incorporate the features
850 into an exisiting plugin)</para>
851 </listitem>
852 <listitem>
853 <para>One of the developers has had the time to audit the code and declare
854 it ready for core</para>
855 </listitem>
856 <listitem>
857 <para>It should also follow code format guidelines, and use functions from
858 utils (perl or c or sh) rather than using its own</para>
859 </listitem>
860 <listitem>
861 <para>Includes patches to configure.in if required (via the EXTRAS list if
862 it will only work on some platforms)</para>
863 </listitem>
864 <listitem>
865 <para>If possible, please submit a test harness. Documentation on sample
866 tests coming soon</para>
867 </listitem>
868 </orderedlist>
870 </section>
872 </section>
873 </article>
875 </book>