Skip to content

Commit 9699e27

Browse files
committed
vap_stations_example.pl demonstrates querying JSON api for /stations data
1 parent 8bb3462 commit 9699e27

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

json/vap_stations_example.pl

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/perl -w
2+
use strict;
3+
use warnings;
4+
use diagnostics;
5+
use Carp;
6+
$SIG{ __DIE__ } = sub { Carp::confess( @_ ) };
7+
$SIG{ __WARN__ } = sub { Carp::confess( @_ ) };
8+
9+
# Un-buffer output
10+
$| = 1;
11+
use Getopt::Long;
12+
use JSON::XS;
13+
use HTTP::Request;
14+
use LWP;
15+
use LWP::UserAgent;
16+
use Data::Dumper;
17+
use Time::HiRes qw(usleep);
18+
use JSON;
19+
use lib '/home/lanforge/scripts';
20+
use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names flatten_list);
21+
22+
package main;
23+
# Default values for ye ole cmd-line args.
24+
our $Resource = 1;
25+
our $quiet = "yes";
26+
our $Host = "localhost";
27+
our $Port = 8080;
28+
our $HostUri = "http://$Host:$Port";
29+
our $Web = LWP::UserAgent->new;
30+
our $Decoder = JSON->new->utf8;
31+
our $ssid;
32+
our $security;
33+
our $passphrase;
34+
35+
my $usage = qq("$0 --host {ip or hostname} # connect to this
36+
--port {port number} # defaults to 8080
37+
);
38+
39+
40+
my $des_resource = 1;
41+
42+
GetOptions
43+
(
44+
'host=s' => \$::Host,
45+
'port=i' => \$::Port,
46+
'resource=i' => \$des_resource
47+
) || (print($usage) && exit(1));
48+
49+
$::HostUri = "http://$Host:$Port";
50+
51+
my $uri = "/stations/list";
52+
my $rh = json_request($uri);
53+
my $ra_links = get_links_from($rh, 'stations');
54+
# print(Dumper($ra_links));
55+
56+
my @attribs = ("ap", "signal", "tx rate", "rx rate", "capabilities");
57+
for my $sta_uri (@$ra_links) {
58+
my $with_fields = "$sta_uri?fields=station+bssid,capabilities,rx+rate,tx+rate,signal,ap";
59+
$rh = json_request($with_fields);
60+
#print(Dumper($rh));
61+
#print(Dumper($rh->{station}));
62+
print("Station ", $rh->{station}->{'station bssid'}, "\n");
63+
for my $k (@attribs) {
64+
print(" $k: ".$rh->{station}->{$k}."\n");
65+
}
66+
print("\n");
67+
}
68+
69+
70+

0 commit comments

Comments
 (0)