aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build/schema.sql113
-rwxr-xr-xweb/api/read/oplog2
-rwxr-xr-xweb/api/write/collector23
-rwxr-xr-xweb/api/write/switches4
-rw-r--r--web/js/nms-types.js48
-rw-r--r--web/js/nms-ui-switch.js20
6 files changed, 167 insertions, 43 deletions
diff --git a/build/schema.sql b/build/schema.sql
index 9288098..d40bad1 100644
--- a/build/schema.sql
+++ b/build/schema.sql
@@ -150,6 +150,20 @@ ALTER SEQUENCE public.linknets_linknet_seq OWNED BY public.linknets.linknet;
--
+-- Name: metrics; Type: TABLE; Schema: public; Owner: postgres
+--
+
+CREATE TABLE public.metrics (
+ ts timestamp with time zone DEFAULT now(),
+ src text,
+ metadata jsonb,
+ data jsonb
+);
+
+
+ALTER TABLE public.metrics OWNER TO postgres;
+
+--
-- Name: networks; Type: TABLE; Schema: public; Owner: nms
--
@@ -448,6 +462,13 @@ CREATE INDEX dhcp_time ON public.dhcp USING btree ("time");
--
+-- Name: ping_brin_time; Type: INDEX; Schema: public; Owner: nms
+--
+
+CREATE INDEX ping_brin_time ON public.ping USING brin ("time");
+
+
+--
-- Name: ping_index; Type: INDEX; Schema: public; Owner: nms
--
@@ -462,6 +483,20 @@ CREATE INDEX ping_secondary_index ON public.ping_secondary_ip USING btree ("time
--
+-- Name: ping_switch_time_btree; Type: INDEX; Schema: public; Owner: nms
+--
+
+CREATE INDEX ping_switch_time_btree ON public.ping USING btree (switch, "time");
+
+
+--
+-- Name: ping_switch_time_unique_btree; Type: INDEX; Schema: public; Owner: nms
+--
+
+CREATE UNIQUE INDEX ping_switch_time_unique_btree ON public.ping USING btree (switch, "time");
+
+
+--
-- Name: seen_mac_addr_family; Type: INDEX; Schema: public; Owner: nms
--
@@ -476,17 +511,66 @@ CREATE INDEX seen_mac_seen ON public.seen_mac USING btree (seen);
--
--- Name: snmp_time; Type: INDEX; Schema: public; Owner: nms
+-- Name: snmp_brin_switch_time; Type: INDEX; Schema: public; Owner: nms
--
-CREATE INDEX snmp_time ON public.snmp USING btree ("time");
+CREATE INDEX snmp_brin_switch_time ON public.snmp USING brin (switch, "time");
+
+
+--
+-- Name: snmp_id_desc_btree; Type: INDEX; Schema: public; Owner: nms
+--
+
+CREATE INDEX snmp_id_desc_btree ON public.snmp USING btree (id DESC);
--
--- Name: snmp_time15; Type: INDEX; Schema: public; Owner: nms
+-- Name: snmp_id_desc_switch_btree; Type: INDEX; Schema: public; Owner: nms
--
-CREATE INDEX snmp_time15 ON public.snmp USING btree (id, switch);
+CREATE INDEX snmp_id_desc_switch_btree ON public.snmp USING btree (id DESC, switch);
+
+
+--
+-- Name: snmp_id_switch_btree; Type: INDEX; Schema: public; Owner: nms
+--
+
+CREATE INDEX snmp_id_switch_btree ON public.snmp USING btree (id, switch);
+
+
+--
+-- Name: snmp_switch_btree; Type: INDEX; Schema: public; Owner: nms
+--
+
+CREATE INDEX snmp_switch_btree ON public.snmp USING btree (switch);
+
+
+--
+-- Name: snmp_switch_id_btree; Type: INDEX; Schema: public; Owner: nms
+--
+
+CREATE INDEX snmp_switch_id_btree ON public.snmp USING btree (switch, id);
+
+
+--
+-- Name: snmp_switch_id_desc_btree; Type: INDEX; Schema: public; Owner: nms
+--
+
+CREATE INDEX snmp_switch_id_desc_btree ON public.snmp USING btree (switch, id DESC);
+
+
+--
+-- Name: snmp_switch_time_btree; Type: INDEX; Schema: public; Owner: nms
+--
+
+CREATE INDEX snmp_switch_time_btree ON public.snmp USING btree (switch, "time");
+
+
+--
+-- Name: snmp_time; Type: INDEX; Schema: public; Owner: nms
+--
+
+CREATE INDEX snmp_time ON public.snmp USING btree ("time");
--
@@ -497,6 +581,20 @@ CREATE INDEX snmp_time6 ON public.snmp USING btree ("time" DESC, switch);
--
+-- Name: snmp_time_brin; Type: INDEX; Schema: public; Owner: nms
+--
+
+CREATE INDEX snmp_time_brin ON public.snmp USING brin ("time");
+
+
+--
+-- Name: snmp_unique_switch_time_btree; Type: INDEX; Schema: public; Owner: nms
+--
+
+CREATE UNIQUE INDEX snmp_unique_switch_time_btree ON public.snmp USING btree (switch, "time");
+
+
+--
-- Name: switches_switch; Type: INDEX; Schema: public; Owner: nms
--
@@ -570,6 +668,13 @@ GRANT ALL ON TABLE public.linknets TO dhcptail;
--
+-- Name: TABLE metrics; Type: ACL; Schema: public; Owner: postgres
+--
+
+GRANT ALL ON TABLE public.metrics TO nms;
+
+
+--
-- Name: TABLE networks; Type: ACL; Schema: public; Owner: nms
--
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 {
diff --git a/web/js/nms-types.js b/web/js/nms-types.js
index 769bd32..308475f 100644
--- a/web/js/nms-types.js
+++ b/web/js/nms-types.js
@@ -36,6 +36,8 @@ class nmsType {
validate(input) {
return true;
}
+ // Always return text-representation
+ // Should be matched by fromString()
toString() {
if (this._value == null || this._value == undefined) {
return ""
@@ -43,8 +45,16 @@ class nmsType {
return this._value.toString();
}
}
+ // Set value from string-input
+ fromString(input) {
+ if (this.validate(input)) {
+ this._value = input;
+ } else {
+ throw "Invalid input. Use .validate() before setting stuff please. I am " + this + " and my input is " + input
+ }
+ }
initial(v) {
- this._value = this._valueParse(v);
+ this.value = v;
if(this.priority == nmsPriority.newOnly) {
this.ro = true;
}
@@ -52,15 +62,8 @@ class nmsType {
get value() {
return this._value;
}
- _valueParse(input) {
- return input;
- }
set value(input) {
- if (this.validate(input)) {
- this._value = this._valueParse(input);
- } else {
- throw "Invalid input. Use .validate() before setting stuff please. I am " + this + " and my input is " + input
- }
+ this._value = input;
}
get _defaultPriority() {
return nmsPriority.optional;
@@ -125,21 +128,9 @@ class nmsTypeNetwork extends nmsType {
}
}
class nmsTypeJSON extends nmsType {
- get value() {
- if (this._value == null || this._value == undefined) {
- return "";
- }
- return JSON.stringify(this._value)
- }
- set value(input) {
- super.value = input;
- }
- /* This should probably actually know the basic template
- * for a placement-object...
- */
validate(input) {
try {
- this._valueParse(input);
+ JSON.parse(input);
this.validationReason = "OK"
return true;
} catch(e) {
@@ -147,11 +138,14 @@ class nmsTypeJSON extends nmsType {
return false;
}
}
- _valueParse(input) {
- if (input instanceof Object) {
- return input;
- } else {
- return JSON.parse(input);
+ toString() {
+ return JSON.stringify(this._value);
+ }
+ fromString(input) {
+ try {
+ this.value = JSON.parse(input);
+ } catch(e) {
+ throw "Invalid input. Use .validate() before setting stuff please. I am " + this + " and my input is " + input
}
}
}
diff --git a/web/js/nms-ui-switch.js b/web/js/nms-ui-switch.js
index b7cbc7c..0919534 100644
--- a/web/js/nms-ui-switch.js
+++ b/web/js/nms-ui-switch.js
@@ -126,15 +126,15 @@ class nmsModThing extends nmsBox {
var ret = {};
var changed = 0;
for (var idx in this.rows) {
- if (this.rows[idx].value != this.rows[idx].original) {
- ret[idx] = this.rows[idx].value;
+ if (this.rows[idx].value.toString() != this.rows[idx].original) {
+ ret[idx] = this.rows[idx].value.value;
changed++;
}
}
if (!changed) {
return undefined;
}
- ret[this.identifier] = this.rows[this.identifier].value;
+ ret[this.identifier] = this.rows[this.identifier].value.value;
return ret;
}
}
@@ -146,7 +146,7 @@ class nmsEditRow extends nmsBox {
console.assert(value instanceof nmsType)
this.name = text;
this._value = value;
- this.original = value.value;
+ this.original = value.toString();
var td1 = new nmsBox("td")
var name = new nmsString(text+" ");
name.html.title = value.description;
@@ -161,7 +161,7 @@ class nmsEditRow extends nmsBox {
this.changed(false)
var content = new nmsBox("td")
var input = new nmsBox("input")
- input.html.value = value.value;
+ input.html.value = value.toString();
input.html.className = "form-control";
input.html.type = "text";
input.row = this;
@@ -188,7 +188,7 @@ class nmsEditRow extends nmsBox {
this.add(content)
}
get value() {
- return this._value.value;
+ return this._value;
}
changed(val) {
if (val) {
@@ -224,12 +224,12 @@ class nmsEditRow extends nmsBox {
} else {
this.valid(true)
this._content.html.classList.remove("has-error");
- this._value.value = value;
+ this._value.fromString(value);
}
- if (this._input.html.value != this._value.value) {
- this._input.html.value = this._value.value
+ if (this._input.html.value != this._value.toString()) {
+ this._input.html.value = this._value.toString()
}
- if (this._value.value != this.original) {
+ if (this._value.toString() != this.original) {
this.changed(true)
this._content.html.classList.add("has-success");
} else {