YATG/Config.pm

filter: Statementstmt 92.8% 13 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod n/a totaltotal 88.8% 16 / 18 CC 1 SCAR 2.2
CC
1
Cov
93%
__ANON__
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« RPC/Serialized/Handler/YATG/Store.pm ↑ Summary
1 package YATG::Config;
2 {
3 1 $YATG::Config::VERSION = '5.140510';
4 }
5  
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Module::MultiConf 0.0301;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 __PACKAGE__->Validate({
12 yatg => {
13 oids => { type => HASHREF },
14 dbi_connect => { type => ARRAYREF },
15 dbi_ip_query => { type => SCALAR, default =>
16 'SELECT ip FROM device WHERE extract(epoch from last_macsuck) > (extract(epoch from now()) - 7200)' },
17 dbi_host_query => { type => SCALAR, optional => 1 },
18 dbi_interfaces_query => { type => SCALAR, optional => 1 },
19 interval => { type => SCALAR, default => 300 },
20 timeout => { type => SCALAR, default => 280 },
21 max_pollers => { type => SCALAR, default => 20 },
22 debug => { type => SCALAR, default => 0 },
23 communities => { type => SCALAR | ARRAYREF,
24 default => 'public' },
25 mibdirs => { type => ARRAYREF, default => [qw(
26 /usr/share/netdisco/mibs/cisco
27 /usr/share/netdisco/mibs/rfc
28 /usr/share/netdisco/mibs/net-snmp
29 )] },
30 disk_root => { type => SCALAR, default => '/var/lib/yatg' },
31 newhosts_watch => { type => SCALAR, optional => 1 },
32 },
33 cache_memcached => {
34 servers => { type => ARRAYREF, optional => 1 },
35 namespace => { type => SCALAR, default => 'yatg:' },
36 },
37 rpc_serialized_client_inet => {
38 data_serializer => { type => HASHREF,
39 default => {serializer => 'YAML::Syck'} },
40 io_socket_inet => { type => HASHREF, optional => 1 },
41 },
42 log_dispatch_syslog => {
43 name => { type => SCALAR, default => 'yatg' },
44 ident => { type => SCALAR, default => 'yatg' },
45 min_level => { type => SCALAR, default => 'info' },
46 facility => { type => SCALAR, default => 'local1' },
47 callbacks => { type => CODEREF | ARRAYREF,
48 0 ▶ default => sub { return "$_[1]\n" } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 },
50 1 nsca => {
51 nsca_server => { type => SCALAR, optional => 1 },
52 nsca_port => { type => SCALAR, default => '5667' },
53 send_nsca_cmd => { type => SCALAR, default => '/usr/bin/send_nsca' },
54 config_file => { type => SCALAR, default => '/etc/send_nsca.cfg' },
55 ignore_ports => { type => SCALAR, default => '^(?:Vlan|Po)\d+$' },
56 ignore_descr => { type => SCALAR, default => '(?:SPAN)' },
57 ignore_oper_descr => { type => SCALAR, optional => 1 },
58 ignore_error_descr => { type => SCALAR, optional => 1 },
59 ignore_discard_descr => { type => SCALAR, optional => 1 },
60 service_prefix => { type => SCALAR, default => 'Interfaces' },
61 },
62 });
63  
64 1 1;
65  
66 # ABSTRACT: Configuration management for YATG
67  
68  
69 __END__
70 =pod
71  
72 =head1 NAME
73  
74 YATG::Config - Configuration management for YATG
75  
76 =head1 VERSION
77  
78 version 5.140510
79  
80 =head1 REQUIRED CONFIGURATION
81  
82 C<yatg_updater> expects one command line argument, which is its main
83 configuration file. This must be in a format recognizable to L<Config::Any>,
84 and you must use a file name suffix to give that module a hint.
85  
86 There is a fairly complete example of this configuration file in the
87 C<examples/> folder of this distribution - look for the C<yatg.yml> file. The
88 file must parse out to an anonymous hash of hashes, as in the example.
89  
90 Let's first consider the C<yatg> key/value, which is the main configuration
91 area.
92  
93 =head2 oids
94  
95 This is a hash, with keys being the Leaf Name of an SNMP OID. This tells
96 C<yatg_updater> the list of OIDs which you would like gathering from each
97 network device. The value for each leaf name key is a list of magic words
98 which tell C<yatg_updater> whether to get the OID, and what to do with the
99 results. Some of the magic words are mutually exclusive.
100  
101 # example key and "magic words" list value
102 yatg:
103 oids:
104 ifOperStatus: [disk, ifindex]
105  
106 =head3 Storage
107  
108 These are the storage methods for the results, and an OID without one of these
109 magic words will be ignored. Multiple storage methods can be given for any OID.
110  
111 =over 4
112  
113 =item C<stdout>
114  
115 This means to use the L<Data::Printer> to print results. It's good for
116 testing.
117  
118 See L<YATG::Store::STDOUT>.
119  
120 =item C<disk>
121  
122 Disk storage means to create a file for each OID of each port on each device.
123 It is very fast and efficient by design, and most useful for long-term
124 historical data such as port traffic counters.
125  
126 See L<YATG::Store::Disk>.
127  
128 =item C<memcached>
129  
130 If you don't need data history, then this module is a better alternative than
131 disk-based storage, because of its speed. A memcached server is required of
132 course.
133  
134 See L<YATG::Store::Memcached>.
135  
136 =item C<rpc>
137  
138 This is merely an extension to the Disk storage module which allows
139 C<yatg_updater> to use disk on another machine. You can think of it as an
140 RPC-based alternative to network mounting a filesystem. On the remote host,
141 the Disk module is then used for storage.
142  
143 See L<YATG::Store::RPC>.
144  
145 =item C<nsca>
146  
147 If you wish to submit data to Nagios as a passive service check result, then
148 this method can be configured to contact an NSCA daemon on your Nagios server.
149  
150 See L<YATG::Store::NSCA>.
151  
152 =back
153  
154 =head3 Interface Indexed OIDs
155  
156 Although C<yatg_updater> will happily poll single value or plain indexed OIDs,
157 you can give it a hint that there is an interface-indexed OID in use.
158  
159 In that case, C<yatg_updater> will make sure that C<IfDescr> and
160 C<IfAdminStatus> are retrieved from the device, and results will be keyed by
161 human-friendly names (e.g. C<FastEthernet2/1>) rather than SNMP interface
162 indexes (e.g. C<10101>).
163  
164 Furthermore, only results for "interesting" interfaces will be stored. This is
165 defined as interfaces which are administratively configured to the "up" state,
166 and whose name does not match an exclusion list (various private
167 sub-interfaces, which are uninteresting). This measure will save you time when
168 storing results to disk as you only save what is interesting. If you store
169 results for a port, then shut it down and some time later start it up again,
170 the results file will be padded out for the period of shut-down time and
171 appended with the new results.
172  
173 Being indexed by interface is something C<yatg_updater> cannot work out for
174 itself for an OID, so provide the C<ifindex> magic word to enable this
175 feature.
176  
177 =head3 IP address filtering
178  
179 We have not yet covered how C<yatg_updater> obtains its list of devices to
180 poll, but for now all you need to know is that by default all listed leaf
181 names will be polled on all devices.
182  
183 You can however provide magic words to override this behaviour and reduce the
184 device space to be polled for a leaf name. Each of these magic words may
185 appear more than once:
186  
187 =over 4
188  
189 =item C<192.2.1.10> or C<192.1.1.0/24>
190  
191 Any IP address or IP subnet will be taken as a restriction placed upon the
192 default list of device IPs, for this OID only.
193  
194 Not providing an explicit IP address or IP subnet means the OID will be polled
195 on all devices in the default list.
196  
197 =item C<!192.2.1.10> or C<!192.1.1.0/24>
198  
199 Using an exclamation mark at the head of the IP address introduces an
200 exclusion filter upon the cached list of IP addresses.
201  
202 This prevents the OID from being checked on the given devices, even if the
203 device IP is also given in a magic word, as above.
204  
205 =back
206  
207 In case it is not clear, an IP address and an IP subnet are no different - a
208 C</32> subnet mask is assumed in the case of an IP address.
209  
210 =head2 communities
211  
212 Provide a list of SNMP community strings to the system using this parameter.
213 For each device, at startup, C<yatg_updater> will work out which community to
214 use and cache that for subsequent SNMP polling. For example:
215  
216 yatg:
217 communities: [public, anotherone]
218  
219 The default value for this is C<[ public ]>.
220  
221 =head2 dbi_connect and the list of devices
222  
223 At start-up, C<yatg_updater> needs to be given a list of device IPs which it
224 should poll with SNMP. C<yatg_updater> will make a connection to a database
225 and gather IPs.
226  
227 By default the SQL query is set for use with NetDisco, so if you use that
228 system you only need alter the DBI connection parameters (password, etc) in
229 the C<dbi_connect> value in the example configuration file.
230  
231 If you want to use a different SQL query, add a new key and value to the
232 configuration:
233  
234 yatg:
235 dbi_ip_query: 'SELECT ip FROM device;'
236  
237 The query must return a single list of IPs (suitable for L<DBI>'s
238 C<selectcol_arrayref>). If you don't have a back-end database with such
239 information, then install SQLite and quickly set one up (see L<YATG::Tutorial>
240 for help). It's good practice for asset management, if nothing else.
241  
242 =head2 mibdirs
243  
244 If you use NetDisco, and have the MIB files from that distribution installed
245 in C</usr/share/netdisco/mibs/...> then you can probably ignore this as the
246 default will work.
247  
248 Otherwise, you must provide this application with all the MIBs required to
249 translate leaf names to OIDs and get data types for polled values. This key
250 takes a list of directories on your system which contain MIB files. They will
251 all be loaded when C<yatg_updater> starts, so only specify what you need
252 otherwise that will take a long time.
253  
254 Here is an example in YAML:
255  
256 yatg:
257 mibdirs:
258 ['/usr/share/netdisco/mibs/cisco',
259 '/usr/share/netdisco/mibs/rfc',
260 '/usr/share/netdisco/mibs/net-snmp']
261  
262 =head1 OPTIONAL CONFIGURATION
263  
264 There are some additional, optional keys for the C<yatg> section:
265  
266 =over 4
267  
268 =item C<interval>
269  
270 C<yatg_updater> polls all devices at a given interval. Provide a number of
271 settings to this key if you want to override the default of 300 (5 minutes).
272 An alternative is the C<YATG_INTERVAL> environment setting.
273  
274 =item C<timeout>
275  
276 If the poller does not return data from all devices within C<timeout> seconds,
277 then the application will die. The default is 280. You should always have a
278 little head-room between the C<timeout> and C<interval>.
279  
280 =item C<max_pollers>
281  
282 This system uses C<SNMP::Effective> for the SNMP polling, which is a fast,
283 lightweight wrapper to the C<SNMP> perl libraries. C<SNMP::Effective> polls
284 asynchronously and you can set the maximum number of polls which are happening
285 at once using this key. The default is 20 which is reasonably for any modern
286 computer.
287  
288 =item C<newhosts_watch>
289  
290 As YATG is a long-running process, you might occasionally want to update its
291 list of hosts to monitor. Of course you can send a C<SIGHUP> and have YATG
292 reload entirely, but this can be slow because of the re-checking of SNMP
293 communities, and also requires an external process to send the signal.
294  
295 If the YATG config has not changed, but you wish to update the list of
296 monitored hosts, then set C<newhosts_watch> to the name of a file. The
297 modification time of the file is watched and if it updates then YATG retrieves
298 a new set of hosts (and host names and interface filters, if configured), on
299 the next polling run.
300  
301 =item C<debug>
302  
303 If this key has a true value, C<yatg_updater> will print out various messages
304 on standard output, instead of using a log file. It's handy for testing, and
305 defaults to false of course. An alternative is the C<YATG_DEBUG> environment
306 setting.
307  
308 =back
309  
310 =head1 LOGGING CONFIGURATION
311  
312 This module uses C<Log::Dispatch::Syslog> for logging, and by default will log
313 timing data to your system's syslog service. The following parameters can be
314 overridden in a section at the same level as C<oids>, but called
315 C<log_dispatch_syslog>:
316  
317 =over 4
318  
319 =item C<name> and C<ident>
320  
321 These are the tokens used to identify the process to syslog, and both default
322 to C<yatg>.
323  
324 =item C<min_level>
325  
326 By default the logging level will be C<info> so override this to change that.
327  
328 =item C<facility>
329  
330 By default the syslog facility will be C<local1> so override this to change
331 that.
332  
333 =back
334  
335 Here is an example of what you might do:
336  
337 log_dispatch_syslog:
338 name: 'my_app'
339 ident: 'my_app'
340 min_level: 'warning'
341 facility: 'local4'
342  
343 =head1 SEE ALSO
344  
345 =over 4
346  
347 =item L<http://www.netdisco.org/>
348  
349 =item L<http://www.sqlite.org/>
350  
351 =back
352  
353 =head1 AUTHOR
354  
355 Oliver Gorwits <oliver@cpan.org>
356  
357 =head1 COPYRIGHT AND LICENSE
358  
359 This software is copyright (c) 2014 by University of Oxford.
360  
361 This is free software; you can redistribute it and/or modify it under
362 the same terms as the Perl 5 programming language system itself.
363  
364 =cut
365  
« RPC/Serialized/Handler/YATG/Store.pm ↑ Summary