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
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Custom Object Variables</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="ch03.html" title="Chapter 3. Configuring Icinga">
<link rel="prev" href="objectdefinitions.html" title="Object Definitions">
<link rel="next" href="configcgi.html" title="CGI Configuration File Options">
</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">Custom Object Variables</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="objectdefinitions.html">Prev</a> </td>
<th width="60%" align="center">Chapter 3. Configuring Icinga</th>
<td width="20%" align="right"> <a accesskey="n" href="configcgi.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="section" title="Custom Object Variables">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="customobjectvars"></a><a name="custom_object_vars"></a>Custom Object Variables</h2></div></div></div>
<p><span class="bold"><strong>Introduction</strong></span></p>
<p>Users often request that new variables be added to host, service, and contact definitions. These include variables for
SNMP community, MAC address, AIM username, Skype number, and street address. The list is endless. The problem that I see with
doing this is that it makes Icinga less generic and more infrastructure-specific. Icinga was intended to be
flexible, which meant things needed to be designed in a generic manner. Host definitions in Icinga, for example, have a
generic "address" variable that can contain anything from an IP address to human-readable driving directions - whatever is
appropriate for the user's setup.</p>
<p>Still, there needs to be a method for admins to store information about their infrastructure components in their
Icinga configuration without imposing a set of specific variables on others. Icinga attempts to solve this problem
by allowing users to define custom variables in their object definitions. Custom variables allow users to define additional
properties in their host, service, and contact definitions, and use their values in notifications, event handlers, and host and
service checks.</p>
<p><span class="bold"><strong>Custom Variable Basics</strong></span></p>
<p>There are a few important things that you should note about custom variables:</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
<p>Custom variable names must begin with an underscore (_) to prevent name collision with standard variables</p>
</li>
<li class="listitem">
<p>Custom variable names are converted to all uppercase before use</p>
</li>
<li class="listitem">
<p>Custom variables are <a class="link" href="objectinheritance.html" title="Object Inheritance">inherited</a> from object templates like normal
variables</p>
</li>
<li class="listitem">
<p>Scripts can reference custom variable values with <a class="link" href="macros.html" title="Understanding Macros and How They Work">macros and environment
variables</a></p>
</li>
</ul></div>
<p><span class="bold"><strong>Examples</strong></span></p>
<p>Here's an example of how custom variables can be defined in different types of object definitions:</p>
<pre class="screen">
define host{
host_name linuxserver
_mac_address 00:06:5B:A6:AD:AA ; <-- Custom MAC_ADDRESS variable
_rack_number R32 ; <-- Custom RACK_NUMBER variable
...
}
define service{
host_name linuxserver
description Memory Usage
_SNMP_community public ; <-- Custom SNMP_COMMUNITY variable
_TechContact Jane Doe ; <-- Custom TECHCONTACT variable
....
}
define contact{
contact_name john
_AIM_username john16 ; <-- Custom AIM_USERNAME variable
_YahooID john32 ; <-- Custom YAHOOID variable
...
}
</pre>
<p><span class="bold"><strong>Custom Variables As Macros</strong></span></p>
<p>Custom variable values can be referenced in scripts and executables that Icinga runs for checks, notifications,
etc. by using <a class="link" href="macros.html" title="Understanding Macros and How They Work">macros</a> or environment variables.</p>
<p>In order to prevent name collision among custom variables from different object types, Icinga prepends "_HOST",
"_SERVICE", or "_CONTACT" to the beginning of custom host, service, or contact variables, respectively, in macro and environment
variable names. The table below shows the corresponding macro and environment variable names for the custom variables that were
defined in the example above.</p>
<div class="informaltable">
<table border="1">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<tbody>
<tr>
<td><p> <span class="bold"><strong>Object Type</strong></span> </p></td>
<td><p> <span class="bold"><strong>Variable Name</strong></span> </p></td>
<td><p> <span class="bold"><strong>Macro Name</strong></span> </p></td>
<td><p> <span class="bold"><strong>Environment Variable</strong></span> </p></td>
</tr>
<tr>
<td><p>Host</p></td>
<td><p>MAC_ADDRESS</p></td>
<td><p>$_HOSTMAC_ADDRESS$</p></td>
<td><p>NAGIOS__HOSTMAC_ADDRESS</p></td>
</tr>
<tr>
<td><p>Host</p></td>
<td><p>RACK_NUMBER</p></td>
<td><p>$_HOSTRACK_NUMBER$</p></td>
<td><p>NAGIOS__HOSTRACK_NUMBER</p></td>
</tr>
<tr>
<td><p>Service</p></td>
<td><p>SNMP_COMMUNITY</p></td>
<td><p>$_SERVICESNMP_COMMUNITY$</p></td>
<td><p>NAGIOS__SERVICESNMP_COMMUNITY</p></td>
</tr>
<tr>
<td><p>Service</p></td>
<td><p>TECHCONTACT</p></td>
<td><p>$_SERVICETECHCONTACT$</p></td>
<td><p>NAGIOS__SERVICETECHCONTACT</p></td>
</tr>
<tr>
<td><p>Contact</p></td>
<td><p>AIM_USERNAME</p></td>
<td><p>$_CONTACTAIM_USERNAME$</p></td>
<td><p>NAGIOS__CONTACTAIM_USERNAME</p></td>
</tr>
<tr>
<td><p>Contact</p></td>
<td><p>YAHOOID</p></td>
<td><p>$_CONTACTYAHOOID$</p></td>
<td><p>NAGIOS__CONTACTYAHOOID</p></td>
</tr>
</tbody>
</table>
</div>
<p><span class="bold"><strong>Custom Variables And Inheritance</strong></span></p>
<p>Custom object variables are <a class="link" href="objectinheritance.html" title="Object Inheritance">inherited</a> just like standard host, service, or
contact variables.</p>
<a class="indexterm" name="id1958299"></a>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="objectdefinitions.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="ch03.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="configcgi.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top"> Object Definitions </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> CGI Configuration File Options</td>
</tr>
</table>
</div>
<P class="copyright">© 2009-2010 Icinga Development Team, http://www.icinga.org</P>
</body>
</html>
|