#!/usr/bin/perl use strict; my %a; my $raw = ''; my %trunk_ins; my %trunk_oos; my %station_names; my %registered_stations; #my %connected_stations; sub trim { my ($str) = shift; $str =~ s/^\s+//; $str =~ s/\s+$//; return $str; } sub set_data { my ($key, $value) = (@_); $a{$key} = $value; #print "setting $key = $value\n"; } sub get_data { my ($key) = (@_); return $a{$key}; } sub dump_data { my $output = ''; #while( my ($k, $v) = each %a ) { foreach my $key (sort (keys (%a))) { #$output .= "$k\t$v\n"; $output .= "$key\t$a{$key}\n"; } #print $output; write_data($output); } sub write_data { my ($data) = shift; #die; open OUTPUT,">/home/roger/avaya/sanity/keyvalues.txt"; print OUTPUT $data; #print OUTPUT "this is data\n"; close OUTPUT; } open INPUT,$ARGV[0]; my $type; my $site; my $station_dn; while (my $line = ) { $raw .= $line; chomp($line); #print $line . "\n"; if($line =~ /^ +DATE AND TIME *$/) { $type = 0; } elsif($line =~ /list ipserver-interface/) { $type = 1; } elsif($line =~ /list media-gateway/) { $type = 2; } elsif($line =~ /list survivable-processor/) { $type = 3; } elsif($line =~ /logging into .*?(\w+)\.pbx$/) { $site = $1; } elsif($line =~ /status station/) { $type = 4; } elsif($line =~ /TRUNK GROUP STATUS/) { $type = 5; } elsif($line =~ /^ +STATIONS +$/) { $type = 6; } elsif($line =~ /^ +REGISTERED IP STATIONS +$/) { $type = 7; } elsif($line =~ /^ +CALL FORWARDING +$/) { $type = 8; } elsif($line =~ /^status cdr-link +$/) { $type = 9; } if($type == 1) { if($line =~ /(6.01) +(.+?) +(.+?) +(.+?) +(.+?) +(.+?) +(.+)$/) { my $ipsi_board = $1; my $ipsi_ip = $2; my $ipsi_service = $5; my $ipsi_control = $6; my $ipsi_cpeg = $7; set_data("hi.${site}.ipsi.${ipsi_board}.ip_address",$ipsi_ip); set_data("hi.${site}.ipsi.${ipsi_board}.service_state",$ipsi_service); set_data("hi.${site}.ipsi.${ipsi_board}.control_state",$ipsi_control); set_data("hi.${site}.ipsi.${ipsi_board}.clock",substr($ipsi_cpeg,0,1)); set_data("hi.${site}.ipsi.${ipsi_board}.packet_interface",substr($ipsi_cpeg,2,1)); set_data("hi.${site}.ipsi.${ipsi_board}.expansion_archangel_link",substr($ipsi_cpeg,4,1)); set_data("hi.${site}.ipsi.${ipsi_board}.tone_generator",substr($ipsi_cpeg,6,1)); #print "IPSI: site=$site, board=$ipsi_board, ip=$ipsi_ip, service=$ipsi_service, control=$ipsi_control, CPEG=$ipsi_cpeg\n"; } } elsif($type == 2) { #if($line =~ /^(\d+) +(.+?) +(\w?) +(\w+?) +(\w+?) +(\w+?) +(\w+?) +(\w)/) { if($line =~ /^(\d+) +(\w[\w ]+?) +(\w+?) +([\w\.]+) +(\w+?) +(\d+) +(\w)/) { #print $line . "\n"; my $gw_num = $1; my $gw_name = $2; my $gw_sn = $3; my $gw_ip = $4; my $gw_type = $5; my $gw_region = $6; my $gw_registered = $7; $gw_name =~ s/ /_/g; set_data("hi.${site}.gateway.${gw_num}.${gw_name}.serial_number",$gw_sn); set_data("hi.${site}.gateway.${gw_num}.${gw_name}.ip_address",$gw_ip); set_data("hi.${site}.gateway.${gw_num}.${gw_name}.region",$gw_region); set_data("hi.${site}.gateway.${gw_num}.${gw_name}.type",$gw_type); set_data("hi.${site}.gateway.${gw_num}.${gw_name}.registered",$gw_registered); #print "GATEWAY: site=$site, num=$gw_num, name=$gw_name\n"; } } elsif($type == 3) { #if($line =~ / *(\d+) +(.+?) +(.+?) +(.) +(.) +(.+) +(.+) +(\d+) *$/) { if($line =~ / *(\d+)\s+(\w+?)\s+(.+?) +(\w) +(\w).+ (\d+) *$/) { my $surv_name = $2; my $surv_type = $3; my $surv_reg = $4; my $surv_act = $5; my $surv_net_reg = $6; #print $line . "\n"; set_data("hi.$site.surv.$surv_name.registered",$surv_reg); set_data("hi.$site.surv.$surv_name.active",$surv_act); set_data("hi.$site.surv.$surv_name.network_region",$surv_net_reg); set_data("hi.$site.surv.$surv_name.type",$surv_type); #print "SURV: site=$site, name=$surv_name, registered=$surv_reg, active=$surv_act, region=$surv_net_reg\n"; #die; } } elsif($type == 4) { if($line =~ /status station (\d+) +Page 1 /) { $station_dn = $1; } if($line =~ /^ +Administered Type: .+ +Service State: (.+?) +$/) { my $state = $1; $state =~ s/\/.*$//; set_data("lo.$site.status_station.$station_dn.service_state",$state); } } elsif($type == 5) { if($line =~ /^(\d+)\/(\d+) (\w+) +(.+?)\/(.+?) /) { my $group = $1; my $member = $2; my $service = $4; if($service eq "in-service") { $trunk_ins{$site}{$group}++; } else { $trunk_oos{$site}{$group}++; } #print "site $site trunk $group member $member $service\n"; } } elsif($type == 6) { if($line =~ /^(\d+) /) { #this is a list station line. Get data here, then the next line too my $line1 = $line; #print $line . "\n"; my $station = $1; my $port = trim(substr($line,13,8)); my $station_name = trim(substr($line,22,27)); my $dept = trim(substr($line,50,11)); $line = ; #my $line2 = $line; #print "$line1\n"; my $station_type = trim(substr($line,15,9)); #$station_name =~ s/ /_/g; #print "$station|$station_name|$dept\n"; #set_data("$site.station.$station.type",$station_type); #set_data("$site.station.$station.name",$station_name); if($port =~ /^S/) { $registered_stations{"lo.$site.station.$station"}=$station_name . ' (unregistered)'; } elsif($port =~ /^0/) { $registered_stations{"lo.$site.station.$station"}=$station_name . " (Port=$port)"; } else { $registered_stations{"lo.$site.station.$station"}=$station_name . " ($station_type)"; } $station_names{$station}=$station_name; } } elsif($type == 7) { if($line =~ /^(\d+) +\w+ +\w+ +\w +([\d\.]+) *$/) { my $reg; my $ver; my $gk; my $stn = $1; my $ip = $2; $line = ; if($line =~ /^ +(\d+) +(.+?) +(.+?) *$/) { $reg = $1; $ver = $2; $gk = $3; } $registered_stations{"lo.$site.station.$stn"}=$station_names{$stn} . " (ip=$ip;reg=$reg;ver=$ver;gk=$gk)"; #print "$1 is registered: " . $station_names{$1} . "_$2\n"; } elsif($line =~ /(\d+) +\w+ +\w+ +\w +([\d\.]+) +/) { #old version of reg #3311 9620 IP_Phone 2.0500 10.15.160.56 1 192.168.112.10 y $registered_stations{"lo.$site.station.$1"}=$station_names{$1} . "_$2"; } } elsif($type == 8) { if($line =~ / +(\d+) +(.+?) +(\d+) +$/) { my $station = $1; my $name = $2; my $dest = $3; if($name =~ /^(\d\d\d\d) /) { if($1 eq $station) { $name =~ s/^.....//; } } $name =~ s/ /_/g; set_data("hi.$site.call_forwarding.$station.$name",$dest); } } elsif($type == 9) { if($line =~ /Link State: (.+?) +(.+) *$/) { set_data("lo.$site.cdr.link_state.primary",$1); set_data("lo.$site.cdr.link_state.secondary",$2); } if($line =~ /^CDR Buffer % Full: +(.+?) +(.+?) *$/) { set_data("lo.$site.cdr.buffer_percent.primary",$1); set_data("lo.$site.cdr.buffer_percent.secondary",$2); } } #print "$line\n"; } close INPUT; #tally up the trunk status foreach my $t (keys %trunk_ins) { foreach my $g (keys %{$trunk_ins{$t}}) { #print "$g "; set_data("lo.$site.trunk_group_$g.in_service.count",$trunk_ins{$t}{$g}); } } foreach my $t (keys %trunk_oos) { foreach my $g (keys %{$trunk_oos{$t}}) { #print "$g "; set_data("lo.$site.trunk_group_$g.out_of_service.count",($trunk_ins{$t}{$g} + 0)); } } #report the station registration status foreach my $s (sort(keys %registered_stations)) { #print "$s "; set_data("$s.status",$registered_stations{$s}); #my $conn = $connected_stations{$s}; #if($conn ne '') { # set_data("$s.connection",$connected_stations{$s}); #} #if($s eq "0091") {die}; } dump_data();