import from HEAD:
[freeradius.git] / dialup_admin / bin / showmodem
1 #!/usr/bin/perl
2 #
3 # This works with Net-SNMP and UCD-SNMP
4
5 $host=shift;
6 $user=shift;
7 $comm=shift || "public";
8 $type=shift|| "xml";
9
10 $conf='/usr/local/dialup_admin/conf/admin.conf';
11 open CONF, "<$conf"
12         or die "Could not open configuration file\n";
13 while(<CONF>){
14         chomp;
15         ($key,$val)=(split /:\s*/,$_);
16         $snmp_type = $val if ($key eq 'general_snmp_type');
17         $snmpget = $val if ($key eq 'general_snmpget_command');
18         $snmpwalk = $val if ($key eq 'general_snmpwalk_command');
19 }
20 close CONF;
21
22 die "general_snmp_type directive is not set in admin.conf\n" if ($snmp_type eq '');
23 die "Could not find snmpwalk binary. Please make sure that the \$snmpwalk variable points to the right location\n" if (! -x $snmpwalk);
24
25 if ($snmp_type = 'ucd') {
26         $snmpgetcmd="$snmpget $host $comm";
27         $snmpwalkcmd="$snmpwalk $host $comm";
28 }
29 if ($snmp_type = 'net') {
30         $snmpgetcmd="$snmpget -v 1 -c $comm $host";
31         $snmpwalkcmd="$snmpwalk -v 1 -c $comm $host";
32 }
33 #DEBUG#print "$snmpwalkcmd\n"; print "$snmpgetcmd\n";
34 @ModulationScheme = (
35         "error",
36         "unknown",
37         "bell103a",
38         "bell212a",
39         "v21",
40         "v22",
41         "v22bis",
42         "v32",
43         "v32bis",
44         "vfc",
45         "v34",
46         "v17",
47         "v29",
48         "v33",
49         "k56flex",
50         "v23",
51         "v32terbo",
52         "v34plus",
53         "v90",
54         "v27ter",
55 );
56                   
57 @Protocol = (
58         "error",
59         "normal",
60         "direct",
61         "reliableMNP",
62         "reliableLAPM",
63         "syncMode",
64         "asyncMode",
65         "ara10",
66         "ara20",
67         "unknown",
68 );
69 #DEBUG#print "$snmpwalkcmd enterprises.9.2.9.2.1.18 | grep $user\n";             
70 $modem=`$snmpwalkcmd enterprises.9.2.9.2.1.18 | grep $user`;
71 if($modem=~/enterprises\.9\.2\.9\.2\.1\.18\.(\d+) =/){
72   $modem=$1;
73   $slot=(1+int($modem/120));
74   $port=$modem%120-1;
75   $modem="$slot.$port";
76
77 #DEBUG#print "$snmpgetcmd enterprises.9.9.47.1.3.1.1.9.$modem\n";                
78   $duration=`$snmpgetcmd enterprises.9.9.47.1.3.1.1.9.$modem` or die "No MIB\n";
79   $duration=~/\) (.*)\./;
80   $duration=$1;
81
82 #DEBUG#print "$snmpgetcmd enterprises.9.9.47.1.3.1.1.12.$modem\n";               
83   $modulation=`$snmpgetcmd enterprises.9.9.47.1.3.1.1.12.$modem` or die "No MIB\n";
84   $modulation=~/ \= (\d+)/;
85   $modulation=$ModulationScheme[$1];
86
87 #DEBUG#print "$snmpgetcmd enterprises.9.9.47.1.3.1.1.13.$modem\n";               
88   $protocol=`$snmpgetcmd enterprises.9.9.47.1.3.1.1.13.$modem` or die "No MIB\n";
89   $protocol=~/ \= (\d+)/;
90   $protocol=$Protocol[$1];
91
92 #DEBUG#print "$snmpgetcmd enterprises.9.9.47.1.3.1.1.14.$modem\n";               
93   $txrate=`$snmpgetcmd enterprises.9.9.47.1.3.1.1.14.$modem` or die "No MIB\n";
94   $txrate=~/Gauge32\: (\d+)/;
95   $txrate=$1;
96
97 #DEBUG#print "$snmpgetcmd enterprises.9.9.47.1.3.1.1.15.$modem\n";               
98   $rxrate=`$snmpgetcmd enterprises.9.9.47.1.3.1.1.15.$modem` or die "No MIB\n";
99   $rxrate=~/Gauge32\: (\d+)/;
100   $rxrate=$1;
101
102 #DEBUG#print "$snmpgetcmd enterprises.9.9.47.1.3.1.1.17.$modem\n";               
103   $rxsignal=`$snmpgetcmd enterprises.9.9.47.1.3.1.1.17.$modem` or die "No MIB\n";
104 #  $rxsignal=~ s/INTEGER\://;
105   $rxsignal=~/ \= (.*)\n/;
106   $rxsignal=$1;
107
108   if($type eq "xml"){
109     print "<User>$user</User>\n";
110     print "\t<Duration>$duration</Duration>\n";
111     print "\t<Modulation>$modulation</Modulation>\n";
112     print "\t<Protocol>$protocol</Protocol>\n";
113     print "\t<TxRate>$txrate</TxRate>\n";
114     print "\t<RxRate>$rxrate</RxRate>\n";
115     print "\t<RxSignal>$rxsignal dBm</RxSignal>\n\n";
116   }else{
117     printf("%14s\t%s\n","User",$user);
118     printf("%14s\t%s\n","Duration",$duration);
119     printf("%14s\t%s\n","Modulation",$modulation);
120     printf("%14s\t%s\n","Protocol",$protocol);
121     printf("%14s\t%s\n","TxRate",$txrate);
122     printf("%14s\t%s\n","RxRate",$rxrate);
123     printf("%14s\t%s dBm\n\n","RxSignal",$rxsignal);
124   }
125 }