diff options
author | Joachim Tingvold <joachim@tingvold.com> | 2015-04-01 03:44:19 +0200 |
---|---|---|
committer | root <root@einstein.tg15.gathering.org> | 2015-04-01 03:44:19 +0200 |
commit | ee87dca5e68e0f8521163b5603717742b248e6b1 (patch) | |
tree | 4bd0a403093e8b9c9eb3fe594bd010258ee7e407 | |
parent | 14e0453b2e74e7a93a092a2cfec46dabbcd2ab65 (diff) |
NMS-changes
-rwxr-xr-x | include/nms.pm | 2 | ||||
-rw-r--r-- | sql/nms.sql | 50 |
2 files changed, 51 insertions, 1 deletions
diff --git a/include/nms.pm b/include/nms.pm index 1ade743..2da31a0 100755 --- a/include/nms.pm +++ b/include/nms.pm @@ -65,7 +65,7 @@ sub switch_connect_ssh($) { -timeout => $nms::config::telnet_timeout, -dump_log => $dumplog, -input_log => $inputlog, - -prompt => '/.*\@e\d+-\d+[>#] /', + -prompt => '/.*\@[a-z0-9-]+[>#] /', -telnetmode => 0, -cmd_remove_mode => 1, -output_record_separator => "\r"); diff --git a/sql/nms.sql b/sql/nms.sql index 18291d1..737b602 100644 --- a/sql/nms.sql +++ b/sql/nms.sql @@ -145,6 +145,56 @@ ALTER FUNCTION public.get_current_datarate() OWNER TO nms; -- Name: get_datarate(); Type: FUNCTION; Schema: public; Owner: nms -- +CREATE TYPE operstatuses AS ( + switch integer, + ifdescr char(16), + operstatus integer, + last_poll_time timestamp with time zone +); +CREATE FUNCTION get_operstatus() RETURNS SETOF operstatuses + LANGUAGE plpgsql + AS $$ +DECLARE + num_entries INTEGER; + poll polls; + last_poll polls; + ret operstatuses; +BEGIN + num_entries := 0; + last_poll.switch = -1; + + FOR poll IN select * from polls where time >= now() - '15 minutes'::interval and time < now() order by switch,ifdescr,time LOOP + IF poll.switch <> last_poll.switch OR poll.ifdescr <> last_poll.ifdescr THEN + IF num_entries >= 1 THEN + ret.switch := last_poll.switch; + ret.ifdescr := last_poll.ifdescr; + ret.operstatus := last_poll.operstatus; + ret.last_poll_time := last_poll.time; + return next ret; + END IF; + num_entries := 1; + ELSE + num_entries := num_entries + 1; + END IF; + last_poll.switch := poll.switch; + last_poll.ifdescr := poll.ifdescr; + last_poll.time := poll.time; + last_poll.operstatus := poll.operstatus; + END LOOP; + -- pah, and once more, for the last switch/port... + IF num_entries >= 1 THEN + ret.switch := last_poll.switch; + ret.ifdescr := last_poll.ifdescr; + ret.operstatus := last_poll.operstatus; + ret.last_poll_time := last_poll.time; + return next ret; + END IF; + + RETURN; +END; +$$; + + CREATE FUNCTION get_datarate() RETURNS SETOF datarate LANGUAGE plpgsql AS $$ |