Blame contrib/cisco_tftp/scarfconf.pl

Packit 667938
#!/usr/local/bin/perl 
Packit 667938
#
Packit 667938
###############################################################
Packit 667938
# Copyright 1999 Frontier GlobalCenter/Global Crossing
Packit 667938
# Copy/Use/Modification is fine please mention us in any mods and
Packit 667938
# send them to us. Also thanks to the perl snmp people!
Packit 667938
###############################################################
Packit 667938
#
Packit 667938
# who to blame: pee@gblx.net Paul E. Erkkila
Packit 667938
#
Packit 667938
# A perl script to have a cisco router dump it's configs
Packit 667938
# to a tftp host
Packit 667938
#
Packit 667938
# To use this script I recommend  defining a view on the router 
Packit 667938
# that does NOT have full write such as
Packit 667938
#
Packit 667938
# snmp-server view configView system included
Packit 667938
# snmp-server view configView ciscoConfigCopyMIB included
Packit 667938
# snmp-server community [community name] view configView RW
Packit 667938
#
Packit 667938
# It needs to be RW so it can set table entries
Packit 667938
#
Packit 667938
# the CISCO-CONFIG-COPY mib is 12.x only as far as I
Packit 667938
# can tell
Packit 667938
#
Packit 667938
# $Author: oetiker $
Packit 667938
# $Id: scarfconf.pl,v 1.1.1.1 2002/02/26 10:16:32 oetiker Exp $
Packit 667938
# $Revision: 1.1.1.1 $
Packit 667938
#
Packit 667938
#
Packit 667938

Packit 667938
require 5.003;
Packit 667938
use strict;
Packit 667938

Packit 667938
## snmp perl
Packit 667938
use SNMP_Session;
Packit 667938
use SNMP_util "0.71";
Packit 667938
use BER;
Packit 667938

Packit 667938

Packit 667938
my $host       = $ARGV[0] || die "useage: $0 target community toHost ID";
Packit 667938
my $community  = $ARGV[1] || die "useage: $0 target community toHost ID";
Packit 667938
my $toHost     = $ARGV[2] || die "useage: $0 target community toHost ID";
Packit 667938
my $randomid   = $ARGV[3] || die "useage: $0 target community toHost ID";
Packit 667938

Packit 667938

Packit 667938
&snmpmapOID("cicsoMgmt",            "1.3.6.1.4.1.9.9.96");
Packit 667938
&snmpmapOID("ccCopySourceFileType", "1.3.6.1.4.1.9.9.96.1.1.1.1.3");
Packit 667938
&snmpmapOID("ccCopyDestFileType",   "1.3.6.1.4.1.9.9.96.1.1.1.1.4");
Packit 667938
&snmpmapOID("ccCopyServerAddress",  "1.3.6.1.4.1.9.9.96.1.1.1.1.5");
Packit 667938
&snmpmapOID("ccCopyFileName",       "1.3.6.1.4.1.9.9.96.1.1.1.1.6");
Packit 667938
&snmpmapOID("ccCopyEntryRowStatus", "1.3.6.1.4.1.9.9.96.1.1.1.1.14");
Packit 667938
&snmpmapOID("ccCopyState",          "1.3.6.1.4.1.9.9.96.1.1.1.1.10");
Packit 667938

Packit 667938

Packit 667938
my ($oid,$response);
Packit 667938

Packit 667938
#
Packit 667938
#  First a simple SNMP Get
Packit 667938
#
Packit 667938
my $hostopt = $community . "@" . $host;
Packit 667938

Packit 667938

Packit 667938
# get system uptime to see if it's actually working :)
Packit 667938
$oid = "sysUptime";
Packit 667938
# print "Getting $oid from $host\n";
Packit 667938
($response) = &snmpget($hostopt, $oid);
Packit 667938
if ($response) {
Packit 667938
#	print "$oid : $response\n";
Packit 667938
} else {
Packit 667938
	print "$host did not respond to SNMP query\n";
Packit 667938
	exit;
Packit 667938
}
Packit 667938

Packit 667938
# build the table row
Packit 667938
# print "Sending Row Build (Create and Wait) ";
Packit 667938
$oid = "ccCopyEntryRowStatus." . $randomid;
Packit 667938
($response) = &snmpset($hostopt,$oid,'int',5);
Packit 667938
if ($response) {
Packit 667938
#    print "$oid : $response\n";
Packit 667938
} else {
Packit 667938
    print "Failure setgging $oid on $host\n";
Packit 667938
    exit;
Packit 667938
}
Packit 667938

