1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Icinga Plugin API</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.1">
<meta name="keywords" content="Supervision, Icinga, Nagios, Linux">
<link rel="home" href="index.html" title="Icinga Version 1.0.2 Documentation">
<link rel="up" href="ch10.html" title="Chapter 10. Development">
<link rel="prev" href="ch10.html" title="Chapter 10. Development">
<link rel="next" href="epnplugins.html" title="Developing Plugins For Use With Embedded Perl">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<CENTER><IMG src="../images/logofullsize.png" border="0" alt="Icinga" title="Icinga"></CENTER>
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Icinga Plugin API</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="ch10.html">Prev</a> </td>
<th width="60%" align="center">Chapter 10. Development</th>
<td width="20%" align="right"> <a accesskey="n" href="epnplugins.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="section" title="Icinga Plugin API">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="pluginapi"></a><a name="plugin_api"></a>Icinga Plugin API</h2></div></div></div>
<p><span class="bold"><strong>Other Resources</strong></span></p>
<p>If you're looking at writing your own plugins for Icinga, please make sure to visit these other resources:</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
<p>The official <a class="link" href="http://sourceforge.net/projects/nagiosplug/" target="_top">Nagios plugin project
website</a></p>
</li>
<li class="listitem">
<p>The official <a class="link" href="http://nagiosplug.sourceforge.net/developer-guidelines.html" target="_top">Nagios plugin
development guidelines</a></p>
</li>
</ul></div>
<p><span class="bold"><strong>Plugin Overview</strong></span></p>
<p>Scripts and executables must do two things (at a minimum) in order to function as Icinga plugins:</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
<p>Exit with one of several possible return values</p>
</li>
<li class="listitem">
<p>Return at least one line of text output to STDOUT</p>
</li>
</ul></div>
<p>The inner workings of your plugin are unimportant to Icinga. Your plugin could check the status of a TCP port, run
a database query, check disk free space, or do whatever else it needs to check something. The details will depend on what needs
to be checked - that's up to you.</p>
<p><span class="bold"><strong>Return Code</strong></span></p>
<p>Icinga determines the status of a host or service by evaluating the return code from plugins. The following tables
shows a list of valid return codes, along with their corresponding service or host states.</p>
<div class="informaltable">
<table border="1">
<colgroup>
<col>
<col>
<col>
</colgroup>
<tbody>
<tr>
<td><p> <span class="bold"><strong>Plugin Return Code</strong></span> </p></td>
<td><p> <span class="bold"><strong>Service State</strong></span> </p></td>
<td><p> <span class="bold"><strong>Host State</strong></span> </p></td>
</tr>
<tr>
<td><p>0</p></td>
<td><p>OK</p></td>
<td><p>UP</p></td>
</tr>
<tr>
<td><p>1</p></td>
<td><p>WARNING</p></td>
<td><p>UP or DOWN/UNREACHABLE*</p></td>
</tr>
<tr>
<td><p>2</p></td>
<td><p>CRITICAL</p></td>
<td><p>DOWN/UNREACHABLE</p></td>
</tr>
<tr>
<td><p>3</p></td>
<td><p>UNKNOWN</p></td>
<td><p>DOWN/UNREACHABLE</p></td>
</tr>
</tbody>
</table>
</div>
<p><span class="bold"><strong>Plugin Output Spec</strong></span></p>
<p>At a minimum, plugins should return at least one of text output but they can optionally return multiple lines of output.
Plugins may also return optional performance data that can be processed by external applications. The basic format for plugin
output is shown below:</p>
<p><span class="color">TEXT OUTPUT</span> | <span class="color">OPTIONAL
PERFDATA</span></p>
<p><span class="color">LONG TEXT LINE 1 LONG TEXT LINE 2 ... LONG TEXT LINE N</span> | <span class="color">PERFDATA LINE 2</span></p>
<p><span class="color">PERFDATA LINE 3 ... PERFDATA LINE N</span></p>
<p>The performance data (shown in <span class="color">orange</span>) is optional. If a plugin
returns performance data in its output, it must separate the performance data from the other text output using a pipe (|)
symbol. Additional lines of long text output (shown in <span class="color">blue</span>) are also
optional.</p>
<p><span class="bold"><strong>Plugin Output Examples</strong></span></p>
<p>Let's see some examples of possible plugin output...</p>
<p><span class="bold"><strong>Case 1: One line of output (text only)</strong></span></p>
<p>Assume we have a plugin that returns one line of output that looks like this:</p>
<p>DISK OK - free space: / 3326 MB (56%); If this plugin was used to perform a service check, the entire line of output will
be stored in the <a class="link" href="macrolist.html#macrolist-serviceoutput">$SERVICEOUTPUT$</a> macro.</p>
<p><span class="bold"><strong>Case 2: One line of output (text and perfdata)</strong></span></p>
<p>A plugin can return optional performance data for use by external applications. To do this, the performance data must be
separated from the text output with a pipe (|) symbol like such:</p>
<p>DISK OK - free space: / 3326 MB (56%); | /=2643MB;5948;5958;0;5968</p>
<p>If this plugin was used to perform a service check, the <span class="emphasis"><em>red</em></span> portion of output (left
of the pipe separator) will be stored in the <a class="link" href="macrolist.html#macrolist-serviceoutput">$SERVICEOUTPUT$</a> macro and the
<span class="emphasis"><em>orange</em></span> portion of output (right of the pipe separator) will be stored in the <a class="link" href="macrolist.html#macrolist-serviceperfdata">$SERVICEPERFDATA$</a> macro.</p>
<p><span class="bold"><strong>Case 3: Multiple lines of output (text and perfdata)</strong></span></p>
<p>A plugin optionally returns multiple lines of both text output and perfdata, like such:</p>
<p><span class="color">DISK OK - free space: / 3326 MB (56%);</span></p>
<p> | <span class="color">/=2643MB;5948;5958;0;5968</span></p>
<p><span class="color">/ 15272 MB (77%);</span></p>
<p><span class="color">/boot 68 MB (69%);</span></p>
<p><span class="color">/home 69357 MB (27%);</span></p>
<p><span class="color">/var/log 819 MB (84%);</span> | <span class="color">/boot=68MB;88;93;0;98</span></p>
<p><span class="color">/home=69357MB;253404;253409;0;253414</span></p>
<p><span class="color">/var/log=818MB;970;975;0;980</span></p>
<p>If this plugin was used to perform a service check, the <span class="color">red</span> portion of
first line of output (left of the pipe separator) will be stored in the <a class="link" href="macrolist.html#macrolist-serviceoutput">$SERVICEOUTPUT$</a> macro. The <span class="color">orange</span>
portions of the first and subsequent lines are concatenated (with spaces) are stored in the <a class="link" href="macrolist.html#macrolist-serviceperfdata">$SERVICEPERFDATA$</a> macro. The <span class="color">blue</span>
portions of the 2nd - 5th lines of output will be concatenated (with escaped newlines) and stored in the <a class="link" href="macrolist.html#macrolist-longserviceoutput">$LONGSERVICEOUTPUT$</a> macro.</p>
<p>The final contents of each macro are listed below:</p>
<div class="informaltable">
<table border="1">
<colgroup>
<col>
<col>
</colgroup>
<tbody>
<tr>
<td><p> <span class="bold"><strong>Macro</strong></span> </p></td>
<td><p> <span class="bold"><strong>Value</strong></span> </p></td>
</tr>
<tr>
<td><p>$SERVICEOUTPUT$</p></td>
<td><p> <span class="color">DISK OK - free space: / 3326 MB (56%);</span> </p></td>
</tr>
<tr>
<td><p>$SERVICEPERFDATA$</p></td>
<td><p> <span class="color">/=2643MB;5948;5958;0;5968 /boot=68MB;88;93;0;98 /home=69357MB;253404;253409;0;253414 /var/log=818MB;970;975;0;980</span>
</p></td>
</tr>
<tr>
<td><p>$LONGSERVICEOUTPUT$</p></td>
<td><p> <span class="color">/ 15272 MB (77%);\n/boot 68 MB (69%);\n/var/log 819 MB
(84%);</span> </p></td>
</tr>
</tbody>
</table>
</div>
<p>With regards to multiple lines of output, you have the following options for returning performance data:</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
<p>You can choose to return no performance data whatsoever</p>
</li>
<li class="listitem">
<p>You can return performance data on the first line only</p>
</li>
<li class="listitem">
<p>You can return performance data only in subsequent lines (after the first)</p>
</li>
<li class="listitem">
<p>You can return performance data in both the first line and subsequent lines (as shown above)</p>
</li>
</ul></div>
<p><span class="bold"><strong>Plugin Output Length Restrictions</strong></span></p>
<p>Icinga will only read the first 4 KB of data that a plugin returns. This is done in order to prevent runaway
plugins from dumping megs or gigs of data back to Icinga. This 4 KB output limit is fairly easy to change if you need.
Simply edit the value of the MAX_PLUGIN_OUTPUT_LENGTH definition in the <span class="emphasis"><em>include/icinga.h.in</em></span> file of the
source code distribution and recompile Icinga. There's nothing else you need to change!</p>
<p><span class="bold"><strong>Examples</strong></span></p>
<p>If you're looking for some example plugins to study, we would recommend that you download the official Nagios
plugins and look through the code for various C, Perl, and shell script plugins. Information on obtaining the official
Nagios plugins can be found <a class="link" href="plugins.html" title="Icinga Plugins">here</a>.</p>
<p><span class="bold"><strong>Perl Plugins</strong></span></p>
<p>Icinga features an optional <a class="link" href="embeddedperl.html" title="Using The Embedded Perl Interpreter">embedded Perl interpreter</a> which can speed up the
execution of Perl plugins. More information on developing Perl plugins for use with the embedded Perl interpreter can be found
<a class="link" href="embeddedperl.html" title="Using The Embedded Perl Interpreter">here</a>.</p>
<a class="indexterm" name="id2009461"></a>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="ch10.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="ch10.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="epnplugins.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Chapter 10. Development </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Developing Plugins For Use With Embedded Perl</td>
</tr>
</table>
</div>
<P class="copyright">© 2009-2010 Icinga Development Team, http://www.icinga.org</P>
</body>
</html>
|