developer-guidelines.sgml 31 KB

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