[Reconnoiter-devel] [reconnoiter commit] r314 - trunk/sql

denish at omniti.com denish at omniti.com
Mon Jun 30 15:32:15 EDT 2008


Author: denish
Date: 2008-06-30 15:32:15 -0400 (Mon, 30 Jun 2008)
New Revision: 314

Modified:
   trunk/sql/schema.sql
Log:
added node configuration  tables and trigger.

Modified: trunk/sql/schema.sql
===================================================================
--- trunk/sql/schema.sql	2008-06-30 17:38:33 UTC (rev 313)
+++ trunk/sql/schema.sql	2008-06-30 19:32:15 UTC (rev 314)
@@ -134,6 +134,23 @@
   active boolean default 'true',
   PRIMARY KEY (sid,metric_name,metric_type)
 );
+
+CREATE TABLE stratcon.current_node_config (
+  remote_address inet not null, 
+  node_type text not null, 
+  whence timestamptz not null, 
+  config xml not null,
+  PRIMARY KEY (remote_address,node_type)
+);
+
+CREATE TABLE stratcon.current_node_config_changelog (
+  remote_address inet not null, 
+  node_type text not null, 
+  whence timestamptz not null, 
+  config xml not null,
+  PRIMARY KEY (remote_address,node_type)
+);
+
 -- Schema Sequence 
 
 CREATE SEQUENCE stratcon.seq_sid
@@ -232,6 +249,45 @@
     LANGUAGE plpgsql;
 
 
+-- Trigger Function to log node config change
+
+CREATE   TRIGGER current_node_config_changelog
+    AFTER INSERT ON stratcon.current_node_config
+    FOR EACH ROW
+    EXECUTE PROCEDURE stratcon.current_node_config_changelog();
+
+
+CREATE OR REPLACE FUNCTION stratcon.current_node_config_changelog() RETURNS trigger
+    AS $$
+DECLARE
+    v_config xml;
+    
+BEGIN
+
+IF TG_OP = 'INSERT' THEN
+    SELECT config FROM  stratcon.current_node_config WHERE remote_address = NEW.remote_address AND node_type= NEW.node_type
+        AND whence = (SELECT max(whence) FROM stratcon.current_node_config_changelog
+                        WHERE  remote_address = NEW.remote_address AND node_type= NEW.node_type and  whence <> NEW.whence )
+    INTO v_config;
+
+    IF v_config IS DISTINCT FROM NEW.config THEN
+
+        INSERT INTO stratcon.current_node_config_changelog (remote_address,node_type,whence,config)
+            VALUES (NEW.remote_address,NEW.node_type,NEW.whence,NEW.config); 
+
+    END IF;
+
+ELSE
+        RAISE EXCEPTION 'Something wrong with stratcon.current_node_config_changelog';
+END IF;
+
+    RETURN NULL;
+
+END
+$$
+    LANGUAGE plpgsql;  
+
+
 -- Trigger Function to log Metrix Text Changes 
 
 CREATE TRIGGER loading_dock_metric_text_s_change_log



More information about the Reconnoiter-devel mailing list