Merge branch 'devel' of h1dev:/srv/APKPM/
[APKPM.git] / lib / H1 / ZTEDSLAM.pm
index bec1b2b..c00a4a7 100644 (file)
@@ -35,7 +35,7 @@ sub parse {
        my $hash;
        foreach my $line ( split(/[\n\r]+/, $out) ) {
                warn "# $line\n" if $ENV{DEBUG};
-               if ( $line =~ m/^(\S+.*?)\s+:\s+(\S+.*)$/ ) {
+               if ( $line =~ m/^(\S+.*?)\s*:\s+(\S+.*)$/ ) {
                        my ($n,$v) = ($1,$2);
                        $n =~ s/\(.+\)//;
                        $hash->{$n} = $v;
@@ -72,5 +72,55 @@ AturDMTState
        )],
 }}
 
+sub custom {
+       my ($self,$port) = @_;
+
+       my $out = $self->command_out("show interface $port adsl-status");
+       my @lines = split(/\s*[\n\r]+/,$out);
+
+       shift @lines if $lines[0] =~ m/adsl-status/; # skip command
+       if ( $lines[2] !~ m/^-+$/ ) {
+               warn "Can't parse into table - missing header separator at index 2: $lines[2]";
+               return;
+       }
+       my @h1 = split(/\s+/, $lines[0]);
+       my @h2 = split(/\s+/, $lines[1]);
+       my @v  = split(/\s+/, $lines[3]);
+
+       my $hash;
+       foreach my $i ( 0 .. $#v ) {
+               my $k = $h1[$i];
+
+               $h2[$i] =~ s/\(\w\)\s*$//; # remove unit
+
+               if ( $h2[$i] =~ m/\// && $v[$i] =~ m/\// ) {
+                       my ($ln,$rn) = split(/\//, $h2[$i]);
+                       my ($lv,$rv) = split(/\//, $v[$i]);
+                       $hash->{ join('_',$k,$ln) } = $lv;
+                       $hash->{ join('_',$k,$rn) } = $rv;
+               } else {
+                       $hash->{ $h2[$i] ? $h1[$i] .'_'. $h2[$i] : $h1[$i] } = $v[$i];
+               }
+       }
+
+       my $out = $self->command_out("show adsl perf $port");
+       my @lines = split(/\s*[\n\r]+/,$out);
+
+       my $table;
+       foreach my $line ( @lines ) {
+               next if ! $line;
+               if ( $line =~ m/ADSL\s+(\w+)\s+Table/i ) {
+                       $table = $1;
+                       next;
+               } elsif ( $line =~ m/^(\S+)\s+:\s+(\S)*$/ ) {
+                       $hash->{ $table . '_' . $1 } = $2 if defined $2;
+               } else {
+                       warn "# IGNORED: $line\n";
+               }
+       }
+
+       return $hash;
+}
+
 1;