File Coverage

blib/lib/Net/SNMP/HostInfo.pm
Criterion Covered Total %
statement 30 81 37.0
branch 0 18 0.0
condition 0 17 0.0
subroutine 10 14 71.4
pod 2 3 66.6
total 42 133 31.5


line stmt bran cond sub pod time code
1             package Net::SNMP::HostInfo;
2            
3             =head1 NAME
4            
5             Net::SNMP::HostInfo - Access the IP statistics of a MIB-II host
6            
7             =head1 SYNOPSIS
8            
9             use Net::SNMP::HostInfo;
10            
11             $host = shift || 'localhost';
12             $password = shift || 'public';
13            
14             $hostinfo = Net::SNMP::HostInfo->new(Hostname => $host,
15             Community => $password);
16            
17             print "Packets Received = ", $hostinfo->ipInReceives, "\n";
18             print "Output Requests = ", $hostinfo->ipOutRequests, "\n";
19            
20             print "TCP Segments Received = ", $hostinfo->tcpInSegs, "\n";
21             print "TCP Segments Sent = ", $hostinfo->tcpOutSegs, "\n";
22            
23             print "UDP Datagrams Received = ", $hostinfo->udpInDatagrams, "\n";
24             print "UDP Datagrams Sent = ", $hostinfo->udpOutDatagrams, "\n";
25            
26             =head1 DESCRIPTION
27            
28             Net::SNMP::HostInfo is a class that simplifies access to the
29             IP, TCP, and UDP information of a MIB-II compliant network host,
30             such as a router or a PC.
31            
32             You can use it to retrieve numerous statistics on IP, ICMP, TCP, and UDP,
33             as well as the IP routing table (L),
34             the IP address table (L),
35             the ARP table (L),
36             the TCP connection table (L),
37             and the UDP listener table (L).
38             Browse the list of available methods to see what values are available.
39            
40             =cut
41            
42             # Base OIDs for the MIB-II groups
43             # 1.3.6.1.2.1.1 = system
44             # 1.3.6.1.2.1.2 = interfaces (implemented by Net::SNMP::Interfaces)
45             # 1.3.6.1.2.1.4 = ip
46             # 1.3.6.1.2.1.5 = icmp
47             # 1.3.6.1.2.1.6 = tcp
48             # 1.3.6.1.2.1.7 = udp
49             # 1.3.6.1.2.1.11 = snmp (not implemented yet)
50            
51 1     1   7832 use 5.006;
  1         4  
  1         39  
52 1     1   5 use strict;
  1         2  
  1         29  
53 1     1   5 use warnings;
  1         77  
  1         40  
54            
55 1     1   822 use Net::SNMP::HostInfo::IpAddrEntry;
  1         2  
  1         31  
56 1     1   763 use Net::SNMP::HostInfo::IpRouteEntry;
  1         2  
  1         51  
57 1     1   850 use Net::SNMP::HostInfo::IpNetToMediaEntry;
  1         2  
  1         87  
58 1     1   580 use Net::SNMP::HostInfo::TcpConnEntry;
  1         3  
  1         31  
59 1     1   597 use Net::SNMP::HostInfo::UdpEntry;
  1         4  
  1         39  
60 1     1   1560 use Net::SNMP;
  1         117130  
  1         155  
61 1     1   8 use Carp;
  1         3  
  1         1028  
