import torrus 1.0.9
[freeside.git] / torrus / perllib / Torrus / DevDiscover / MicrosoftWindows.pm
1 #  Copyright (C) 2003-2004  Stanislav Sinyagin, Shawn Ferry
2 #
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.
7 #
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.
12 #
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.
16
17 # $Id: MicrosoftWindows.pm,v 1.1 2010-12-27 00:03:55 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
19 # Shawn Ferry <sferry at sevenspace dot com> <lalartu at obscure dot org>
20
21 # MS Windows 2000/XP SNMP agent discovery.
22 # ifDescr does not give unique interace mapping, so MAC address mapping
23 # is used.
24
25 package Torrus::DevDiscover::MicrosoftWindows;
26
27 use strict;
28 use Torrus::Log;
29
30
31 $Torrus::DevDiscover::registry{'MicrosoftWindows'} = {
32     'sequence'     => 500,
33     'checkdevtype' => \&checkdevtype,
34     'discover'     => \&discover,
35     'buildConfig'  => \&buildConfig
36     };
37
38
39 our %oiddef =
40     (
41      # MSFT-MIB
42      'windowsNT'                    => '1.3.6.1.4.1.311.1.1.3.1',
43
44      # FtpServer-MIB
45      'ms_ftpStatistics'             => '1.3.6.1.4.1.311.1.7.2.1',
46
47      # HttpServer-MIB
48      'ms_httpStatistics'            => '1.3.6.1.4.1.311.1.7.3.1',
49      );
50
51 # Not all interfaces are normally needed to monitor.
52 # You may override the interface filtering in devdiscover-siteconfig.pl:
53 # redefine $Torrus::DevDiscover::MicrosoftWindows::interfaceFilter
54 # or define $Torrus::DevDiscover::MicrosoftWindows::interfaceFilterOverlay
55
56 our $interfaceFilter;
57 our $interfaceFilterOverlay;
58 my %winNTInterfaceFilter;
59
60 if( not defined( $interfaceFilter ) )
61 {
62     $interfaceFilter = \%winNTInterfaceFilter;
63 }
64
65
66 # Key is some unique symbolic name, does not mean anything
67 # ifType is the number to match the interface type
68 # ifDescr is the regexp to match the interface description
69 %winNTInterfaceFilter =
70     (
71      'MS TCP Loopback interface' => {
72          'ifType'  => 24                        # softwareLoopback
73          },
74      );
75
76 sub checkdevtype
77 {
78     my $dd = shift;
79     my $devdetails = shift;
80
81     if( not $dd->oidBaseMatch
82         ( 'windowsNT',
83           $devdetails->snmpVar( $dd->oiddef('sysObjectID') ) ) )
84     {
85         return 0;
86     }
87
88     my $data = $devdetails->data();
89
90     &Torrus::DevDiscover::RFC2863_IF_MIB::addInterfaceFilter
91         ($devdetails, $interfaceFilter);
92
93     if( defined( $interfaceFilterOverlay ) )
94     {
95         &Torrus::DevDiscover::RFC2863_IF_MIB::addInterfaceFilter
96             ($devdetails, $interfaceFilterOverlay);
97     }
98
99     $devdetails->setCap('interfaceIndexingManaged');
100     
101     return 1;
102 }
103
104
105 sub discover
106 {
107     my $dd = shift;
108     my $devdetails = shift;
109
110     my $session = $dd->session();
111     my $data = $devdetails->data();
112
113     # In Windows SNMP agent, ifDescr is not unique per interface.
114     # We use MAC address as a unique interface identifier.
115
116     $data->{'nameref'}{'ifComment'} = ''; # suggest?
117
118     $data->{'param'}{'ifindex-map'} = '$IFIDX_MAC';
119     Torrus::DevDiscover::RFC2863_IF_MIB::retrieveMacAddresses( $dd,
120                                                                $devdetails );
121
122     $data->{'nameref'}{'ifNick'} = 'MAC';
123     
124     # FTP and HTTP servers, if present
125     if( $dd->checkSnmpTable( 'ms_ftpStatistics' ) )
126     {
127         $devdetails->setCap( 'msIIS' );
128         $devdetails->setCap( 'msFtpStats' );
129     }
130
131     if( $dd->checkSnmpTable( 'ms_httpStatistics' ) )
132     {
133         $devdetails->setCap( 'msIIS' );
134         $devdetails->setCap( 'msHttpStats' );
135     }
136
137     return 1;
138 }
139
140
141 # Nothing really to do yet
142 sub buildConfig
143 {
144     my $devdetails = shift;
145     my $cb = shift;
146     my $devNode = shift;
147
148     if( $devdetails->hasCap( 'msIIS' ) )
149     {
150         my $iisParam = {
151             'precedence'    =>  -100000,
152             'comment'       => 'Microsoft Internet Information Server'
153             };
154
155         my @iisTemplates;
156         if( $devdetails->hasCap( 'msFtpStats' ) )
157         {
158             push( @iisTemplates,
159                   'MicrosoftWindows::microsoft-iis-ftp-stats' );
160         }
161         if( $devdetails->hasCap( 'msHttpStats' ) )
162         {
163             push( @iisTemplates,
164                   'MicrosoftWindows::microsoft-iis-http-stats' );
165         }
166
167
168         my $iisNode = $cb->addSubtree( $devNode, 'MS_IIS', $iisParam,
169                                        \@iisTemplates );
170     }
171 }
172
173
174 1;
175
176
177 # Local Variables:
178 # mode: perl
179 # indent-tabs-mode: nil
180 # perl-indent-level: 4
181 # End: