developer-guidelines.sgml 32 KB

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