1 # Copyright (C) 2003 Shawn Ferry
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17 # $Id: UcdSnmp.pm,v 1.1 2010-12-27 00:03:47 ivan Exp $
18 # Shawn Ferry <sferry at sevenspace dot com> <lalartu at obscure dot org>
22 package Torrus::DevDiscover::UcdSnmp;
28 $Torrus::DevDiscover::registry{'UcdSnmp'} = {
30 'checkdevtype' => \&checkdevtype,
31 'discover' => \&discover,
32 'buildConfig' => \&buildConfig
38 'ucd' => '1.3.6.1.4.1.2021',
39 'net_snmp' => '1.3.6.1.4.1.8072',
41 # We assume that if we have Avail we also have Total
42 'ucd_memAvailSwap' => '1.3.6.1.4.1.2021.4.4.0',
43 'ucd_memAvailReal' => '1.3.6.1.4.1.2021.4.6.0',
45 # If we have in we assume out
46 'ucd_ssSwapIn' => '1.3.6.1.4.1.2021.11.3.0',
48 # If we have User we assume System and Idle
49 'ucd_ssCpuRawUser' => '1.3.6.1.4.1.2021.11.50.0',
50 'ucd_ssCpuRawNice' => '1.3.6.1.4.1.2021.11.51.0',
51 'ucd_ssCpuRawWait' => '1.3.6.1.4.1.2021.11.54.0',
52 'ucd_ssCpuRawKernel' => '1.3.6.1.4.1.2021.11.55.0',
53 'ucd_ssCpuRawInterrupts' => '1.3.6.1.4.1.2021.11.56.0',
54 'ucd_ssCpuRawSoftIRQ' => '1.3.6.1.4.1.2021.11.61.0',
56 # if we have Sent we assume Received
57 'ucd_ssIORawSent' => '1.3.6.1.4.1.2021.11.57.0',
59 'ucd_ssRawInterrupts' => '1.3.6.1.4.1.2021.11.59.0',
60 'ucd_ssRawContexts' => '1.3.6.1.4.1.2021.11.60.0',
62 'ucd_laTable' => '1.3.6.1.4.1.2021.10'
68 my $devdetails = shift;
70 my $sysObjectID = $devdetails->snmpVar( $dd->oiddef('sysObjectID') );
72 if( not $dd->oidBaseMatch( 'ucd', $sysObjectID )
74 not $dd->oidBaseMatch( 'net_snmp', $sysObjectID ) )
86 my $devdetails = shift;
88 my $session = $dd->session();
89 my $data = $devdetails->data();
98 'ucd_ssCpuRawInterrupts',
100 'ucd_ssCpuRawSoftIRQ',
102 'ucd_ssRawInterrupts',
106 my $result = $dd->retrieveSnmpOIDs( @checkOids );
107 if( defined( $result ) )
109 foreach my $oid ( @checkOids )
111 if( defined($result->{$oid}) and length($result->{$oid}) > 0 )
113 $devdetails->setCap($oid);
118 if( $dd->checkSnmpTable('ucd_laTable') )
120 $devdetails->setCap('ucd_laTable');
129 my $devdetails = shift;
133 my $data = $devdetails->data();
135 # Hostresources MIB is optional in net-snmp. We try and use the same
136 # subtree name for UCD and Hostresources statistics.
139 $devdetails->param('RFC2790_HOST_RESOURCES::sysperf-subtree-name');
140 if( not defined( $subtreeName ) )
142 $subtreeName = 'System_Performance';
143 $devdetails->setParam
144 ('RFC2790_HOST_RESOURCES::sysperf-subtree-name', $subtreeName);
148 if( $devdetails->hasCap('ucd_ssIORawSent') )
150 push( @templates, 'UcdSnmp::ucdsnmp-blockio' );
153 if( $devdetails->hasCap('ucd_ssRawInterrupts') )
155 push( @templates, 'UcdSnmp::ucdsnmp-raw-interrupts' );
158 if( $devdetails->hasCap('ucd_laTable') )
160 push( @templates, 'UcdSnmp::ucdsnmp-load-average' );
163 if( $devdetails->hasCap('ucd_memAvailSwap') )
165 push( @templates, 'UcdSnmp::ucdsnmp-memory-swap' );
168 if( $devdetails->hasCap('ucd_memAvailReal') )
170 push( @templates, 'UcdSnmp::ucdsnmp-memory-real' );
174 my @cpuMultiTemplates;
176 if( $devdetails->hasCap('ucd_ssCpuRawUser') )
179 'graph-lower-limit' => '0',
180 'rrd-hwpredict' => 'disabled',
181 'vertical-label' => 'Cpu Usage',
182 'comment' => 'Cpu Idle, Sys, User',
183 'ds-names' => 'idle,sys,user',
184 'ds-type' => 'rrd-multigraph'
188 'UcdSnmp::ucdsnmp-cpu-user',
189 'UcdSnmp::ucdsnmp-cpu-system',
190 'UcdSnmp::ucdsnmp-cpu-idle' );
192 push( @cpuMultiTemplates,
193 'UcdSnmp::ucdsnmp-cpu-user-multi',
194 'UcdSnmp::ucdsnmp-cpu-system-multi',
195 'UcdSnmp::ucdsnmp-cpu-idle-multi' );
197 if( $devdetails->hasCap('ucd_ssCpuRawWait') )
199 push( @templates, 'UcdSnmp::ucdsnmp-cpu-wait' );
200 push( @cpuMultiTemplates, 'UcdSnmp::ucdsnmp-cpu-wait-multi' );
202 $cpuMultiParam->{'comment'} .= ', Wait';
203 $cpuMultiParam->{'ds-names'} .= ',wait';
206 if( $devdetails->hasCap('ucd_ssCpuRawKernel') )
208 push( @templates, 'UcdSnmp::ucdsnmp-cpu-kernel' );
209 push( @cpuMultiTemplates, 'UcdSnmp::ucdsnmp-cpu-kernel-multi' );
211 $cpuMultiParam->{'comment'} .= ', Kernel';
212 $cpuMultiParam->{'ds-names'} .= ',kernel';
215 if( $devdetails->hasCap('ucd_ssCpuRawNice') )
217 push( @templates, 'UcdSnmp::ucdsnmp-cpu-nice' );
218 push( @cpuMultiTemplates, 'UcdSnmp::ucdsnmp-cpu-nice-multi' );
220 $cpuMultiParam->{'comment'} .= ', Nice';
221 $cpuMultiParam->{'ds-names'} .= ',nice';
224 if( $devdetails->hasCap('ucd_ssCpuRawInterrupts') )
226 push( @templates, 'UcdSnmp::ucdsnmp-cpu-interrupts' );
227 push( @cpuMultiTemplates,
228 'UcdSnmp::ucdsnmp-cpu-interrupts-multi' );
230 $cpuMultiParam->{'comment'} .= ', Interrupts';
231 $cpuMultiParam->{'ds-names'} .= ',int';
234 if( $devdetails->hasCap('ucd_ssCpuRawSoftIRQ') )
236 push( @templates, 'UcdSnmp::ucdsnmp-cpu-softirq' );
237 push( @cpuMultiTemplates,
238 'UcdSnmp::ucdsnmp-cpu-softirq-multi' );
240 $cpuMultiParam->{'comment'} .= ', SoftIRQs';
241 $cpuMultiParam->{'ds-names'} .= ',softirq';
244 $cpuMultiParam->{'comment'} =~ s/\,\s+(\w+)$/ and $1/;
247 my $perfNode = $cb->addSubtree( $devNode, $subtreeName,
252 $cb->addLeaf( $perfNode, 'Cpu_Stats',
253 $cpuMultiParam, \@cpuMultiTemplates );
263 # indent-tabs-mode: nil
264 # perl-indent-level: 4