1########################################################################## 2## 3## Passport.pm 4## 5## Pancho plugin for Nortel Passport 8000 serie devices 6## 7## Author : Jean-Francois Taltavull 8## Release : 1.0 - 2003/10/27 9## Last update : 2003/12/05 10## 11## Mib file : rapid_city.mib, rc_vlan.mib 12## Mib name : RAPID-CITY {enterprises 2272} 13## Mib version/date : v542, 2002/04/01 14## Mib branch : 2k copy file - enterprises.rcMgmt.rc2k.rc2kCopyFile (oid : 2272.1.100.7) 15## 16## Caveats : 17## downloading and uploading device's configuration mean transfering /config.cfg file. 18## 19## Plugin's features : 20## - upload, download 21## (commit, startup and reload are not supported.) 22## 23## 24## Copyright (c) 2003 Jean-Fran�ois Taltavull 25## All rights reserved 26## 27## Some parts of code written by Russel Vrolyk. 28## 29## This code is part of the Pancho project. 30## http://www.pancho.org 31## Copyright (c) 2001-2002 Charles J. Menzes 32## All rights reserved. 33## 34## 35## This program is free software; you can redistribute it and/or modify 36## it under the terms of the GNU General Public License as published by 37## the Free Software Foundation; either version 2 of the License, or 38## (at your option) any later version. 39## 40## This program is distributed in the hope that it will be useful, 41## but WITHOUT ANY WARRANTY; without even the implied warranty of 42## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 43## GNU General Public License for more details. 44## 45## You should have received a copy of the GNU General Public License 46## along with this program; if not, write to the Free Software 47## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 48## 49########################################################################## 50package Pancho::Passport; 51 52use strict; 53use Net::SNMP; 54 55# these are device types we can handle in this plugin 56# the names should be contained in the sysdescr string 57# returned by the devices 58# the key is the name and the value is the vendor description 59my %types = ( 60 'Passport-8' => "Nortel Passport 8000 serie", 61 ); 62 63my $snmpslowdown = 3; # to slowdown snmp requests loops (seconds) 64 65 66#------------------------------------------------------------------------------- 67# device_types 68# IN : N/A 69# OUT: returns an array ref of devices this plugin can handle 70#------------------------------------------------------------------------------- 71sub device_types { 72 my $self = shift; 73 my @devices = keys %types; 74 75 return \@devices; 76} 77 78 79#------------------------------------------------------------------------------- 80# device_description 81# IN : scalar containing sysdescr 82# OUT: returns scalar containing description or 'Unknown' if it doesn't exist 83#------------------------------------------------------------------------------- 84sub device_description { 85 my $self = shift; 86 my $name = shift || return 0; 87 my $sn = ''; 88 89 if ($sn = (grep { $name =~ m/$_/gi } keys %types)[0]) { 90 return $types{$sn}; 91 } 92 else { 93 return "Unknown"; 94 } 95} 96 97 98#------------------------------------------------------------------------------- 99# process_device - figures out what device type we have and tries to 100# operate on it based on args given 101# IN : args - hash ref containing various program args 102# opts - hash ref of options passed into program 103#------------------------------------------------------------------------------- 104sub process_device { 105 my $self = shift; 106 my $args = shift; 107 my $opts = shift; 108 109 110 if (($args->{src} eq "start") or ($args->{dst} eq "start")) { 111 # startup config not supported 112 &passport_log($args,"Operations on startup-config not supported."); 113 return 0; 114 } 115 116 117 SWITCH: { 118 ($opts->{download} || $opts->{upload}) && do { 119 &passport_transfer($args); 120 last SWITCH; 121 }; 122 123 $opts->{commit} && do { 124 &passport_log($args,"Commit operation not supported."); 125 last SWITCH; 126 }; 127 128 $opts->{reload} && do { 129 &passport_log($args,"Reload operation not supported."); 130 last SWITCH; 131 }; 132 133 &passport_log($args,"Unknown operation."); 134 } 135} 136 137 138sub passport_transfer { 139 my $args = shift; 140 141 my %oid = ( 142 ## rc2kCopyFileSource 143 filesource => ".1.3.6.1.4.1.2272.1.100.7.1.0", 144 145 ## rc2kCopyFileDestination 146 filedest => ".1.3.6.1.4.1.2272.1.100.7.2.0", 147 148 ## rc2kCopyFileAction 149 action => ".1.3.6.1.4.1.2272.1.100.7.3.0", 150 151 ## rc2kCopyFileResult 152 result => ".1.3.6.1.4.1.2272.1.100.7.4.0" 153 ); 154 155 my %action = ( 156 none => 1, 157 start => 2 158 ); 159 160 my %state = ( 161 none => 1, 162 inProgress => 2, 163 success => 3, 164 fail => 4, 165 invalidSource => 5, 166 invalidDestination => 6, 167 outOfMemory => 7, 168 outOfSpace => 8, 169 fileNotFound => 9 170 ); 171 172 173 ## determine the mib value for action object 174 my $filesrc; my $filedst; 175 if ($args->{src} eq "tftp") { 176 $filesrc = "$args->{utftp}:$args->{file}"; 177 $filedst = "config.cfg"; 178 } 179 else { 180 $filesrc = "config.cfg"; 181 $filedst = "$args->{utftp}:$args->{file}"; 182 } 183 184 ## set up snmp session parameters 185 my $s = $args->{snmp}->create_snmp($args); 186 187 $s->set_request ( 188 ## set the source filename 189 $oid{filesource}, OCTET_STRING, $filesrc, 190 ## set the destination filename 191 $oid{filedest}, OCTET_STRING, $filedst, 192 ## set action code 193 $oid{action}, INTEGER, $action{'start'} 194 ); 195 196 ## grab an error message if it exists 197 my $error = $s->error; 198 ## put error value into hash 199 $args->{err} = $error; 200 201 if (!$error) { 202 ## OK, no error 203 ## get the current status of the tftp action 204 sleep $snmpslowdown; 205 my $current_state = $s->get_request("$oid{result}"); 206 my $result = $current_state->{"$oid{result}"}; 207 208 ## loop and check for completion 209 while ($result && $result == "$state{'inProgress'}") { 210 ## get the current status of the tftp action 211 sleep $snmpslowdown; 212 $current_state = $s->get_request("$oid{result}"); 213 $result = $current_state->{"$oid{result}"}; 214 } 215 216 ## check the final state 217 if ($result != "$state{'success'}") { 218 ## transfer failure 219 &passport_log($args, "problem with transfer operation. Result = " 220 . $result); 221 } 222 else { 223 ## success, log output to screen and possibly external file 224 $args->{log}->log_action($args); 225 } 226 } 227 228 else { 229 ## Error : can't trigger transfer operation... 230 &passport_log($args, "can't trigger transfer operation."); 231 } 232 233 ## close the snmp session 234 $s->close; 235} 236 237 238#------------------------------------------------------------------------------- 239# passport_log 240# Add a leading "Plugin Passport" to the message and logs it 241#------------------------------------------------------------------------------- 242 243sub passport_log { 244 my $args = shift; 245 my $msg = shift; 246 247 $args->{err} = "Plugin Passport - $msg"; 248 $args->{log}->log_action($args); 249} 250 251 252# this must be here or else it won't return true 2531; 254