diff options
author | Kristian Lyngstol <kristian@bohemians.org> | 2015-04-13 17:50:50 +0200 |
---|---|---|
committer | Kristian Lyngstol <kristian@bohemians.org> | 2015-04-13 17:50:50 +0200 |
commit | 250b12289f959341ed9b1dde435c5bb97e8ca6dc (patch) | |
tree | b6e1a713dc84cdde77866075a987707e9b462e77 | |
parent | 868a1c5a7c5b1785109a533151bb9e631adf9974 (diff) |
Add dhcp-json.pl to get DHCP data in json-format
-rwxr-xr-x | web/nms.gathering.org/dhcp-json.pl | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/web/nms.gathering.org/dhcp-json.pl b/web/nms.gathering.org/dhcp-json.pl new file mode 100755 index 0000000..210c434 --- /dev/null +++ b/web/nms.gathering.org/dhcp-json.pl @@ -0,0 +1,19 @@ +#! /usr/bin/perl +use CGI qw(fatalsToBrowser); +use DBI; +use lib '../../include'; +use nms; +my $cgi = CGI->new; + +my $dbh = nms::db_connect(); + +my $q = $dbh->prepare('select sysname,EXTRACT(EPOCH FROM last_ack) as last_ack from switches natural join dhcp '); +$q->execute(); + +my %json = (); +while (my $ref = $q->fetchrow_hashref()) { + $json{'dhcp'}{$ref->{'sysname'}}{'last_ack'} = $ref->{'last_ack'}; +} +$dbh->disconnect; +print $cgi->header(-type=>'text/json; charset=utf-8'); +print JSON::XS::encode_json(\%json); |