Motorola MB8611 Stats
Not the best code but it works. To get all the header info, login while developer tools is open in chrome and then copy the request parameters. Output is consumed by telegraf
#!/usr/bin/perl -w
use strict;
use LWP::Simple;
use JSON qw( decode_json encode_json);
my $url = 'https://192.168.100.1/HNAP1/';
# Headers from developer tools
my $ns_headers = [
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0',
'Accept' => 'application/json',
'Accept-Language' => 'en-US,en;q=0.5',
'Content-Type' => 'application/json',
'SOAPACTION' => '"http://purenetworks.com/HNAP1/GetMultipleHNAPs"',
'HNAP_AUTH' => 'AUTH_STRING',
'Origin' => 'https://192.168.100.1',
'Connection' => 'keep-alive',
'Referer' => 'https://192.168.100.1/MotoStatusConnection.html',
'Cookie' => 'Secure; Secure; uid=myuid;PrivateKey=PKEYHERE',
'Sec-Fetch-Dest' => 'empty',
'Sec-Fetch-Mode' => 'cors',
'Sec-Fetch-Site' => 'same-origin'
];
my $DEBUG = 0;
my %mapping;
my $ua = LWP::UserAgent->new();
$ua->ssl_opts(SSL_verify_mode => 0x00, verify_hostname => 0);
my $payload = {"GetMultipleHNAPs" => {"GetHomeConnection" => "","GetHomeAddress" => ""}};
my $encode = encode_json($payload);
my $result = grab_stats($encode);
for my $info (keys %{$result->{"GetHomeConnectionResponse"}}) {
print "$info : " . $result->{"GetHomeConnectionResponse"}->{$info} ."\n" if $DEBUG;
}
# Downstream
$payload = {"GetMultipleHNAPs" => {"GetMotoStatusDownstreamChannelInfo" => "","GetMotoStatusUpstreamChannelInfo" => ""}};
$encode = encode_json($payload);
$result = grab_stats($encode);
my $decode = $result->{"GetMotoStatusDownstreamChannelInfoResponse"}->{"MotoConnDownstreamChannel"};
my @indx = split(/\+/, $decode);
print "Downstream\n" if $DEBUG;
my $poststr = "";
foreach my $chan (@indx) {
my @items = split(/\^/, $chan);
$items[0] =~ s/\|//g;
print "Channel $items[0] Lock-status $items[1] Modulation $items[2] ID $items[3] Freq(mhz) $items[4] Pwr(dbmv) $items[5] SNR (db) $items[6] Corrected $items[7] Uncorrected $items[8]\n" if $DEBUG;
my $mod = $items[2];
$mod =~ s/ /_/g;
#I see occasional spaces, remove 'em
my $pwr = $items[5];
$pwr =~ s/^\s+//;
$poststr .= "modem_down,downchannel=$items[0],status=$items[1],modulation=$mod freq=$items[4],pwr=$pwr,snr=$items[6],corrected=$items[7],uncorrected=$items[8]\n";
}
# Upstream
$decode = $result->{"GetMotoStatusUpstreamChannelInfoResponse"}->{"MotoConnUpstreamChannel"};
@indx = split(/\+/, $decode);
print "Upstream\n" if $DEBUG;
foreach my $chan (@indx) {
my @items = split(/\^/, $chan);
$items[0] =~ s/\|//g;
print "Channel $items[0] Lock-status $items[1] Type $items[2] ID $items[3] Symb rate $items[4] Freq(mhz) $items[5] Pwr (dbmv) $items[6]\n" if $DEBUG;
$poststr .="modem_up,upchannel=$items[0],status=$items[1],type=$items[2] symb_rate=$items[4],freq=$items[5],pwr=$items[6]\n";
}
print $poststr;
sub grab_stats {
my $encode = shift;
my $r = HTTP::Request->new('POST', $url, $ns_headers, $encode);
my $res = $ua->request($r);
my $decode = decode_json($res->decoded_content);
return $decode->{"GetMultipleHNAPsResponse"};
}