forked from extremenetworks/ExtremeScripting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetfdbsql.pl
More file actions
162 lines (140 loc) · 4.96 KB
/
Copy pathgetfdbsql.pl
File metadata and controls
162 lines (140 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#t!/usr/bin/perl -w
######
#THE INFORMATION AND SPECIFICATIONS IN THIS DEVELOPER KIT ARE SUBJECT TO CHANGE WITHOUT
#NOTICE. ALL INFORMATION AND SPECIFICATIONS IN THIS DEVELOPER KIT ARE PRESENTED WITHOUT
#WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. YOU TAKE FULL RESPONSIBILITY FOR YOUR USE OF
#THE DEVELOPER KIT.
#
# THE DEVELOPER KIT IS LICENSED TO YOU UNDER THE THEN-CURRENT LICENSE TERMS FOR THE
# DEVELOPER KIT IN EFFECT AT THE TIME THE DEVELOPER KIT IS PROVIDED TO YOU BY
# EXTREME NETWORKS. PLEASE CONTACT EXTREME NETWORKS IF YOU DO NOT HAVE A COPY OF THE
# LICENSE TERMS. USE OF THE DEVELOPER KIT CONSTITUTES YOUR ACCEPTANCE OF THE DEVELOPER
# KIT LICENSE TERMS.
#
# Copyright (c) 2007,2008,2015 Extreme Networks
## All rights reserved.
##
## Redistribution and use in source and binary forms, with or without modification,
## are permitted provided that the following conditions are met:
##
## 1. Redistributions of source code must retain the above copyright notice, this
## list of conditions and the following disclaimer.
##
## 2. Redistributions in binary form must reproduce the above copyright notice,
## this list of conditions and the following disclaimer in the documentation
## and/or other materials provided with the distribution.
##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
## WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
##
## Support
## ******************************
## The software is provided as is and Extreme has no obligation to provide
## maintenance, support, updates, enhancements or modifications.
## Any support provided by Extreme is at its sole discretion.
## Issues and/or bug fixes may be reported in the Hub:
##
## https://community.extremenetworks.com/
###
##
## This is an example on how to use getAllFdb API.
## It will read switch ip, username and password from the command line
##
## Usage: "perl getAllFdb.pl <ip_address> <account> <password>
## Example: "perl getAllFdb.pl 10.0.0.1 admin password"
##
## Copyright (c) Extreme Networks Inc. 2006,2007
## All rights reserved
##
###
######
###
## Contributors:
##
## Thorsten Krohn - Wilhelm Tel, Germany
## Andy Gatward - Reading University, United Kingdom
## Paul Tinsley - Lightining Source, United States
## Jussi Sjöström - Xenetic, Finland
##
###
######
use SOAP::Lite;
use DBI;
use DBD::mysql;
#use IO::All;
require ('sessionManage.pl');
my $host=$ARGV[0];
my $usrname=$ARGV[1];
my $pwd=$ARGV[2];
# MYSQL CONFIG VARIABLES
my $dbhost = "localhost";
my $database = "fdb";
my $tablename = "fdb";
my $user = "fdb";
my $pw = "fdbfdb";
# PERL MYSQL CONNECT()
my $connect = Mysql->connect($dbhost, $database, $user, $pw);
# SELECT DB
$connect->selectdb($database);
my $sessid=opensession($host,$usrname,$pwd);
if ($sessid==null) {
die "Could not open connection to switch.\n";
} else {
print "Connection to switch opened, sessionid $sessid.\n";
# set up connection
my $connection = SOAP::Lite
-> proxy("http://$usrname:$pwd\@$host/xmlservice", timeout=>10)
-> ns("urn:xapi/l2protocol/fdb", "xos") # namespace and prefix for operation
-> autotype(0)
-> envprefix('SOAP-ENV'); # envelope prefix
# assemble the SOAP Message
my $method = SOAP::Data->name('xos:getAllFdb');
# Assign the Result
$result = $connection->call($method);
handleResponse($result);
# send request
my $response = $connection->call($method => @params);
}
sub handleResponse {
my $res = shift;
if ($res->fault) {
print $res->faultcode, " ", $res->faultstring, "\n";
exit();
}else
{
my @fdbentry = $result->valueof('//Body/getAllFdbResponse/reply/fdb');
my $len = @fdbentry;
print $len."\n";
my $i=0;
for ($i=0; $i < $len; $i++) {
my $fdbentry= $fdb[$i];
my $macAdress=$fdb->{"macAddress"};
my $vlan=$fdb->{"vlan"};
my $port=$fdb->{"port"};
my $age=$fdb->{"age"};
}
foreach my $test (@fdbentry){
$mac = $test->{'macAddress'};
$vlan = $test->{'vlan'};
$port = $test->{'port'};
$age = $test->{'age'};
my $fdbinsert = "INSERT INTO $tablename (id, mac, vlan, port, age) VALUES (id,$mac,$vlan,$port,$age)";
# EXECUTE THE QUERY FUNCTION
$execute = $connect->query($myquery);
# AFFECTED ROWS
$affectedrows = $execute->affectedrows($myquery);
# ID OF LAST INSERT
$lastid = $execute->insertid($myquery)
}
}
}
}
closesession($sessid,$host,$usrname);