10 my $password = 'removed';
14 my ($cmd, $conn) = @_;
16 # Send the command and get data from switch
17 my @data = $conn->cmd($cmd);
19 foreach my $line (@data) {
20 # Remove escape-7 sequence
21 $line =~ s/\x1b\x37//g;
28 sub switch_connect($) {
31 # Errmode => 'return',
32 my $conn = new Net::Telnet( Timeout => $timeout,
33 Dump_Log => 'dumplog',
34 Prompt => '/es(\-)?3024|e(\-)?\d+\-\dsw>/i');
35 my $ret = $conn->open( Host => $ip);
36 if (!$ret || $ret != 1) {
39 # XXX: Just send the password as text, I did not figure out how to
40 # handle authentication with only password through $conn->login().
41 #$conn->login(»·Prompt => '/password[: ]*$/i',
43 # Password => $password);
44 $conn->cmd($password);
50 sub switch_get_arp($) {
53 my @data = switch_exec('ip arp status', $conn);
55 # 81.162.241.1 Ethernet 300 00:e0:2b:e0:f3:00 41 swif0 swp24
56 $_ =~ /(\d+\.\d+\.\d+\.\d+)\s+\w+\s+\d+\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)\s+\d+\s+\w+\s+(\w+)/;
57 next if (!defined($1));
58 next if ($3 eq "NULL");
64 my $conn = switch_connect($ARGV[0]);
65 if (!defined($conn)) {
66 die "something went wrong!";
68 my @data = switch_exec('sys monitor status', $conn);
69 my @fields = split(/\s+/, $data[2]);
70 # The temp fields are 6, 7, 8
71 print "$fields[7] + $fields[8] + $fields[9]\n";
72 my $avgtemp = ($fields[7] + $fields[8] + $fields[9]) / 3;
73 print $avgtemp." avgtemp\n";