diff options
Diffstat (limited to 'web/api')
-rwxr-xr-x | web/api/read/oplog | 2 | ||||
-rwxr-xr-x | web/api/write/collector | 23 | ||||
-rwxr-xr-x | web/api/write/switches | 4 |
3 files changed, 27 insertions, 2 deletions
diff --git a/web/api/read/oplog b/web/api/read/oplog index f2ed3a7..88a7616 100755 --- a/web/api/read/oplog +++ b/web/api/read/oplog @@ -25,7 +25,7 @@ while (my $ref = $query->fetchrow_hashref()) { $meh{'timestamp'} = $ref->{'timestamp'}; $meh{'timestamp'} =~ s/ /T/; $meh{'timestamp'} =~ s/\+00$/Z/; - $meh{'timestamp'} =~ s/\+(\d\d)$/+\1:00/; + $meh{'timestamp'} =~ s/\+(\d\d)$/+$1:00/; push @{$nms::web::json{'oplog'}},\%meh; } diff --git a/web/api/write/collector b/web/api/write/collector new file mode 100755 index 0000000..eb20e8c --- /dev/null +++ b/web/api/write/collector @@ -0,0 +1,23 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 +use lib '/opt/gondul/include'; +use utf8; +use nms; +use nms::web qw($dbh db_safe_quote get_input finalize_output); + +use strict; +use warnings; + +my %input = %{JSON::XS::decode_json(get_input())}; + +my ($q,$check); +my $metric = $dbh->prepare("INSERT INTO metrics (src,metadata,data) VALUES(?,?,?)"); + +$nms::web::cc{'max-age'} = '0'; +$nms::web::cc{'stale-while-revalidate'} = '0'; +$nms::web::json{'state'} = 'ok'; + +foreach my $entry (@{$input{'data'}}) { + $metric->execute($input{'src'},JSON::XS::encode_json($input{'metadata'}),JSON::XS::encode_json($entry)); +} +finalize_output(); diff --git a/web/api/write/switches b/web/api/write/switches index e42c4b3..1f91d48 100755 --- a/web/api/write/switches +++ b/web/api/write/switches @@ -97,7 +97,9 @@ foreach my $tmp2 (@tmp) { push @dups, "not really, but: " . $switch{'placement'}; } if (defined($switch{'tags'})) { - $switch{'tags'} =~ s/'/"/g; + # MY GOD I HATE THIS + # But I'm too lazy to improve it more for now. + $switch{'tags'} = "[". join(",", map { "\"".$_."\"" } @{$switch{'tags'}})."]"; } my @set; map { |