bignellrp
asked on
Separate show dsl command in perl for use in cacti
Need a way using regex to separate an array into separate variables.
Just need to output the numeric values for speed/attenuation/noise_ma rgin
I tried to do this with "split" but it doesn't work. I would rather do it with regex but my programming skills are limited. I know cisco can use snmp for cacti graphs, but i evenutually want to modify this script for different routers.
If someone could provide the code i need to separate out the following output into separate varialbles and expalin the regex so i can change it if necessary:
ATM0
Alcatel 20190 chipset information
ATU-R (DS) ATU-C (US)
Modem Status: Showtime (DMTDSL_SHOWTIME)
DSL Mode: ITU G.992.1 (G.DMT) Annex A
ITU STD NUM: 0x01 0x1
Vendor ID: 'STMI' 'GSPN'
Vendor Specific: 0x0000 0x0008
Vendor Country: 0x0F 0xFF
Chip ID: C196 (0)
DFE BOM: DFE3.0 Annex A (1)
Capacity Used: 93% 100%
Noise Margin: 12.5 dB 13.0 dB
Output Power: 13.0 dBm 12.5 dBm
Attenuation: 9.0 dB 3.0 dB
FEC ES Errors: 0 0
ES Errors: 21216 1348
SES Errors: 0 0
LOSES Errors: 0 0
UES Errors: 0 0
Defect Status: None None
Last Fail Code: None
Watchdog Counter: 0xA3
Watchdog Resets: 0
Selftest Result: 0x00
Subfunction: 0x00
Interrupts: 4191 (0 spurious)
PHY Access Err: 0
Activations: 3
LED Status: ON
LED On Time: 100
LED Off Time: 100
Init FW: init_AMR-3.0.014_no_bist.b in
Operation FW: AMR-3.0.014.bin
FW Source: embedded
FW Version: 3.0.14
Interleave Fast Interleave Fast
Speed (kbps): 8160 0 704 0
Cells: 87842588 0 1254180885 0
Reed-Solomon EC: 7 0 2 0
CRC Errors: 0 0 3 0
Header Errors: 0 0 0 0
Total BER: 0E-0 0E-0
Leakage Average BER: 0E-0 0E-0
ATU-R (DS) ATU-C (US)
Bitswap: enabled enabled
Bitswap success: 0 0
Bitswap failure: 0 0
LOM Monitoring : Disabled
DMT Bits Per Bin
000: 0 0 0 0 0 0 2 4 6 7 8 8 9 A A A
010: A A A A A A A A 9 9 9 8 8 7 7 6
020: 0 0 0 9 A A B B B B B B C C B C
030: C C C C C C B B B B B B B B B B
040: 0 B B B B B B B B B B B B B B B
050: B B B B B B B B B B B B B B B B
060: B B B B 2 B B B B B B B A B B B
070: A A A A A A A A A A A A A A A A
080: A A A A A A A A A A A A A A A A
090: A A A A A A A A A A A A A A A A
0A0: A A A A A A A A A A A A A A A A
0B0: A A A A A A A A A A A A A A A A
0C0: A A A A A A A A A A A A A A A A
0D0: A B A A A A A B A A A A A A A A
0E0: A A A A A A A A A A A A A A 9 9
0F0: A 9 A A 9 9 9 9 9 9 9 9 9 9 9 9
DSL: Training log buffer capability is not enabled
Just need to output the numeric values for speed/attenuation/noise_ma
I tried to do this with "split" but it doesn't work. I would rather do it with regex but my programming skills are limited. I know cisco can use snmp for cacti graphs, but i evenutually want to modify this script for different routers.
If someone could provide the code i need to separate out the following output into separate varialbles and expalin the regex so i can change it if necessary:
ATM0
Alcatel 20190 chipset information
ATU-R (DS) ATU-C (US)
Modem Status: Showtime (DMTDSL_SHOWTIME)
DSL Mode: ITU G.992.1 (G.DMT) Annex A
ITU STD NUM: 0x01 0x1
Vendor ID: 'STMI' 'GSPN'
Vendor Specific: 0x0000 0x0008
Vendor Country: 0x0F 0xFF
Chip ID: C196 (0)
DFE BOM: DFE3.0 Annex A (1)
Capacity Used: 93% 100%
Noise Margin: 12.5 dB 13.0 dB
Output Power: 13.0 dBm 12.5 dBm
Attenuation: 9.0 dB 3.0 dB
FEC ES Errors: 0 0
ES Errors: 21216 1348
SES Errors: 0 0
LOSES Errors: 0 0
UES Errors: 0 0
Defect Status: None None
Last Fail Code: None
Watchdog Counter: 0xA3
Watchdog Resets: 0
Selftest Result: 0x00
Subfunction: 0x00
Interrupts: 4191 (0 spurious)
PHY Access Err: 0
Activations: 3
LED Status: ON
LED On Time: 100
LED Off Time: 100
Init FW: init_AMR-3.0.014_no_bist.b
Operation FW: AMR-3.0.014.bin
FW Source: embedded
FW Version: 3.0.14
Interleave Fast Interleave Fast
Speed (kbps): 8160 0 704 0
Cells: 87842588 0 1254180885 0
Reed-Solomon EC: 7 0 2 0
CRC Errors: 0 0 3 0
Header Errors: 0 0 0 0
Total BER: 0E-0 0E-0
Leakage Average BER: 0E-0 0E-0
ATU-R (DS) ATU-C (US)
Bitswap: enabled enabled
Bitswap success: 0 0
Bitswap failure: 0 0
LOM Monitoring : Disabled
DMT Bits Per Bin
000: 0 0 0 0 0 0 2 4 6 7 8 8 9 A A A
010: A A A A A A A A 9 9 9 8 8 7 7 6
020: 0 0 0 9 A A B B B B B B C C B C
030: C C C C C C B B B B B B B B B B
040: 0 B B B B B B B B B B B B B B B
050: B B B B B B B B B B B B B B B B
060: B B B B 2 B B B B B B B A B B B
070: A A A A A A A A A A A A A A A A
080: A A A A A A A A A A A A A A A A
090: A A A A A A A A A A A A A A A A
0A0: A A A A A A A A A A A A A A A A
0B0: A A A A A A A A A A A A A A A A
0C0: A A A A A A A A A A A A A A A A
0D0: A B A A A A A B A A A A A A A A
0E0: A A A A A A A A A A A A A A 9 9
0F0: A 9 A A 9 9 9 9 9 9 9 9 9 9 9 9
DSL: Training log buffer capability is not enabled
#!/usr/bin/perl
use Net::Telnet::Cisco;
use strict;
my $host = "xxxxxxx";
my $username = "xxxxxxxx";
my $password = "xxxxxxxxx";
my $session = Net::Telnet::Cisco->new(Host => $host, Timeout=> '120', Errmode=> 'return');
unless($session) {
print "Could not connect to device: $host\n";
next;
}
$session->login($username, $password);
if($session->errmsg) {
print "Authentication failed";
}
#my @output = "";
#@output = $session->cmd('sh dsl int ATM0');
my @status = $session->cmd('sh dsl int atm0');
$session->close;
chomp(@status);
my $split = "@status";
my @split = split(/ /, $split);
@split = grep /\S/, @split;
open FILE, ">/home/rbignell/adsl_status.txt" or die $!;
for my $char (@split) {
print FILE $char . "\n";
}
close FILE;
print "downstream_speed:$split[146] ";
print "upstream_speed:$split[148] ";
print "downstream_attenuation:$split[63] ";
print "upstream_attenuation:$split[65] ";
print "downstream_noisemargin:$split[52]";
print "upstream_noisemargin:$split[55]";
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thx...works perfectly
#assuming $str contains all of the output
my ($NoiseMargin) = $str =~ /Noise Margin:\s+(.*)/;