62            
63             our $VERSION = '0.04';
64             our $AUTOLOAD;
65            
66             my %oids = (
67             sysDescr => '1.3.6.1.2.1.1.1',
68             sysObjectID => '1.3.6.1.2.1.1.2',
69             sysUpTime => '1.3.6.1.2.1.1.3',
70             sysContact => '1.3.6.1.2.1.1.4',
71             sysName => '1.3.6.1.2.1.1.5',
72             sysLocation => '1.3.6.1.2.1.1.6',
73             sysServices => '1.3.6.1.2.1.1.7',
74            
75             ipForwarding => '1.3.6.1.2.1.4.1',
76             ipDefaultTTL => '1.3.6.1.2.1.4.2',
77             ipInReceives => '1.3.6.1.2.1.4.3',
78             ipInHdrErrors => '1.3.6.1.2.1.4.4',
79             ipInAddrErrors => '1.3.6.1.2.1.4.5',
80             ipForwDatagrams => '1.3.6.1.2.1.4.6',
81             ipInUnknownProtos => '1.3.6.1.2.1.4.7',
82             ipInDiscards => '1.3.6.1.2.1.4.8',
83             ipInDelivers => '1.3.6.1.2.1.4.9',
84             ipOutRequests => '1.3.6.1.2.1.4.10',
85             ipOutDiscards => '1.3.6.1.2.1.4.11',
86             ipOutNoRoutes => '1.3.6.1.2.1.4.12',
87             ipReasmTimeout => '1.3.6.1.2.1.4.13',
88             ipReasmReqds => '1.3.6.1.2.1.4.14',
89             ipReasmOKs => '1.3.6.1.2.1.4.15',
90             ipReasmFails => '1.3.6.1.2.1.4.16',
91             ipFragOKs => '1.3.6.1.2.1.4.17',
92             ipFragFails => '1.3.6.1.2.1.4.18',
93             ipFragCreates => '1.3.6.1.2.1.4.19',
94             # ipAddrTable => '1.3.6.1.2.1.4.20',
95             # ipRouteTable => '1.3.6.1.2.1.4.21',
96             # ipNetToMediaTable => '1.3.6.1.2.1.4.22',
97             ipRoutingDiscards => '1.3.6.1.2.1.4.23',
98            
99             icmpInMsgs => '1.3.6.1.2.1.5.1',
100             icmpInErrors => '1.3.6.1.2.1.5.2',
101             icmpInDestUnreachs => '1.3.6.1.2.1.5.3',
102             icmpInTimeExcds => '1.3.6.1.2.1.5.4',
103             icmpInParmProbs => '1.3.6.1.2.1.5.5',
104             icmpInSrcQuenchs => '1.3.6.1.2.1.5.6',
105             icmpInRedirects => '1.3.6.1.2.1.5.7',
106             icmpInEchos => '1.3.6.1.2.1.5.8',
107             icmpInEchoReps => '1.3.6.1.2.1.5.9',
108             icmpInTimestamps => '1.3.6.1.2.1.5.10',
109             icmpInTimestampReps => '1.3.6.1.2.1.5.11',
110             icmpInAddrMasks => '1.3.6.1.2.1.5.12',
111             icmpInAddrMaskReps => '1.3.6.1.2.1.5.13',
112             icmpOutMsgs => '1.3.6.1.2.1.5.14',
113             icmpOutErrors => '1.3.6.1.2.1.5.15',
114             icmpOutDestUnreachs => '1.3.6.1.2.1.5.16',
115             icmpOutTimeExcds => '1.3.6.1.2.1.5.17',
116             icmpOutParmProbs => '1.3.6.1.2.1.5.18',
117             icmpOutSrcQuenchs => '1.3.6.1.2.1.5.19',
118             icmpOutRedirects => '1.3.6.1.2.1.5.20',
119             icmpOutEchos => '1.3.6.1.2.1.5.21',
120             icmpOutEchoReps => '1.3.6.1.2.1.5.22',
121             icmpOutTimestamps => '1.3.6.1.2.1.5.23',
122             icmpOutTimestampReps => '1.3.6.1.2.1.5.24',
123             icmpOutAddrMasks => '1.3.6.1.2.1.5.25',
124             icmpOutAddrMaskReps => '1.3.6.1.2.1.5.26',
125            
126             tcpRtoAlgorithm => '1.3.6.1.2.1.6.1',
127             tcpRtoMin => '1.3.6.1.2.1.6.2',
128             tcpRtoMax => '1.3.6.1.2.1.6.3',
129             tcpMaxConn => '1.3.6.1.2.1.6.4',
130             tcpActiveOpens => '1.3.6.1.2.1.6.5',
131             tcpPassiveOpens => '1.3.6.1.2.1.6.6',
132             tcpAttemptFails => '1.3.6.1.2.1.6.7',
133             tcpEstabResets => '1.3.6.1.2.1.6.8',
134             tcpCurrEstab => '1.3.6.1.2.1.6.9',
135             tcpInSegs => '1.3.6.1.2.1.6.10',
136             tcpOutSegs => '1.3.6.1.2.1.6.11',
137             tcpRetransSegs => '1.3.6.1.2.1.6.12',
138             # tcpConnTable => '1.3.6.1.2.1.6.13',
139             tcpInErrs => '1.3.6.1.2.1.6.14',
140             tcpOutRsts => '1.3.6.1.2.1.6.15',
141            
142             udpInDatagrams => '1.3.6.1.2.1.7.1',
143             udpNoPorts => '1.3.6.1.2.1.7.2',
144             udpInErrors => '1.3.6.1.2.1.7.3',
145             udpOutDatagrams => '1.3.6.1.2.1.7.4',
146             # udpTable => '1.3.6.1.2.1.7.5',
147            
148             );
149            
150             my %decodedObjects = (
151             ipForwarding => { qw/1 forwarding 2 not-forwarding/ },
152             tcpRtoAlgorithm => { qw/1 other 2 constant 3 rsre 4 vanj/ },
153             );
154            
155             my %tables = (
156             ipAddrTable =>
157             [qw/1.3.6.1.2.1.4.20.1.1 Net::SNMP::HostInfo::IpAddrEntry C4/],
158             ipRouteTable =>
159             [qw/1.3.6.1.2.1.4.21.1.1 Net::SNMP::HostInfo::IpRouteEntry C4/],
160             ipNetToMediaTable =>
161             [qw/1.3.6.1.2.1.4.22.1.1 Net::SNMP::HostInfo::IpNetToMediaEntry NC4/],
162             tcpConnTable =>
163             [qw/1.3.6.1.2.1.6.13.1.1 Net::SNMP::HostInfo::TcpConnEntry C4nC4n/],
164             udpTable =>
165             [qw/1.3.6.1.2.1.7.5.1.1 Net::SNMP::HostInfo::UdpEntry C4n/],
166             );
167            
168             # Preloaded methods go here.
169            
170             =head1 METHODS
171            
172             =over
173            
174             =item new
175            
176             Creates a new Net::SNMP::HostInfo object. You can specify the
177             following optional parameters:
178            
179             =over
180            
181             =item Hostname => $hostname
182            
183             The hostname of the target device; defaults to 'localhost'.
184            
185             =item Community => $community
186            
187             The community string of the target device; defaults to 'public'.
188            
189             =item Session => $session
190            
191             An alternative to specifying the Hostname and Community
192             parameters: you can use an existing Net::SNMP session for
193             all Net::SNMP::HostInfo queries.
194            
195             =item Decode => $decode
196            
197             If true, certain values, such as ipForwarding, will be
198             returned as strings instead of numbers. For example,
199             ipForwarding will be returned as 'forwarding(1)' or
200             'not-forwarding(2)'. The following values are affected:
201            
202             ipForwarding
203             tcpRtoAlgorithm
204             ipNetToMediaType (ipNetToMediaTable)
205             ipRouteType (ipRouteTable)
206             ipRouteProto (ipRouteTable)
207             tcpConnState (tcpConnTable)
208            
209             Additionally, ethernet addresses returned by
210             ipNetToMediaPhysAddress will be prettified.
211            
212             =back
213            
214             Here are some examples:
215            
216             $hostinfo = Net::SNMP::HostInfo->new(Hostname => 'quartz',
217             Community => 'crystal',
218             Decode => 1);
219            
220             $interfaces = Net::SNMP::Interfaces->new(Hostname => 'quartz',
221             Community => 'crystal');
222             $hostinfo = Net::SNMP::HostInfo->new(Session => $interfaces->session,
223             Decode => 1);
224            
225             ($session, $error) = Net::SNMP->session(-hostname => 'quartz',
226             -community => 'crystal');
227             $hostinfo = Net::SNMP::HostInfo->new(Session => $session,
228             Decode => 1);
229            
230             =cut
231            
232             sub new
233             {
234 0     0 1   my $class = shift;
235            
236 0           my %args = @_;
237            
238 0           my $self = {};
239            
240 0   0       $self->{_decode} = $args{Decode} || 0;
241            
242 0           my ($session, $error);
243 0 0 0       if ($args{Session} && ref($args{Session}) eq "Net::SNMP") {
244             # Use existing Net::SNMP session
245 0           $session = $args{Session};
246             } else {
247             # Create new Net::SNMP session
248 0   0       $self->{_hostname} = $args{Hostname} || 'localhost';
249 0   0       $self->{_community} = $args{Community} || 'public';
250 0   0       $self->{_port} = $args{Port} || 161;
251            
252 0           ($session, $error) = Net::SNMP->session(
253             -hostname => $self->{_hostname},
254             -community => $self->{_community},
255             -port => $self->{_port}
256             );
257             }
258            
259             # check that we have a session with an SNMP host
260 0 0         if (defined $session) {
261 0           my $oid = '1.3.6.1.2.1.1.5.0'; # sysName
262 0           my $response = $session->get_request($oid);
263            
264 0 0         if (defined $response) {
265             # we're okay
266             } else {
267 0           croak "Could not establish session to host";
268             }
269             } else {
270 0           croak "Could not establish session to host";
271             }
272            
273 0           $self->{_session} = $session;
274            
275 0           bless $self, $class;
276 0           return $self;
277             }
278            
279             =item session
280            
281             Returns the Net::SNMP session object being used.
282             The session can be then used for other SNMP queries.
283            
284             =cut
285            
286 0     0 1   sub session { return $_[0]->{_session}; }
287            
288             =item ipForwarding
289            
290             "The indication of whether this entity is acting
291             as an IP gateway in respect to the forwarding of
292             datagrams received by, but not addressed to, this
293             entity. IP gateways forward datagrams. IP hosts
294             do not (except those source-routed via the host).
295            
296             Note that for some managed nodes, this object may
297             take on only a subset of the values possible.
298             Accordingly, it is appropriate for an agent to
299             return a `badValue' response if a management
300             station attempts to change this object to an
301             inappropriate value."
302            
303             Possible values are:
304            
305             forwarding(1),
306             not-forwarding(2)
307            
308             =item ipDefaultTTL
309            
310             "The default value inserted into the Time-To-Live
311             field of the IP header of datagrams originated at
312             this entity, whenever a TTL value is not supplied
313             by the transport layer protocol."
314            
315             =item ipInReceives
316            
317             "The total number of input datagrams received from
318             interfaces, including those received in error."
319            
320             =item ipInHdrErrors
321            
322             "The number of input datagrams discarded due to
323             errors in their IP headers, including bad
324             checksums, version number mismatch, other format
325             errors, time-to-live exceeded, errors discovered
326             in processing their IP options, etc."
327            
328             =item ipInAddrErrors
329            
330             "The number of input datagrams discarded because
331             the IP address in their IP header's destination
332             field was not a valid address to be received at
333             this entity. This count includes invalid
334             addresses (e.g., 0.0.0.0) and addresses of
335             unsupported Classes (e.g., Class E). For entities
336             which are not IP Gateways and therefore do not
337             forward datagrams, this counter includes datagrams
338             discarded because the destination address was not
339             a local address."
340            
341             =item ipForwDatagrams
342            
343             "The number of input datagrams for which this
344             entity was not their final IP destination, as a
345             result of which an attempt was made to find a
346             route to forward them to that final destination.
347             In entities which do not act as IP Gateways, this
348             counter will include only those packets which were
349             Source-Routed via this entity, and the Source-
350             Route option processing was successful."
351            
352             =item ipInUnknownProtos
353            
354             "The number of locally-addressed datagrams
355             received successfully but discarded because of an
356             unknown or unsupported protocol."
357            
358             =item ipInDiscards
359            
360             "The number of input IP datagrams for which no
361             problems were encountered to prevent their
362             continued processing, but which were discarded
363             (e.g., for lack of buffer space). Note that this
364             counter does not include any datagrams discarded
365             while awaiting re-assembly."
366            
367             =item ipInDelivers
368            
369             "The total number of input datagrams successfully
370             delivered to IP user-protocols (including ICMP)."
371            
372             =item ipOutRequests
373            
374             "The total number of IP datagrams which local IP
375             user-protocols (including ICMP) supplied to IP in
376             requests for transmission. Note that this counter
377             does not include any datagrams counted in
378             ipForwDatagrams."
379            
380             =item ipOutDiscards
381            
382             "The number of output IP datagrams for which no
383             problem was encountered to prevent their
384             transmission to their destination, but which were
385             discarded (e.g., for lack of buffer space). Note
386             that this counter would include datagrams counted
387             in ipForwDatagrams if any such packets met this
388             (discretionary) discard criterion."
389            
390             =item ipOutNoRoutes
391            
392             "The number of IP datagrams discarded because no
393             route could be found to transmit them to their
394             destination. Note that this counter includes any
395             packets counted in ipForwDatagrams which meet this
396             `no-route' criterion. Note that this includes any
397             datagarms which a host cannot route because all of
398             its default gateways are down."
399            
400             =item ipReasmTimeout
401            
402             "The maximum number of seconds which received
403             fragments are held while they are awaiting
404             reassembly at this entity."
405            
406             =item ipReasmReqds
407            
408             "The number of IP fragments received which needed
409             to be reassembled at this entity."
410            
411             =item ipReasmOKs
412            
413             "The number of IP datagrams successfully re-
414             assembled."
415            
416             =item ipReasmFails
417            
418             "The number of failures detected by the IP re-
419             assembly algorithm (for whatever reason: timed
420             out, errors, etc). Note that this is not
421             necessarily a count of discarded IP fragments
422             since some algorithms (notably the algorithm in
423             RFC 815) can lose track of the number of fragments
424             by combining them as they are received."
425            
426             =item ipFragOKs
427            
428             "The number of IP datagrams that have been
429             successfully fragmented at this entity."
430            
431             =item ipFragFails
432            
433             "The number of IP datagrams that have been
434             discarded because they needed to be fragmented at
435             this entity but could not be, e.g., because their
436             Don't Fragment flag was set."
437            
438             =item ipFragCreates
439            
440             "The number of IP datagram fragments that have
441             been generated as a result of fragmentation at
442             this entity."
443            
444             =item ipAddrTable
445            
446             "The table of addressing information relevant to
447             this entity's IP addresses."
448            
449             Returns a list of Net::SNMP::HostInfo::IpAddrEntry objects.
450            
451             =item ipRouteTable
452            
453             "This entity's IP Routing table."
454            
455             Returns a list of Net::SNMP::HostInfo::IpRouteEntry objects.
456            
457             =item ipNetToMediaTable
458            
459             "The IP Address Translation table used for mapping
460             from IP addresses to physical addresses."
461            
462             Returns a list of Net::SNMP::HostInfo::IpNetToMediaEntry objects.
463            
464             =item ipRoutingDiscards
465            
466             "The number of routing entries which were chosen
467             to be discarded even though they are valid. One
468             possible reason for discarding such an entry could
469             be to free-up buffer space for other routing
470             entries."
471            
472             =item icmpInMsgs
473            
474             "The total number of ICMP messages which the
475             entity received. Note that this counter includes
476             all those counted by icmpInErrors."
477            
478             =item icmpInErrors
479            
480             "The number of ICMP messages which the entity
481             received but determined as having ICMP-specific
482             errors (bad ICMP checksums, bad length, etc.)."
483            
484             =item icmpInDestUnreachs
485            
486             "The number of ICMP Destination Unreachable
487             messages received."
488            
489             =item icmpInTimeExcds
490            
491             "The number of ICMP Time Exceeded messages
492             received."
493            
494             =item icmpInParmProbs
495            
496             "The number of ICMP Parameter Problem messages
497             received."
498            
499             =item icmpInSrcQuenchs
500            
501             "The number of ICMP Source Quench messages
502             received."
503            
504             =item icmpInRedirects
505            
506             "The number of ICMP Redirect messages received."
507            
508             =item icmpInEchos
509            
510             "The number of ICMP Echo (request) messages
511             received."
512            
513             =item icmpInEchoReps
514            
515             "The number of ICMP Echo Reply messages received."
516            
517             =item icmpInTimestamps
518            
519             "The number of ICMP Timestamp (request) messages
520             received."
521            
522             =item icmpInTimestampReps
523            
524             "The number of ICMP Timestamp Reply messages
525             received."
526            
527             =item icmpInAddrMasks
528            
529             "The number of ICMP Address Mask Request messages
530             received."
531            
532             =item icmpInAddrMaskReps
533            
534             "The number of ICMP Address Mask Reply messages
535             received."
536            
537             =item icmpOutMsgs
538            
539             "The total number of ICMP messages which this
540             entity attempted to send. Note that this counter
541             includes all those counted by icmpOutErrors."
542            
543             =item icmpOutErrors
544            
545             "The number of ICMP messages which this entity did
546             not send due to problems discovered within ICMP
547             such as a lack of buffers. This value should not
548             include errors discovered outside the ICMP layer
549             such as the inability of IP to route the resultant
550             datagram. In some implementations there may be no
551             types of error which contribute to this counter's
552             value."
553            
554             =item icmpOutDestUnreachs
555            
556             "The number of ICMP Destination Unreachable
557             messages sent."
558            
559             =item icmpOutTimeExcds
560            
561             "The number of ICMP Time Exceeded messages sent."
562            
563             =item icmpOutParmProbs
564            
565             "The number of ICMP Parameter Problem messages
566             sent."
567            
568             =item icmpOutSrcQuenchs
569            
570             "The number of ICMP Source Quench messages sent."
571            
572             =item icmpOutRedirects
573            
574             "The number of ICMP Redirect messages sent. For a
575             host, this object will always be zero, since hosts
576             do not send redirects."
577            
578             =item icmpOutEchos
579            
580             "The number of ICMP Echo (request) messages sent."
581            
582             =item icmpOutEchoReps
583            
584             "The number of ICMP Echo Reply messages sent."
585            
586             =item icmpOutTimestamps
587            
588             "The number of ICMP Timestamp (request) messages
589             sent."
590            
591             =item icmpOutTimestampReps
592            
593             "The number of ICMP Timestamp Reply messages
594             sent."
595            
596             =item icmpOutAddrMasks
597            
598             "The number of ICMP Address Mask Request messages
599             sent."
600            
601             =item icmpOutAddrMaskReps
602            
603             "The number of ICMP Address Mask Reply messages
604             sent."
605            
606             =item tcpRtoAlgorithm
607            
608             "The algorithm used to determine the timeout value
609             used for retransmitting unacknowledged octets."
610            
611             Possible values are:
612            
613             other(1),
614             constant(2),
615             rsre(3),
616             vanj(4)
617            
618             =item tcpRtoMin
619            
620             "The minimum value permitted by a TCP
621             implementation for the retransmission timeout,
622             measured in milliseconds. More refined semantics
623             for objects of this type depend upon the algorithm
624             used to determine the retransmission timeout. In
625             particular, when the timeout algorithm is rsre(3),
626             an object of this type has the semantics of the
627             LBOUND quantity described in RFC 793."
628            
629             =item tcpRtoMax
630            
631             "The maximum value permitted by a TCP
632             implementation for the retransmission timeout,
633             measured in milliseconds. More refined semantics
634             for objects of this type depend upon the algorithm
635             used to determine the retransmission timeout. In
636             particular, when the timeout algorithm is rsre(3),
637             an object of this type has the semantics of the
638             UBOUND quantity described in RFC 793."
639            
640             =item tcpMaxConn
641            
642             "The limit on the total number of TCP connections
643             the entity can support. In entities where the
644             maximum number of connections is dynamic, this
645             object should contain the value -1."
646            
647             =item tcpActiveOpens
648            
649             "The number of times TCP connections have made a
650             direct transition to the SYN-SENT state from the
651             CLOSED state."
652            
653             =item tcpPassiveOpens
654            
655             "The number of times TCP connections have made a
656             direct transition to the SYN-RCVD state from the
657             LISTEN state."
658            
659             =item tcpAttemptFails
660            
661             "The number of times TCP connections have made a
662             direct transition to the CLOSED state from either
663             the SYN-SENT state or the SYN-RCVD state, plus the
664             number of times TCP connections have made a direct
665             transition to the LISTEN state from the SYN-RCVD
666             state."
667            
668             =item tcpEstabResets
669            
670             "The number of times TCP connections have made a
671             direct transition to the CLOSED state from either
672             the ESTABLISHED state or the CLOSE-WAIT state."
673            
674             =item tcpCurrEstab
675            
676             "The number of TCP connections for which the
677             current state is either ESTABLISHED or CLOSE-
678             WAIT."
679            
680             =item tcpInSegs
681            
682             "The total number of segments received, including
683             those received in error. This count includes
684             segments received on currently established
685             connections."
686            
687             =item tcpOutSegs
688            
689             "The total number of segments sent, including
690             those on current connections but excluding those
691             containing only retransmitted octets."
692            
693             =item tcpRetransSegs
694            
695             "The total number of segments retransmitted - that
696             is, the number of TCP segments transmitted
697             containing one or more previously transmitted
698             octets."
699            
700             =item tcpConnTable
701            
702             "A table containing TCP connection-specific
703             information."
704            
705             Returns a list of Net::SNMP::HostInfo::TcpConnEntry objects.
706            
707             =item tcpInErrs
708            
709             "The total number of segments received in error
710             (e.g., bad TCP checksums)."
711            
712             =item tcpOutRsts
713            
714             "The number of TCP segments sent containing the
715             RST flag."
716            
717             =item udpInDatagrams
718            
719             "The total number of UDP datagrams delivered to
720             UDP users."
721            
722             =item udpNoPorts
723            
724             "The total number of received UDP datagrams for
725             which there was no application at the destination
726             port."
727            
728             =item udpInErrors
729            
730             "The number of received UDP datagrams that could
731             not be delivered for reasons other than the lack
732             of an application at the destination port."
733            
734             =item udpOutDatagrams
735            
736             "The total number of UDP datagrams sent from this
737             entity."
738            
739             =item udpTable
740            
741             "A table containing UDP listener information."
742            
743             Returns a list of Net::SNMP::HostInfo::UdpEntry objects.
744            
745             =back
746            
747             =cut
748            
749             sub AUTOLOAD
750             {
751 0     0     my $self = shift;
752            
753            
754 0 0         return if $AUTOLOAD =~ /DESTROY$/;
755            
756 0           my ($name) = $AUTOLOAD =~ /::([^:]+)$/;
757             #print "Called $name\n";
758            
759 0 0         if (exists $tables{$name}) {
760 0           my ($baseoid, $class, $indexTemplate) = @{$tables{$name}};
  0            
761 0           return $self->getTable($baseoid, $class, $indexTemplate);
762             }
763            
764 0 0         if (!exists $oids{$name}) {
765 0           croak "Can't locate object method '$name'";
766             }
767            
768 0           my $oid = $oids{$name} . ".0";
769            
770             #print "Trying $oid\n";
771            
772 0           my $response = $self->{_session}->get_request($oid);
773            
774 0 0         if ($response) {
775 0           my $value = $response->{$oid};
776            
777 0 0 0       if ($self->{_decode} &&
      0        
778             exists $decodedObjects{$name} &&
779             exists $decodedObjects{$name}{$value}) {
780 0           return $decodedObjects{$name}{$value}."($value)";
781             } else {
782 0           return $value;
783             }
784             } else {
785 0           return undef;
786             }
787             }
788            
789             # The ipAddrTable is indexed by ipAdEntAddr
790             # |------baseoid------|--index---|
791             # 1.3.6.1.2.1.4.20.1.1.192.168.0.1 = '192.168.0.1'
792            
793             # The ipRouteTable is indexed by ipRouteDest
794             # |------baseoid------|---index----|
795             # 1.3.6.1.2.1.4.21.1.1.192.168.0.255 = '192.168.0.255'
796            
797             # The index to the ipNetToMediaTable is formed of two values:
798             # ipNetToMediaIfIndex
799             # ipNetToMediaNetAddress
800             # |------baseoid------|---index----|
801             # 1.3.6.1.2.1.4.22.1.1.2.192.168.0.1 = '2'
802            
803             # The index to the tcpConnTable is formed of four values:
804             # tcpConnLocalAddress
805             # tcpConnLocalPort
806             # tcpConnRemAddress
807             # tcpConnRemPort
808             # |------baseoid------|------------index-------------|
809             # 1.3.6.1.2.1.6.13.1.1.192.168.0.1.12345.0.0.0.0.57528 = '2'
810            
811             # The index to the udpTable is formed of two values:
812             # udpLocalAddress
813             # udpLocalPort
814             # |-----baseoid------|--------------|
815             # 1.3.6.1.2.1.7.5.1.1.192.168.0.1.123 = '192.168.0.1'
816            
817             sub getTable
818             {
819 0     0 0   my $self = shift;
820 0           my $baseoid = shift;
821 0           my $class = shift; # class for each entry in the table
822 0           my $indexTemplate = shift; # how to pack the object's index for sorting
823            
824 0           my $response = $self->{_session}->get_table(-baseoid => $baseoid);
825             #use Data::Dumper; print Dumper($response);
826            
827 0           my @table = ();
828 0           my @indices = sort { pack($indexTemplate, split(/\./, $a)) cmp
  0            
829             pack($indexTemplate, split(/\./, $b)) }
830 0           map { /^$baseoid\.(.*)/ } keys %$response;
831             #for (@indices) { print "$_\n"; }
832            
833 0           for my $index (@indices) {
834 0           my %args = (
835             Index => $index,
836             Decode => $self->{_decode},
837             Session => $self->{_session},
838             );
839 0           push @table, $class->new(%args);
840             }
841            
842 0 0         return wantarray ? @table : \@table;
843             }
844            
845             1;
846            
847             __END__