1 # Copyright (C) 2003 Shawn Ferry, Stanislav Sinyagin
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: RFC2790_HOST_RESOURCES.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>
19 # Stanislav Sinyagin <ssinyagin@yahoo.com>
21 # Standard HOST_RESOURCES_MIB discovery, which should apply to most hosts
23 package Torrus::DevDiscover::RFC2790_HOST_RESOURCES;
29 $Torrus::DevDiscover::registry{'RFC2790_HOST_RESOURCES'} = {
31 'checkdevtype' => \&checkdevtype,
32 'discover' => \&discover,
33 'buildConfig' => \&buildConfig
37 # define the oids that are needed to determine support,
38 # capabilities and information about the device
41 'hrSystemUptime' => '1.3.6.1.2.1.25.1.1.0',
42 'hrSystemNumUsers' => '1.3.6.1.2.1.25.1.5.0',
43 'hrSystemProcesses' => '1.3.6.1.2.1.25.1.6.0',
44 'hrSystemMaxProcesses' => '1.3.6.1.2.1.25.1.7.0',
45 'hrMemorySize' => '1.3.6.1.2.1.25.2.2.0',
46 'hrStorageTable' => '1.3.6.1.2.1.25.2.3.1',
47 'hrStorageIndex' => '1.3.6.1.2.1.25.2.3.1.1',
48 'hrStorageType' => '1.3.6.1.2.1.25.2.3.1.2',
49 'hrStorageDescr' => '1.3.6.1.2.1.25.2.3.1.3',
50 'hrStorageAllocationUnits' => '1.3.6.1.2.1.25.2.3.1.4',
51 'hrStorageSize' => '1.3.6.1.2.1.25.2.3.1.5',
52 'hrStorageUsed' => '1.3.6.1.2.1.25.2.3.1.6',
53 'hrStorageAllocationFailures' => '1.3.6.1.2.1.25.2.3.1.7'
57 our %storageDescTranslate = ( '/' => {'subtree' => 'root' } );
59 # storage type names from MIB
63 2 => 'Physical Memory (RAM)',
64 3 => 'Virtual Memory',
66 5 => 'Removable Disk',
71 10 => 'Network File System'
80 my $devdetails = shift;
82 my $session = $dd->session();
83 my $data = $devdetails->data();
85 return $dd->checkSnmpOID('hrSystemUptime');
92 my $devdetails = shift;
94 my $data = $devdetails->data();
95 my $session = $dd->session();
97 if( $dd->checkSnmpOID('hrSystemNumUsers') )
99 $devdetails->setCap('hrSystemNumUsers');
102 if( $dd->checkSnmpOID('hrSystemProcesses') )
104 $devdetails->setCap('hrSystemProcesses');
108 my $hrStorageTable = $session->get_table( -baseoid =>
109 $dd->oiddef('hrStorageTable') );
110 if( defined( $hrStorageTable ) )
112 $devdetails->storeSnmpVars( $hrStorageTable );
115 $data->{'hrStorage'} = $ref;
118 ( $devdetails->getSnmpIndices($dd->oiddef('hrStorageIndex') ) )
120 my $typeNum = $devdetails->snmpVar( $dd->oiddef('hrStorageType') .
122 $typeNum =~ s/^[0-9.]+\.(\d+)$/$1/;
124 my $descr = $devdetails->snmpVar($dd->oiddef('hrStorageDescr')
127 my $used = $devdetails->snmpVar($dd->oiddef('hrStorageUsed')
130 if( defined( $used ) and $storageTypes{$typeNum} )
132 my $ref = { 'param' => {}, 'templates' => [] };
133 $data->{'hrStorage'}{$INDEX} = $ref;
134 my $param = $ref->{'param'};
136 $param->{'storage-description'} = $descr;
138 my $comment = $storageTypes{$typeNum};
139 if( $descr =~ /^\// )
141 $comment .= ' (' . $descr . ')';
143 $param->{'comment'} = $comment;
145 if( $storageDescTranslate{$descr}{'subtree'} )
147 $descr = $storageDescTranslate{$descr}{'subtree'};
151 $param->{'storage-nick'} = $descr;
155 ($dd->oiddef('hrStorageAllocationUnits') . '.' . $INDEX);
157 $param->{'collector-scale'} = sprintf('%d,*', $units);
161 ($dd->oiddef('hrStorageSize') . '.' . $INDEX);
165 if( $storageGraphTop > 0 )
167 $param->{'graph-upper-limit'} =
169 $units * $size * $storageGraphTop / 100 );
172 if( $storageHiMark > 0 )
174 $param->{'upper-limit'} =
176 $units * $size * $storageHiMark / 100 );
180 push( @{ $ref->{'templates'} },
181 'RFC2790_HOST_RESOURCES::hr-storage-usage' );
185 if( scalar( keys %{$data->{'hrStorage'}} ) > 0 )
187 $devdetails->setCap('hrStorage');
197 my $devdetails = shift;
201 my $data = $devdetails->data();
203 { # Anon sub for System Info
205 $devdetails->param('RFC2790_HOST_RESOURCES::sysperf-subtree-name');
206 if( not defined( $subtreeName ) )
208 $subtreeName = 'System_Performance';
209 $devdetails->setParam
210 ('RFC2790_HOST_RESOURCES::sysperf-subtree-name', $subtreeName);
216 ('RFC2790_HOST_RESOURCES::hr-system-performance-subtree',
217 'RFC2790_HOST_RESOURCES::hr-system-uptime');
218 if( $devdetails->hasCap('hrSystemNumUsers') )
220 push( @templates, 'RFC2790_HOST_RESOURCES::hr-system-num-users' );
223 if( $devdetails->hasCap('hrSystemProcesses') )
225 push( @templates, 'RFC2790_HOST_RESOURCES::hr-system-processes' );
228 my $subtreeNode = $cb->addSubtree( $devNode, $subtreeName,
229 $param, \@templates );
232 if( $devdetails->hasCap('hrStorage') )
234 # Build hrstorage subtree
235 my $subtreeName = 'Storage_Used';
238 my @templates = ('RFC2790_HOST_RESOURCES::hr-storage-subtree');
239 my $subtreeNode = $cb->addSubtree( $devNode, $subtreeName,
240 $param, \@templates );
242 foreach my $INDEX ( sort {$a<=>$b} keys %{$data->{'hrStorage'}} )
244 my $ref = $data->{'hrStorage'}{$INDEX};
246 #Display in index order, This is generally good(tm)
247 $ref->{'param'}->{'precedence'} = sprintf("%d", 1000 - $INDEX);
249 $cb->addLeaf( $subtreeNode, $ref->{'param'}{'storage-nick'},
250 $ref->{'param'}, $ref->{'templates'} );
261 # indent-tabs-mode: nil
262 # perl-indent-level: 4