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