developer-guidelines.sgml 31 KB

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