From 0bd0445cfd697ee373f9d923a3002be648a584c7 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Wed, 13 Feb 2019 21:44:32 +0100 Subject: Add basic collector-implementation References #195 This is the first dumb-ass implementation of the collector-api. It actually works fine for write AS IS, but has 0 safties. But I'm thinking the API itself is reasonably stable and ready for testing. I will need to extend it for dhcp-specific stuff, and the plan is to create a secondary table with metadata (hidden from the user) and a few other nice things. Also, indexes. We need indexes. Obviously. --- web/api/write/collector | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 web/api/write/collector (limited to 'web/api') 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(); -- cgit v1.2.3