buried more whitesapce
[torrus-plus.git] / src / doc / devdoc / devdiscover.pod
blobe5341065c8db7c783a3a920bfd0c3b1523512424
1 #  devdiscover.pod - Guide to devdiscover
2 #  Copyright (C) 2003 Shawn Ferry, Stanislav Sinyagin
4 #  This program is free software; you can redistribute it and/or modify
5 #  it under the terms of the GNU General Public License as published by
6 #  the Free Software Foundation; either version 2 of the License, or
7 #  (at your option) any later version.
9 #  This program is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #  GNU General Public License for more details.
14 #  You should have received a copy of the GNU General Public License
15 #  along with this program; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18 # Shawn Ferry <sferry at sevenspace dot com> <lalartu at obscure dot org>
19 # Stanislav Sinyagin <ssinyagin@yahoo.com>
22 =head1 Torrus SNMP Device Discovery Developer's Guide
24 =head2 C<devdiscover> overview
26 C<devdiscover> is an extensible, module based, SNMP device discovery
27 utility. It is intended to automatically generate Torrus configuration
28 files, based on SNMP discovery results and templates.
30 See I<Torrus Command Reference> for command usage and functionality overview.
32 In general, C<devdiscover> consists of the following files and functional
33 parts:
35 =over 4
37 =item * C<bin/devdiscover.in>
39 This file is installed as C<bin/devdiscover> in Torrus installation directory,
40 with certain variables substituted. The program provides all the commandline
41 functionality and options processing. Once the CLI options are processed and
42 verified, the control is passed to the C<Torrus::DevDiscover> object.
44 =item * C<Torrus::DevDiscover>
46 This Perl module is responsible for the SNMP discovery process organization:
48 =over 8
50 =item *
52 it registers the discovery modules;
54 =item *
56 establishes an SNMP session to the target host;
58 =item *
60 initiates a new C<Torrus::DevDiscover::DevDetails> object for the target host;
62 =item *
64 stores the connection-specific parameters to the device object;
66 =item *
68 for each registered discovery module, executes C<checkdevtype()> in
69 I<sequential> order;
71 =item *
73 for those discovery modules which paid interest in this target host,
74 executes C<discover()> in I<sequential> order;
76 =item *
78 upon request from C<bin/devdiscover>, builds the configuration
79 XML tree, by calling C<buildConfig()> in I<sequential> order for each
80 relevant discovery module for each target host.
82 =back
84 =item * C<Torrus::DevDiscover::DevDetails>
86 This Perl module is defined in F<lib/Torrus/DevDiscover.pm>, and provides
87 the functionality to store the results of SNMP device discovery.
89 =item * C<Torrus::ConfigBuilder>
91 This module is an encapsulation wrapper for XML configuration builder.
92 It provides methods for every element of Torrus configuration.
94 =item * Discovery Modules
96 These provide all the functionality for SNMP discovery. Normally
97 one module covers one MIB, or sometimes several vendor-specific MIBs,
98 and it is responsible for finding out the device details necessary
99 for Torrus configuration building. Usually a discovery module refers to one or
100 several I<template definition files>. A module may depend on
101 other modules' discovery results. This is controlled by its
102 C<sequence number>. Vendor-independent discovery modules are normally named
103 as C<Torrus::DevDiscover::RFCXXXX_SOME_HUMAN_NAME>, and vendor-specific
104 ones are named as C<Torrus::DevDiscover::Vendor[Product[Subsystem]]>.
106 =item * Template definition files
108 These are XML documents residing in F<xmlconfig/vendor> and
109 F<xmlconfig/generic> directories. Each file is a piece of Torrus configuration,
110 and contains definitions and templates for particular MIB or vendor.
111 Generic template definition files are for vendor-independent MIBs,
112 and normally they are named as F<rfcXXXX.some-human-name.xml>.
113 Vendor-specific files are named as F<vendor.product[.subsystem].xml>.
115 =back
118 =head2 Discovery Module Internals
120 Discovery modules are Perl packages with few required components.
121 Before creating your own modules, please read and follow
122 I<Torrus Programming Style Guide>.
124 Upon initialization, C<Torrus::DevDiscover> loads the modules listed in
125 C<@Torrus::DevDiscover::loadModules> array. This array is pre-populated
126 by standard module names in F<devdiscover-config.pl>.
127 You can add new module names by pushing them onto this array in your
128 local F<devdiscover-siteconfig.pl>.
130 =head3 Module Registration
132 Each discovery module should register itself in DevDiscover registry.
133 Normally there's only one registry entry per discovery module, though
134 it's not a limitation. The registry entry is identified by a registry
135 name, which normally repeats the module name.
137 Example:
139     $Torrus::DevDiscover::registry{'RFC2790_HOST_RESOURCES'} = {
140         'sequence'     => 100,
141         'checkdevtype' => \&checkdevtype,
142         'discover'     => \&discover,
143         'buildConfig'  => \&buildConfig
144         };
146 Each registry entry must contain 4 fields:
148 =over 4
150 =item * C<sequence>
152 The sequence number determines the order in which every discovery module's
153 procedure is executed. Sequence numbers of dependant modules must
154 be higher than those of their dependencies.
156 Generic MIB discovery modules should have the sequence number 100. If
157 a particular generic module depends on other generic modules, its sequence
158 number may be 110.
160 Vendor-specific modules should have the sequence number 500.
161 Vendor-specific modules that depend on other vendor-specific modules,
162 should have sequence number 510.
164 Dependencies deeper than one level may exist, but it's recommended
165 to avoid them. For most cases this should be enough.
167 Exception is made for C<RFC2863_IF_MIB> module, which has the sequence
168 number 50. That is because it provides the basic interface discovery,
169 and many other modules depend on its results.
171 Another exception is vendor-specific modules where the SNMP session parameters
172 must be set earliest possible. One of such parameters is C<snmp-max-msg-size>.
173 Some vendor SNMP agents would not be walked properly without this setting.
174 In these occasions, the sequence number is below 50. The recommended value
175 is 30.
177 =item * C<checkdevtype>
179 Must be a subroutine reference. This subroutine is called with two object
180 references as arguments: C<Torrus::DevDiscover> and
181 C<Torrus::DevDiscover::DevDetails>.
182 The purpose of this subroutine is to determine if the target host is
183 of required type, or if it supports the required MIB.
184 The subroutine should return true if and only if the target host
185 supports the MIB variables this module is supposed to discover.
187 In general, C<checkdevtype> subroutine is small, and checks one or several
188 OIDs presence on the host, or their values, e.g. the value of I<sysObjectID>
189 variable. It should perform as less as possible SNMP requests, in order to
190 speed up the pre-discovery process.
192 =item * C<discover>
194 Must be a subroutine reference. This subroutine is called with the same
195 two arguments as C<checkdevtype()>. It is called for those modules only,
196 whose C<checkdevtype()> has returned true. The subroutine should return true
197 if no errors occured during the discovery.
199 The purpose of C<discover()> is to perform the actual SNMP discovery,
200 and prepare the parameter values for future XML configuration.
202 =item * C<buildConfig>
204 Must be a subroutine reference. This subroutine is called with three object
205 references as arguments: C<Torrus::DevDiscover::DevDetails>,
206 C<Torrus::ConfigBuilder>, and an XML element object, which should be used only
207 to pass data to ConfigBuilder methods.
209 This subroutine is designed to construct the resulting XML configuration
210 subtree as a child of a given XML element. Upper level subtrees
211 are handled by CLI options processing code.
213 =back
216 =head3 OID Definitions
218 OID definitions are designed to provide symbolic names to OIDs
219 in numerical notation. Normally the symbolic names repeat the names from
220 corresponding MIBs.
222 The definitions must be defined in an C<oiddef> hash defined in the
223 package namespace. Then they are automatically imported by DevDiscover
224 initialization procerure.
226 Example:
228     our %oiddef =
229         (
230          'hrSystemUptime'               => '1.3.6.1.2.1.25.1.1.0',
231          'hrSystemNumUsers'             => '1.3.6.1.2.1.25.1.5.0',
232          'hrSystemProcesses'            => '1.3.6.1.2.1.25.1.6.0',
233          'hrSystemMaxProcesses'         => '1.3.6.1.2.1.25.1.7.0',
234          'hrMemorySize'                 => '1.3.6.1.2.1.25.2.2.0',
235          'hrStorageTable'               => '1.3.6.1.2.1.25.2.3.1',
236          'hrStorageIndex'               => '1.3.6.1.2.1.25.2.3.1.1',
237          'hrStorageType'                => '1.3.6.1.2.1.25.2.3.1.2',
238          'hrStorageDescr'               => '1.3.6.1.2.1.25.2.3.1.3',
239          'hrStorageAllocationUnits'     => '1.3.6.1.2.1.25.2.3.1.4',
240          'hrStorageSize'                => '1.3.6.1.2.1.25.2.3.1.5',
241          'hrStorageUsed'                => '1.3.6.1.2.1.25.2.3.1.6',
242          'hrStorageAllocationFailures'  => '1.3.6.1.2.1.25.2.3.1.7'
243          );
246 =head3 Template References
248 Normally a discovery module would refer to configuration templates
249 defined in template definition files. In order to provide an extra level of
250 flexibility, these templates should be defined in
251 F<devdiscover-config.pl> or in F<devdiscover-siteconfig.pl>.
253 It is recommended that the template references in the discovery modules
254 follow the naming standard: C<module::template-name>.
256 ConfigBuilder's C<addTemplateApplication()> method looks up every
257 template name in the global hash C<%Torrus::ConfigBuilder::templateRegistry>
258 and figures out the source XML file and the actual template name.
260 Example:
262     $Torrus::ConfigBuilder::templateRegistry{
263         'RFC2790_HOST_RESOURCES::hr-system-uptime'} = {
264             'name'   => 'mytest-hr-system-uptime',
265             'source' => 'mytest.templates.xml'
266             };
269 =head3 Interface filtering
271 Usually not all interfaces from ifTable need to be monitored.
272 For example, Loopback and Null0 interfaces on Cisco routers.
274 C<Torrus::DevDiscover::RFC2863_IF_MIB> provides the functionality to
275 automatically filter out the interfaces, based on filter definitions.
276 Filter definitions are registered by calling the subroutine
277 C<Torrus::DevDiscover::RFC2863_IF_MIB::addInterfaceFilter
278 ($devdetails, $interfaceFilter)>. The second argument is a reference
279 to a hash of the following structure:
281 Keys are symbolic names that mean nothing and need only to be unique.
282 Values are hash references with the following entries: C<ifType>
283 specifies the IANA interface type, and optional C<ifDescr> specifies
284 a regular expression to match against interface description.
286 The filters are usually registered within C<checkdevtype> subroutine
287 of the vendor module, after the device type is identified. See
288 F<CiscoIOS.pm> and F<CiscoCatOS.pm> as examples.
291 =head2 Authors
293 Shawn Ferry: initial draft.
295 Stanislav Sinyagin: revision and detailed content.