It is quite easy to use the NBI from Perl. There are many option and libraries that can used. For this example, I used the 'normal' HTTPS support with LWP::UserAgent and the JSON module.
This sample will print out a basic inventory of the AccessPoints the are known to Prime Infrastructure. If a large number of AccessPoints are present it could easily be changed to use paging.
To run the script below, you will need to install JSON and LWP::Protocol::https from CPAN.
#!/opt/local/bin/perl -w use strict; use JSON -support_by_pp; use LWP 5.64; use LWP::UserAgent; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; my $ua = LWP::UserAgent->new; my $BASE_URL = 'https://172.18.138.90/webacs/api/v1/'; my $UN="root"; my $PW="Public123"; sub fetch ($){ my ($url) = @_; my $req = HTTP::Request->new(GET => $BASE_URL.$url); $req->authorization_basic($UN,$PW); return $ua->request($req)->content or die ("Cannot read from ".$BASE_URL.$url); } my $content = fetch('data/AccessPoints.json?.full=true'); my $json = new JSON; # these are some nice json options to relax restrictions a bit: my $json_text = $json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->decode($content); foreach my $ap (@{$json_text->{queryResponse}->{'entity'}}){ print "------------------------\nAccess Point ".$ap->{'accessPointsDTO'}->{'@id'}."\n"; print "Model:".$ap->{'accessPointsDTO'}->{'model'}."\n"; print "MAC Address:".$ap->{'accessPointsDTO'}->{'macAddress'}."\n"; print "Serial Number:".$ap->{'accessPointsDTO'}->{'serialNumber'}."\n"; print "Software Version:".$ap->{'accessPointsDTO'}->{'softwareVersion'}."\n"; print "Status:".$ap->{'accessPointsDTO'}->{'status'}."\n"; print "Location:".$ap->{'accessPointsDTO'}->{'location'}."\n"; }
The result of running the program is:
------------------------ Access Point 13544533 Model:AIR-CAP3602I-A-K9 MAC Address:c4:0a:cb:88:34:10 Serial Number:FTX1552GKU8 Software Version:7.2.103.0 Status:MINOR Location:default location ------------------------ Access Point 13544535 Model:AIR-CAP3602I-A-K9 MAC Address:c4:0a:cb:88:41:80 Serial Number:FTX1552GKUB Software Version:7.2.103.0 Status:CLEARED Location:default location
The returned JSON is as follows:
{"queryResponse": {"@type":"AccessPoints", "@rootUrl":"https://172.18.138.90/webacs/api/v1/data", "@requestUrl":"https://172.18.138.90/webacs/api/v1/data/AccessPoints?.full=true", "@responseType":"listEntityInstances", "entity":[ {"@url":"https://172.18.138.90/webacs/api/v1/data/AccessPoints/13544533", "@type":"AccessPoints", "@dtoType":"accessPointsDTO", "accessPointsDTO": {"@id":"13544533", "@displayName":"13544533", "adminStatus":"ENABLE", "bootVersion":"12.4.23.0", "clientCount":0, "clientCount_2_4GHz":0, "clientCount_5GHz":0, "controllerIpAddress":"192.168.100.25", "controllerName":"TST-WLC3", "countryCode":"US", "ethernetMac":"c4:64:13:b4:20:4a", "hreapEnabled":false, "ipAddress":"192.168.90.87", "location":"default location", "lwappUpTime":10846300, "macAddress":"c4:0a:cb:88:34:10", "model":"AIR-CAP3602I-A-K9 ", "name":"APc464.13b4.204a", "serialNumber":"FTX1552GKU8", "softwareVersion":"7.2.103.0", "status":"MINOR", "type":"AP3600I", "upTime":50884700}}, {"@url":"https://172.18.138.90/webacs/api/v1/data/AccessPoints/13544535", "@type":"AccessPoints", "@dtoType":"accessPointsDTO", "accessPointsDTO": {"@id":"13544535", "@displayName":"13544535", "adminStatus":"ENABLE", "bootVersion":"12.4.23.0", "clientCount":0, "clientCount_2_4GHz":0, "clientCount_5GHz":0, "controllerIpAddress":"192.168.100.25", "controllerName":"TST-WLC3", "countryCode":"US", "ethernetMac":"c4:64:13:b4:21:15", "hreapEnabled":false, "ipAddress":"192.168.90.89", "location":"default location", "lwappUpTime":10845000, "macAddress":"c4:0a:cb:88:41:80", "model":"AIR-CAP3602I-A-K9 ", "name":"APc464.13b4.2115", "serialNumber":"FTX1552GKUB", "softwareVersion":"7.2.103.0", "status":"CLEARED", "type":"AP3600I", "upTime":50676200}}]}}