aboutsummaryrefslogtreecommitdiffstats
path: root/web/api/public
diff options
context:
space:
mode:
authorOle Mathias Aa. Heggem <olemathias.aa.heggem@gmail.com>2019-04-16 18:31:57 +0100
committerolemathias.aa.heggem@gmail.com <root@gondul.tg19.gathering.org>2019-04-16 18:31:57 +0100
commit8da1d9b3b52f91989f2a8f54d07f5dcc75f93d17 (patch)
tree14d6b78445ec95529fda70cc088e21df2973691d /web/api/public
parent82549fbe361534a34791b4098069a070cdc7e1f7 (diff)
Use new metrics in dhcp api
Diffstat (limited to 'web/api/public')
-rwxr-xr-xweb/api/public/dhcp21
1 files changed, 16 insertions, 5 deletions
diff --git a/web/api/public/dhcp b/web/api/public/dhcp
index f153a49..3e56f59 100755
--- a/web/api/public/dhcp
+++ b/web/api/public/dhcp
@@ -8,13 +8,24 @@ use warnings;
use Data::Dumper;
nms::web::setwhen('60m');
-my $q = $nms::web::dbh->prepare('select distinct on (name) extract(epoch from date_trunc(\'second\',time)) as time,name from dhcp join networks on dhcp.network = networks.network where ' . $nms::web::when . ' order by name,time desc;');
-$q->execute();
-while ( my $ref = $q->fetchrow_hashref() ) {
+#my $q = $nms::web::dbh->prepare('select distinct on (name) extract(epoch from date_trunc(\'second\',time)) as time,name from dhcp join networks on dhcp.network = networks.network where ' . $nms::web::when . ' order by name,time desc;');
+my $q_v4 = $nms::web::dbh->prepare("select distinct on (name) extract(epoch from date_trunc('second', metrics.time)) as time, networks.name as name from metrics JOIN networks ON (data->>'clientip')::inet <<= networks.subnet4 where $nms::web::when order by name,time desc;");
+$q_v4->execute();
+while ( my $ref = $q_v4->fetchrow_hashref() ) {
my $sysname = $ref->{'sname'};
- $json{'dhcp'}{$ref->{'name'}} = $ref->{'time'};
+ $json{'dhcp4'}{$ref->{'name'}} = $ref->{'time'};
}
-my $q2 = $nms::web::dbh->prepare("select name,count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp natural join networks where $nms::web::when group by networks.name;");
+
+my $q_v6 = $nms::web::dbh->prepare("select distinct on (name) extract(epoch from date_trunc('second', metrics.time)) as time, networks.name as name from metrics JOIN networks ON (data->>'clientip')::inet <<= networks.subnet6 where $nms::web::when order by name,time desc;");
+$q_v6->execute();
+while ( my $ref = $q_v6->fetchrow_hashref() ) {
+ my $sysname = $ref->{'sname'};
+ $json{'dhcp6'}{$ref->{'name'}} = $ref->{'time'};
+}
+
+
+#my $q2 = $nms::web::dbh->prepare("select name,count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp natural join networks where $nms::web::when group by networks.name;");
+my $q2 = $nms::web::dbh->prepare("SELECT networks.name, count(distinct data->>'clientmac') as clients, count(distinct data->>'clientip') as addresses, count(data->>'clientmac') as acks from metrics JOIN networks ON (data->>'clientip')::inet <<= networks.subnet4 WHERE $nms::web::when GROUP BY networks.name;");
$q2->execute();
while (my $ref = $q2->fetchrow_hashref()) {
$nms::web::json{'networks'}{$ref->{name}} = $ref;