aboutsummaryrefslogtreecommitdiffstats
path: root/web/api/public/dhcp
blob: f153a4913f6f65c2f6e7b253ac1cce077f540a66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#! /usr/bin/perl
# vim:ts=8:sw=8

use lib '/opt/gondul/include';
use nms::web qw (%json finalize_output);
use strict;
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 $sysname = $ref->{'sname'};
	$json{'dhcp'}{$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;");
$q2->execute();
while (my $ref = $q2->fetchrow_hashref()) {
	$nms::web::json{'networks'}{$ref->{name}} = $ref;
}

$nms::web::cc{'max-age'} = "10";
$nms::web::cc{'stale-while-revalidate'} = "30";
finalize_output();