Packit 667938
# 4 is running-config
Packit 667938
# print "Setting source file type ";
Packit 667938
$oid = "ccCopySourceFileType." . $randomid;
Packit 667938
($response) = &snmpset($hostopt,$oid,'int',4);
Packit 667938
if ($response) {
Packit 667938
#    print "$oid : $response\n";
Packit 667938
} else {
Packit 667938
    print "Failure setting $oid on $host\n";
Packit 667938
    exit;
Packit 667938
}
Packit 667938

Packit 667938
# 1 is netfile
Packit 667938
#print "Setting destination file type ";
Packit 667938
$oid = "ccCopyDestFileType." . $randomid;
Packit 667938
($response) = &snmpset($hostopt,$oid,'int',1);
Packit 667938
if ($response) {
Packit 667938
#    print "$oid : $response\n";
Packit 667938
} else {
Packit 667938
    print "Failure setting $oid on $host\n";
Packit 667938
    exit;
Packit 667938
}
Packit 667938

Packit 667938
# send it to this host
Packit 667938
#print "Setting destination ip address ";
Packit 667938
$oid = "ccCopyServerAddress." . $randomid;
Packit 667938
($response) = &snmpset($hostopt,$oid,'ipaddr',$toHost);
Packit 667938
if ($response) {
Packit 667938
#    print "$oid : $response\n";
Packit 667938
} else {
Packit 667938
    print "Failure setting $oid on $host\n";
Packit 667938
    exit;
Packit 667938
}
Packit 667938

Packit 667938
# name to use
Packit 667938
# print "Setting config file name ";
Packit 667938
$oid = "ccCopyFileName." . $randomid;
Packit 667938
my $filename = $host . "." . $randomid;
Packit 667938
($response) = &snmpset($hostopt,$oid,'string',$filename);
Packit 667938
if ($response) {
Packit 667938
#    print "$oid : $response\n";
Packit 667938
} else {
Packit 667938
    print "Failure setting $oid on $host\n";
Packit 667938
    exit;
Packit 667938
}
Packit 667938

Packit 667938
# GO GO GO
Packit 667938
print "Sending request to start copy operation ";
Packit 667938
$oid = "ccCopyEntryRowStatus." . $randomid;
Packit 667938
($response) = &snmpset($hostopt,$oid,'int',1);
Packit 667938
if ($response) {
Packit 667938
    print "$oid : $response\n";
Packit 667938
} else {
Packit 667938
   exit;
Packit 667938
}
Packit 667938

Packit 667938

Packit 667938
my $pollagain = 1;
Packit 667938
while ($pollagain) {
Packit 667938
my $pstatus = &waitForCompletion($hostopt);
Packit 667938
if ($pstatus eq 1) {
Packit 667938
    print "Waiting\n";
Packit 667938
}
Packit 667938
if ($pstatus eq 2) {
Packit 667938
    print "Running\n";
Packit 667938
}
Packit 667938
if ($pstatus eq 3) {
Packit 667938
    print "Successful\n";
Packit 667938
    $pollagain = 0; 
Packit 667938
}
Packit 667938
if ($pstatus eq 4) {
Packit 667938
    print "Copy Failed\n";
Packit 667938
    $pollagain = 0;
Packit 667938
}
Packit 667938
sleep(1);
Packit 667938
}
Packit 667938

Packit 667938

Packit 667938
exit;
Packit 667938
#### EOP  ###
Packit 667938
#############
Packit 667938

Packit 667938

Packit 667938

Packit 667938
sub waitForCompletion {
Packit 667938
my ($hostopt) = @_;
Packit 667938

Packit 667938
my $oid = "ccCopyState." . $randomid;
Packit 667938
my $response;
Packit 667938
($response) = &snmpget($hostopt, $oid);
Packit 667938
if ($response) {
Packit 667938
	return $response;
Packit 667938
} else {
Packit 667938
	print "$host did not respond to SNMP query\n";
Packit 667938
	exit;
Packit 667938
}
Packit 667938

Packit 667938

Packit 667938
}
Packit 667938

Packit 667938

Packit 667938

Packit 667938