1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
5
<title>Custom Object Variables</title>
7
<STYLE type="text/css">
9
.Default { font-family: verdana,arial,serif; font-size: 8pt; }
10
.PageTitle { font-family: verdana,arial,serif; font-size: 16pt; font-weight: bold; }
16
<body bgcolor="#FFFFFF" text="black" class="Default">
19
<img src="images/nagios.jpg" border="0" alt="Nagios" title="Nagios">
20
<h1 class="PageTitle">Custom Object Variables</h1>
26
<img src="images/upto.gif" border="0" align="middle" alt="Up To" title="Up To">Up To: <a href="toc.html">Contents</a><br>
27
<img src="images/seealso.gif" border="0" align="middle" alt="See Also" title="See Also"> See Also: <a href="objectdefinitions.html">Object Configuration</a>, <a href="objectinheritance.html">Object Inheritance</a>, <a href="macros.html">Macros</a>
31
<strong><u>Introduction</u></strong>
35
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 Nagios less generic and more infrastructure-specific. Nagios was intended to be flexible, which meant things needed to be designed in a generic manner. Host definitions in Nagios, 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.
38
Still, there needs to be a method for admins to store information about their infrastructure components in their Nagios configuration without imposing a set of specific variables on others. Nagios 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.
42
<strong><u>Custom Variable Basics</u></strong>
46
There are a few important things that you should note about custom variables:
50
<li>Custom variable names must begin with an underscore (_) to prevent name collision with standard variables
51
<li>Custom variable names are case-insensitive
52
<li>Custom variables are <a href="objectinheritance.html">inherited</a> from object templates like normal variables
53
<li>Scripts can reference custom variable values with <a href="macros.html">macros and environment variables</a>
57
<strong><u>Examples</u></strong>
61
Here's an example of how custom variables can be defined in different types of object definitions:
67
_mac_address 00:06:5B:A6:AD:AA ; <-- Custom MAC_ADDRESS variable
68
_rack_number R32 ; <-- Custom RACK_NUMBER variable
74
description Memory Usage
75
_SNMP_community public ; <-- Custom SNMP_COMMUNITY variable
76
_TechContact Jane Doe ; <-- Custom TECHCONTACT variable
82
_AIM_username john16 ; <-- Custom AIM_USERNAME variable
83
_YahooID john32 ; <-- Custom YAHOOID variable
89
<strong><u>Custom Variables As Macros</u></strong>
93
Custom variable values can be referenced in scripts and executables that Nagios runs for checks, notifications, etc. by using <a href="macros.html">macros</a> or environment variables.
96
In order to prevent name collision among custom variables from different object types, Nagios 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.
100
<table border="1" class="Default">
101
<tr><th>Object Type</th><th>Variable Name</th><th>Macro Name</th><th>Environment Variable</th></tr>
102
<tr><td>Host</td><td>MAC_ADDRESS</td><td>$_HOSTMAC_ADDRESS$</td><td>NAGIOS__HOSTMAC_ADDRESS</td></tr>
103
<tr><td>Host</td><td>RACK_NUMBER</td><td>$_HOSTRACK_NUMBER$</td><td>NAGIOS__HOSTRACK_NUMBER</td></tr>
104
<tr><td>Service</td><td>SNMP_COMMUNITY</td><td>$_SERVICESNMP_COMMUNITY$</td><td>NAGIOS__SERVICESNMP_COMMUNITY</td></tr>
105
<tr><td>Service</td><td>TECHCONTACT</td><td>$_SERVICETECHCONTACT$</td><td>NAGIOS__SERVICETECHCONTACT</td></tr>
106
<tr><td>Contact</td><td>AIM_USERNAME</td><td>$_CONTACTAIM_USERNAME$</td><td>NAGIOS__CONTACTAIM_USERNAME</td></tr>
107
<tr><td>Contact</td><td>YAHOOID</td><td>$_CONTACTYAHOOID$</td><td>NAGIOS__CONTACTYAHOOID</td></tr>
112
<strong><u>Custom Variables And Inheritance</u></strong>
116
Custom object variables are <a href="objectinheritance.html">inherited</a> just like standard host, service, or contact variables.
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
9
<title>Custom Object Variables</title>
13
<STYLE type="text/css">
17
.Default { font-family: verdana,arial,serif; font-size: 8pt; }
19
.PageTitle { font-family: verdana,arial,serif; font-size: 16pt; font-weight: bold; }
31
<body bgcolor="#FFFFFF" text="black" class="Default">
37
<img src="images/nagios.jpg" border="0" alt="Nagios" title="Nagios">
39
<h1 class="PageTitle">Custom Object Variables</h1>
51
<img src="images/upto.gif" border="0" align="middle" alt="Up To" title="Up To">Up To: <a href="toc.html">Contents</a><br>
53
<img src="images/seealso.gif" border="0" align="middle" alt="See Also" title="See Also"> See Also: <a href="objectdefinitions.html">Object Configuration</a>, <a href="objectinheritance.html">Object Inheritance</a>, <a href="macros.html">Macros</a>
61
<strong><u>Introduction</u></strong>
69
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 Nagios less generic and more infrastructure-specific. Nagios was intended to be flexible, which meant things needed to be designed in a generic manner. Host definitions in Nagios, 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.
75
Still, there needs to be a method for admins to store information about their infrastructure components in their Nagios configuration without imposing a set of specific variables on others. Nagios 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.
83
<strong><u>Custom Variable Basics</u></strong>
91
There are a few important things that you should note about custom variables:
99
<li>Custom variable names must begin with an underscore (_) to prevent name collision with standard variables
101
<li>Custom variable names are case-insensitive
103
<li>Custom variables are <a href="objectinheritance.html">inherited</a> from object templates like normal variables
105
<li>Scripts can reference custom variable values with <a href="macros.html">macros and environment variables</a>
113
<strong><u>Examples</u></strong>
121
Here's an example of how custom variables can be defined in different types of object definitions:
131
host_name linuxserver
133
_mac_address 00:06:5B:A6:AD:AA ; <-- Custom MAC_ADDRESS variable
135
_rack_number R32 ; <-- Custom RACK_NUMBER variable
145
host_name linuxserver
147
description Memory Usage
149
_SNMP_community public ; <-- Custom SNMP_COMMUNITY variable
151
_TechContact Jane Doe ; <-- Custom TECHCONTACT variable
163
_AIM_username john16 ; <-- Custom AIM_USERNAME variable
165
_YahooID john32 ; <-- Custom YAHOOID variable
177
<strong><u>Custom Variables As Macros</u></strong>
185
Custom variable values can be referenced in scripts and executables that Nagios runs for checks, notifications, etc. by using <a href="macros.html">macros</a> or environment variables.
191
In order to prevent name collision among custom variables from different object types, Nagios 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.
199
<table border="1" class="Default">
201
<tr><th>Object Type</th><th>Variable Name</th><th>Macro Name</th><th>Environment Variable</th></tr>
203
<tr><td>Host</td><td>MAC_ADDRESS</td><td>$_HOSTMAC_ADDRESS$</td><td>NAGIOS__HOSTMAC_ADDRESS</td></tr>
205
<tr><td>Host</td><td>RACK_NUMBER</td><td>$_HOSTRACK_NUMBER$</td><td>NAGIOS__HOSTRACK_NUMBER</td></tr>
207
<tr><td>Service</td><td>SNMP_COMMUNITY</td><td>$_SERVICESNMP_COMMUNITY$</td><td>NAGIOS__SERVICESNMP_COMMUNITY</td></tr>
209
<tr><td>Service</td><td>TECHCONTACT</td><td>$_SERVICETECHCONTACT$</td><td>NAGIOS__SERVICETECHCONTACT</td></tr>
211
<tr><td>Contact</td><td>AIM_USERNAME</td><td>$_CONTACTAIM_USERNAME$</td><td>NAGIOS__CONTACTAIM_USERNAME</td></tr>
213
<tr><td>Contact</td><td>YAHOOID</td><td>$_CONTACTYAHOOID$</td><td>NAGIOS__CONTACTYAHOOID</td></tr>
223
<strong><u>Custom Variables And Inheritance</u></strong>
231
Custom object variables are <a href="objectinheritance.html">inherited</a> just like standard host, service, or contact variables.