diff options
Diffstat (limited to 'web/nms.gathering.org/api/private')
-rwxr-xr-x | web/nms.gathering.org/api/private/comment-add | 20 | ||||
-rwxr-xr-x | web/nms.gathering.org/api/private/comment-change | 20 | ||||
-rwxr-xr-x | web/nms.gathering.org/api/private/comments | 15 | ||||
-rwxr-xr-x | web/nms.gathering.org/api/private/port-state | 31 | ||||
-rwxr-xr-x | web/nms.gathering.org/api/private/switch-add | 51 | ||||
-rwxr-xr-x | web/nms.gathering.org/api/private/switches-management | 30 |
6 files changed, 167 insertions, 0 deletions
diff --git a/web/nms.gathering.org/api/private/comment-add b/web/nms.gathering.org/api/private/comment-add new file mode 100755 index 0000000..beb7b21 --- /dev/null +++ b/web/nms.gathering.org/api/private/comment-add @@ -0,0 +1,20 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 +use lib '../../../../include'; +use utf8; +use nms::web; +use strict; +use warnings; + +my $data = db_safe_quote('comment'); +my $switch = db_safe_quote('switch'); +my $user = $dbh->quote($cgi->remote_user() || "undefined"); + +my $q = $nms::web::dbh->prepare("INSERT INTO switch_comments (time,username,switch,comment) values (now(),$user,(select switch from switches where sysname = $switch limit 1),$data)"); +$q->execute(); + +$nms::web::cc{'max-age'} = '0'; +$nms::web::cc{'stale-while-revalidate'} = '0'; +$nms::web::json{'state'} = 'ok'; + +finalize_output(); diff --git a/web/nms.gathering.org/api/private/comment-change b/web/nms.gathering.org/api/private/comment-change new file mode 100755 index 0000000..ccf336d --- /dev/null +++ b/web/nms.gathering.org/api/private/comment-change @@ -0,0 +1,20 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 +use lib '../../../../include'; +use utf8; +use nms; +use nms::web; +use strict; +use warnings; + +my $id = db_safe_quote('comment'); +my $state = db_safe_quote('state'); + +my $q = $nms::web::dbh->prepare("UPDATE switch_comments SET state = " . $state . " WHERE id = " . $id . ";"); +$q->execute(); + +$nms::web::cc{'max-age'} = '0'; +$nms::web::cc{'stale-while-revalidate'} = '0'; +$nms::web::json{'state'} = 'ok'; + +finalize_output(); diff --git a/web/nms.gathering.org/api/private/comments b/web/nms.gathering.org/api/private/comments new file mode 100755 index 0000000..4adfb2b --- /dev/null +++ b/web/nms.gathering.org/api/private/comments @@ -0,0 +1,15 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +use lib '../../../../include'; +use nms::web; +use strict; +use warnings; + +my $query = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,state,username,id,comment from switch_comments natural join switches where state != \'delete\' order by time desc'); +$query->execute(); +while (my $ref = $query->fetchrow_hashref()) { + push @{$nms::web::json{'comments'}{$ref->{'sysname'}}{'comments'}},$ref; +} + +nms::web::finalize_output(); diff --git a/web/nms.gathering.org/api/private/port-state b/web/nms.gathering.org/api/private/port-state new file mode 100755 index 0000000..1f30181 --- /dev/null +++ b/web/nms.gathering.org/api/private/port-state @@ -0,0 +1,31 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +use lib '../../../../include'; +use nms::web; +use strict; +use warnings; + +my $query = 'select sysname,extract(epoch from date_trunc(\'second\',time)) as time, ifname,ifhighspeed,ifhcinoctets,ifhcoutoctets from polls natural join switches where time in (select max(time) from polls where ' . $nms::web::when . ' group by switch,ifname);'; +my $q = $nms::web::dbh->prepare($query); +$q->execute(); + +while (my $ref = $q->fetchrow_hashref()) { + my @fields = ('ifhighspeed','ifhcoutoctets','ifhcinoctets'); + foreach my $val (@fields) { + $nms::web::json{'switches'}{$ref->{'sysname'}}{'ports'}{$ref->{'ifname'}}{$val} = $ref->{$val}; + } + $nms::web::json{'switches'}{$ref->{'sysname'}}{'ports'}{$ref->{'ifname'}}{'time'} = $ref->{'time'}; +} + +my $q3 = $nms::web::dbh->prepare('select distinct on (switch) switch,temp,time,sysname from switch_temp natural join switches where ' . $nms::web::when . ' order by switch,time desc'); + + +$q3->execute(); +while (my $ref = $q3->fetchrow_hashref()) { + my $sysname = $ref->{'sysname'}; + $nms::web::json{'switches'}{$ref->{'sysname'}}{'temp'} = $ref->{'temp'}; + $nms::web::json{'switches'}{$ref->{'sysname'}}{'temp_time'} = $ref->{'time'}; +} + +finalize_output(); diff --git a/web/nms.gathering.org/api/private/switch-add b/web/nms.gathering.org/api/private/switch-add new file mode 100755 index 0000000..2b1f306 --- /dev/null +++ b/web/nms.gathering.org/api/private/switch-add @@ -0,0 +1,51 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +#use CGI qw(fatalsToBrowser); +use DBI; +use lib '../../../../include'; +use nms; +use nms::web qw(%get_params %json finalize_output get_input); +use strict; +use warnings; +use JSON; +use Data::Dumper; + +$nms::web::cc{'max-age'} = "0"; + +my $in = get_input(); +my @tmp = @{JSON::XS::decode_json($in)}; + +my @added; +my @dups; + +my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); +my $insert = $nms::web::dbh->prepare("INSERT INTO SWITCHES (ip, sysname, switchtype,placement) VALUES(?,?,'ex2200',?);"); + +foreach my $tmp2 (@tmp) { + my %switch = %{$tmp2}; + my $affected = 0; + + $sth->execute( $switch{'sysname'}); + while ( my @row = $sth->fetchrow_array ) { + $affected += 1; + } + + if ($affected == 0) { + my ($x1,$x2,$y1,$y2); + $x1 = $switch{'placement'}{'x1'}; + $y1 = $switch{'placement'}{'y1'}; + $x2 = $switch{'placement'}{'xx'}; + $y2 = $switch{'placement'}{'yy'}; + my $place = "(($x1,$y1),($x2,$y2))"; + $json{'foo'} = $place . "foo"; + $insert->execute($switch{'mgtmt4'}, $switch{'sysname'},$place); + push @added, $switch{'sysname'}; + } else { + push @dups, $switch{'sysname'}; + } +} +$json{'switches_addded'} = \@added; +$json{'switches_duplicate'} = \@dups; + +finalize_output(); diff --git a/web/nms.gathering.org/api/private/switches-management b/web/nms.gathering.org/api/private/switches-management new file mode 100755 index 0000000..474f674 --- /dev/null +++ b/web/nms.gathering.org/api/private/switches-management @@ -0,0 +1,30 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +use CGI qw(fatalsToBrowser); +use DBI; +use lib '../../../../include'; +use nms; +use nms::web; +use strict; +use warnings; +use Data::Dumper; + +$nms::web::cc{'max-age'} = "60"; + +my $q2 = $nms::web::dbh->prepare('select sysname,ip,switchtype,poll_frequency,community,last_updated from switches '); + +$q2->execute(); +while (my $ref = $q2->fetchrow_hashref()) { + my $sysname = $ref->{'sysname'}; + $nms::web::json{'switches'}{$ref->{'sysname'}} = $ref; +} + +my $q4 = $nms::web::dbh->prepare('select linknet, (select sysname from switches where switch = switch1) as sysname1, addr1, (select sysname from switches where switch = switch2) as sysname2,addr2 from linknets'); + +$q4->execute(); +while (my $ref = $q4->fetchrow_hashref()) { + $nms::web::json{'linknets'}{$ref->{'linknet'}} = $ref; +} + +finalize_output(); |