aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristian Lyngstol <kly@kly@.no>2016-03-21 22:26:31 +0100
committerKristian Lyngstol <kly@kly@.no>2016-03-21 22:26:31 +0100
commit9317bfc07c0fb7ef0fbbf3afa3a0cba293d3184e (patch)
tree851e979110bd4425cb1620fdad064fa92396e598
parent727e4ab31aa6d1a754711d4cd29dbcefae2e952a (diff)
NMS: Add DHCP API
-rwxr-xr-xweb/nms.gathering.org/api/public/dhcp19
1 files changed, 19 insertions, 0 deletions
diff --git a/web/nms.gathering.org/api/public/dhcp b/web/nms.gathering.org/api/public/dhcp
new file mode 100755
index 0000000..d432af0
--- /dev/null
+++ b/web/nms.gathering.org/api/public/dhcp
@@ -0,0 +1,19 @@
+#! /usr/bin/perl
+# vim:ts=8:sw=8
+
+use lib '../../../../include';
+use nms::web qw (%json finalize_output);
+use strict;
+use warnings;
+use Data::Dumper;
+
+my $q = $nms::web::dbh->prepare('select distinct on (sysname) extract(epoch from date_trunc(\'second\',time)) as time,sysname from dhcp join switches on dhcp.switch = switches.switch where ' . $nms::web::when . ' order by sysname,time desc;');
+$q->execute();
+while ( my $ref = $q->fetchrow_hashref() ) {
+ my $sysname = $ref->{'sysname'};
+ $json{'dhcp'}{$ref->{'sysname'}} = $ref->{'time'};
+}
+
+$nms::web::cc{'max-age'} = "5";
+$nms::web::cc{'stale-while-revalidate'} = "30";
+finalize_output();