Last year I published the blog post Cacti – How to graph CCQ on Ubiquiti devices. Recently I updated ubiquiti_ccq.pl script, so it will work with all NanoBridge and PowerBridge devices.
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Cookies;
use JSON;
if (($#ARGV+1) ne 1) {
exit();
}
my $host = $ARGV[0];
my $cookie_jar = HTTP::Cookies->new();
my $browser = LWP::UserAgent->new();
my $response = '';
my $directory = '';
my $json = JSON->new();
$browser->cookie_jar( $cookie_jar);
$response = $browser->get(
"https://${host}/login.cgi"
);
$response = $browser->post(
"https://${host}/login.cgi",
Content_Type => 'form-data',
Content => [
username => 'USER',
password => 'PASS',
],
);
$response = $browser->get(
"https://${host}/index.cgi"
);
# <link rel="shortcut icon" href="/120816.1338/favicon.ico" >
# Use "120816.1338" directory
# <link rel="shortcut icon" href="/110723.1014/favicon.ico" >
# Use "110723.1014" directory
if ($response->content =~ m/<link rel="shortcut icon" href="\/.*\/favicon.ico".*>/) {
$directory = $&;
$directory =~ s/<link.*href="\/(.*)\/.*".*>/$1/;
$response = $browser->get(
"https://${host}/${directory}/status.cgi"
);
print ($json->decode($response->content)->{wireless}->{ccq}/10 . "\n");
}
Please remember to replace
USER
and PASS
with desired credentials.