diff options
author | Nicolai Tellefsen <niccofyren@gmail.com> | 2016-03-21 20:33:44 +0100 |
---|---|---|
committer | Nicolai Tellefsen <niccofyren@gmail.com> | 2016-03-21 20:33:44 +0100 |
commit | 5ba657e0bca0e4970b08583f6dfc94bfae34741c (patch) | |
tree | 44ed77deecd40ca984aae4bfa1bb949cb87bf7a0 /web/nms-public.gathering.org/old/switches-json.pl | |
parent | d528cad67897dd2c3b98ec15a82868ac2764e2c7 (diff) | |
parent | 727e4ab31aa6d1a754711d4cd29dbcefae2e952a (diff) |
Merge branch 'master' of https://github.com/tech-server/tgmanage
Diffstat (limited to 'web/nms-public.gathering.org/old/switches-json.pl')
-rwxr-xr-x | web/nms-public.gathering.org/old/switches-json.pl | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/web/nms-public.gathering.org/old/switches-json.pl b/web/nms-public.gathering.org/old/switches-json.pl new file mode 100755 index 0000000..74f4e5f --- /dev/null +++ b/web/nms-public.gathering.org/old/switches-json.pl @@ -0,0 +1,43 @@ +#! /usr/bin/perl +use CGI; +use GD; +use DBI; +use JSON::XS; +use lib '../../include'; +use nms; +my $cgi = CGI->new; + +my $dbh = nms::db_connect(); +my %json = (); + +my $q = $dbh->prepare('select switch,sysname,placement,zorder from switches natural join placements WHERE sysname != \'e3-2\''); # FULHACK to remove e3-2 from the maps +# my $q = $dbh->prepare('select switch,sysname,placement,zorder from switches natural join placements'); # FULHACK to remove e3-2 from the maps +my $q2 = $dbh->prepare('select distinct on (switch) switch,temp,time,sysname from switch_temp natural join switches order by switch,time desc'); +$q->execute(); +while (my $ref = $q->fetchrow_hashref()) { + $ref->{'placement'} =~ /\((-?\d+),(-?\d+)\),\((-?\d+),(-?\d+)\)/; + my ($x1, $y1, $x2, $y2) = ($1, $2, $3, $4); + my $sysname = $ref->{'sysname'}; + $json{'switches'}{$ref->{'switch'}} = { + sysname => $sysname, + x => $x2, + y => $y2, + width => $x1 - $x2, + height => $y1 - $y2, + zorder => $ref->{'zorder'} + }; +} + +$q2->execute(); +while (my $ref = $q2->fetchrow_hashref()) { + $json{'switches'}{$ref->{'switch'}}{'temp'} = $ref->{'temp'}; + $json{'switches'}{$ref->{'switch'}}{'time'} = $ref->{'time'}; +} +my $q = $dbh->prepare('select linknet,switch1,switch2 from linknets'); +$q->execute(); +while (my $ref = $q->fetchrow_hashref()) { + push @{$json{'linknets'}}, $ref; +} + +print $cgi->header(-type=>'text/json; charset=utf-8'); +print JSON::XS::encode_json(\%json); |