diff --git a/sql/baseline/arnold.sql b/sql/baseline/arnold.sql index 0400b66e50..3f5addf1fc 100644 --- a/sql/baseline/arnold.sql +++ b/sql/baseline/arnold.sql @@ -22,6 +22,8 @@ orgid VARCHAR, determined CHAR(1), -- set to y if this is mac/port combo is blocked with the -d option. fromvlan INT, -- original vlan on port before change (only on vlanchange) tovlan INT, -- vlan on port after change (only on vlanchange) +textual_interface VARCHAR DEFAULT '', -- for storing textual representation of the interface when detaining + UNIQUE (mac,swportid) ); @@ -41,7 +43,9 @@ username VARCHAR NOT NULL CREATE TABLE quarantine_vlans ( quarantineid SERIAL PRIMARY KEY, vlan INT, -description VARCHAR +description VARCHAR, + +CONSTRAINT quarantine_vlan_unique UNIQUE (vlan) ); -- A block, of lack of better name, is a run where we do automatic blocking @@ -63,19 +67,3 @@ activeonvlans VARCHAR, -- a string with comma-separated vlan-numbers detainmenttype VARCHAR CHECK (detainmenttype='disable' OR detainmenttype='quarantine'), -- type of detainment to try quarantineid INT REFERENCES quarantine_vlans ON UPDATE CASCADE ON DELETE CASCADE ); - --- Create field for storing textual representation of the interface when detaining - -ALTER table arnold.identity ADD textual_interface VARCHAR DEFAULT ''; - - --- Fix uniqueness on quarantine vlans - -DELETE FROM quarantine_vlans WHERE quarantineid in ( - SELECT q2.quarantineid - FROM quarantine_vlans q1 - JOIN quarantine_vlans q2 - ON (q1.vlan = q2.vlan AND q1.quarantineid < q2.quarantineid) - ORDER BY q1.quarantineid); - -ALTER TABLE quarantine_vlans ADD CONSTRAINT quarantine_vlan_unique UNIQUE (vlan); diff --git a/sql/baseline/manage.sql b/sql/baseline/manage.sql index 3c28388e9a..c465c2133f 100644 --- a/sql/baseline/manage.sql +++ b/sql/baseline/manage.sql @@ -4,18 +4,18 @@ SQL Initialization script for NAV's manage database. Read the README file for more info. - + Run the command: psql manage -f manage.sql - + !! WARNING !! This SQL script is encoded as unicode (UTF-8), before you do make changes and commit, be 100% sure that your editor does not mess it up. - + Check 1 : These norwegian letters looks nice: ! æøåÆØÅ ! - Check 2 : This is the Euro currency sign: + Check 2 : This is the Euro currency sign: ! € ! ============================================= */ @@ -79,7 +79,7 @@ CREATE TABLE vlan ( usageid VARCHAR(30) REFERENCES usage, netident VARCHAR, description VARCHAR -); +); CREATE TABLE prefix ( prefixid SERIAL PRIMARY KEY, @@ -105,6 +105,9 @@ INSERT INTO cat values ('EDGE','Edge switch without vlans (layer 2)','t'); INSERT INTO cat values ('WLAN','Wireless equipment','t'); INSERT INTO cat values ('SRV','Server','f'); INSERT INTO cat values ('OTHER','Other equipment','f'); +INSERT INTO cat VALUES ('ENV', 'Environmental probes', true); +INSERT INTO cat VALUES ('POWER', 'Power distribution equipment', true); + CREATE TABLE device ( deviceid SERIAL PRIMARY KEY, @@ -139,7 +142,7 @@ CREATE TABLE netbox ( up CHAR(1) NOT NULL DEFAULT 'y' CHECK (up='y' OR up='n' OR up='s'), -- y=up, n=down, s=shadow snmp_version INT4 NOT NULL DEFAULT 2, upsince TIMESTAMP NOT NULL DEFAULT NOW(), - uptodate BOOLEAN NOT NULL DEFAULT false, + uptodate BOOLEAN NOT NULL DEFAULT false, discovered TIMESTAMP NULL DEFAULT NOW(), data hstore DEFAULT hstore('') NOT NULL, UNIQUE(ip) @@ -165,33 +168,32 @@ CREATE TABLE netbox_vtpvlan ( UNIQUE(netboxid, vtpvlan) ); -CREATE TABLE subcat ( - subcatid VARCHAR, +CREATE TABLE netboxgroup ( + netboxgroupid VARCHAR, descr VARCHAR NOT NULL, - catid VARCHAR(8) NOT NULL REFERENCES cat(catid), - PRIMARY KEY (subcatid) -); -INSERT INTO subcat (subcatid,descr,catid) VALUES ('AD','Description','SRV'); -INSERT INTO subcat (subcatid,descr,catid) VALUES ('ADC','Description','SRV'); -INSERT INTO subcat (subcatid,descr,catid) VALUES ('BACKUP','Description','SRV'); -INSERT INTO subcat (subcatid,descr,catid) VALUES ('DNS','Description','SRV'); -INSERT INTO subcat (subcatid,descr,catid) VALUES ('FS','Description','SRV'); -INSERT INTO subcat (subcatid,descr,catid) VALUES ('LDAP','Description','SRV'); -INSERT INTO subcat (subcatid,descr,catid) VALUES ('MAIL','Description','SRV'); -INSERT INTO subcat (subcatid,descr,catid) VALUES ('NOTES','Description','SRV'); -INSERT INTO subcat (subcatid,descr,catid) VALUES ('STORE','Description','SRV'); -INSERT INTO subcat (subcatid,descr,catid) VALUES ('TEST','Description','SRV'); -INSERT INTO subcat (subcatid,descr,catid) VALUES ('UNIX','Description','SRV'); -INSERT INTO subcat (subcatid,descr,catid) VALUES ('UNIX-STUD','Description','SRV'); -INSERT INTO subcat (subcatid,descr,catid) VALUES ('WEB','Description','SRV'); -INSERT INTO subcat (subcatid,descr,catid) VALUES ('WIN','Description','SRV'); -INSERT INTO subcat (subcatid,descr,catid) VALUES ('WIN-STUD','Description','SRV' + + PRIMARY KEY (netboxgroupid) ); +INSERT INTO netboxgroup (netboxgroupid,descr) VALUES ('AD','Description'); +INSERT INTO netboxgroup (netboxgroupid,descr) VALUES ('ADC','Description'); +INSERT INTO netboxgroup (netboxgroupid,descr) VALUES ('BACKUP','Description'); +INSERT INTO netboxgroup (netboxgroupid,descr) VALUES ('DNS','Description'); +INSERT INTO netboxgroup (netboxgroupid,descr) VALUES ('FS','Description'); +INSERT INTO netboxgroup (netboxgroupid,descr) VALUES ('LDAP','Description'); +INSERT INTO netboxgroup (netboxgroupid,descr) VALUES ('MAIL','Description'); +INSERT INTO netboxgroup (netboxgroupid,descr) VALUES ('NOTES','Description'); +INSERT INTO netboxgroup (netboxgroupid,descr) VALUES ('STORE','Description'); +INSERT INTO netboxgroup (netboxgroupid,descr) VALUES ('TEST','Description'); +INSERT INTO netboxgroup (netboxgroupid,descr) VALUES ('UNIX','Description'); +INSERT INTO netboxgroup (netboxgroupid,descr) VALUES ('UNIX-STUD','Description'); +INSERT INTO netboxgroup (netboxgroupid,descr) VALUES ('WEB','Description'); +INSERT INTO netboxgroup (netboxgroupid,descr) VALUES ('WIN','Description'); +INSERT INTO netboxgroup (netboxgroupid,descr) VALUES ('WIN-STUD','Description'); CREATE TABLE netboxcategory ( id SERIAL, netboxid INT4 NOT NULL REFERENCES netbox ON UPDATE CASCADE ON DELETE CASCADE, - category VARCHAR NOT NULL REFERENCES subcat ON UPDATE CASCADE ON DELETE CASCADE, + category VARCHAR NOT NULL REFERENCES netboxgroup ON UPDATE CASCADE ON DELETE CASCADE, PRIMARY KEY(netboxid, category) ); @@ -215,8 +217,8 @@ CREATE TABLE module ( descr VARCHAR, up CHAR(1) NOT NULL DEFAULT 'y' CHECK (up='y' OR up='n'), -- y=up, n=down downsince TIMESTAMP, - CONSTRAINT module_netboxid_key UNIQUE (netboxid, name), - UNIQUE(deviceid) + + CONSTRAINT module_netboxid_key UNIQUE (netboxid, name) ); CREATE TABLE mem ( @@ -250,40 +252,40 @@ CREATE TABLE interface ( ifalias VARCHAR, -- non IF-MIB values - baseport INT4, -- baseport number from BRIDGE-MIB, if any. + baseport INT4, -- baseport number from BRIDGE-MIB, if any. -- A non-null value should be a good indicator that this is a switch port. media VARCHAR, vlan INT4, trunk BOOLEAN, duplex CHAR(1) CHECK (duplex='f' OR duplex='h'), -- f=full, h=half - to_netboxid INT4, - to_interfaceid INT4, + to_netboxid INT4, + to_interfaceid INT4, gone_since TIMESTAMP, - + CONSTRAINT interface_pkey PRIMARY KEY (interfaceid), - CONSTRAINT interface_netboxid_fkey + CONSTRAINT interface_netboxid_fkey FOREIGN KEY (netboxid) REFERENCES netbox (netboxid) ON UPDATE CASCADE ON DELETE CASCADE, - CONSTRAINT interface_moduleid_fkey + CONSTRAINT interface_moduleid_fkey FOREIGN KEY (moduleid) REFERENCES module (moduleid) ON UPDATE CASCADE ON DELETE SET NULL, - CONSTRAINT interface_to_netboxid_fkey - FOREIGN KEY (to_netboxid) + CONSTRAINT interface_to_netboxid_fkey + FOREIGN KEY (to_netboxid) REFERENCES netbox (netboxid) ON UPDATE CASCADE ON DELETE SET NULL, - CONSTRAINT interface_to_interfaceid_fkey - FOREIGN KEY (to_interfaceid) + CONSTRAINT interface_to_interfaceid_fkey + FOREIGN KEY (to_interfaceid) REFERENCES interface (interfaceid) ON UPDATE CASCADE ON DELETE SET NULL, CONSTRAINT interface_netboxid_ifindex_unique UNIQUE (netboxid, ifindex) ); --- this should be populated with entries parsed from +-- this should be populated with entries parsed from -- http://www.iana.org/assignments/ianaiftype-mib CREATE TABLE iana_iftype ( iftype INT4 NOT NULL, @@ -308,7 +310,7 @@ CREATE TABLE rproto_attr ( protoname VARCHAR NOT NULL, -- bgp/ospf/isis metric INT4, - CONSTRAINT rproto_attr_pkey + CONSTRAINT rproto_attr_pkey PRIMARY KEY (id), CONSTRAINT rproto_attr_interfaceid_fkey FOREIGN KEY (interfaceid) @@ -331,14 +333,16 @@ CREATE TABLE swportallowedvlan ( CREATE TABLE swportblocked ( + swportblockedid SERIAL PRIMARY KEY, interfaceid INT4 NOT NULL REFERENCES interface ON UPDATE CASCADE ON DELETE CASCADE, vlan INT4 NOT NULL, - PRIMARY KEY(interfaceid, vlan) + + CONSTRAINT swportblocked_uniq UNIQUE (interfaceid, vlan) ); -- View to mimic old swport table CREATE VIEW swport AS ( - SELECT + SELECT interfaceid AS swportid, moduleid, ifindex, @@ -365,7 +369,7 @@ CREATE VIEW swport AS ( -- View to mimic old gwport table CREATE VIEW gwport AS ( - SELECT + SELECT i.interfaceid AS gwportid, moduleid, ifindex, @@ -480,7 +484,7 @@ CREATE TABLE arp ( -- Rule to automatically close open arp entries related to a given prefix CREATE OR REPLACE RULE close_arp_prefices AS ON DELETE TO prefix - DO UPDATE arp SET end_time=NOW(), prefixid=NULL + DO UPDATE arp SET end_time=NOW(), prefixid=NULL WHERE prefixid=OLD.prefixid AND end_time='infinity'; -- View for listing all IP addresses that appear to be alive at the moment. @@ -499,8 +503,7 @@ CREATE TABLE cam ( mac MACADDR NOT NULL, start_time TIMESTAMP NOT NULL, end_time TIMESTAMP NOT NULL DEFAULT 'infinity', - misscnt INT4 DEFAULT '0', - UNIQUE(netboxid,sysname,module,port,mac,start_time) + misscnt INT4 DEFAULT '0' ); @@ -532,17 +535,17 @@ CREATE VIEW prefix_max_ip_cnt AS -- This view gives the allowed vlan for a given hexstring i swportallowedvlan CREATE VIEW allowedvlan AS ( - SELECT - interfaceid, vlan AS allowedvlan - FROM - (SELECT interfaceid, decode(hexstring, 'hex') AS octetstring + SELECT + interfaceid, vlan AS allowedvlan + FROM + (SELECT interfaceid, decode(hexstring, 'hex') AS octetstring FROM swportallowedvlan) AS allowed_octets CROSS JOIN generate_series(0, 4095) AS vlan WHERE vlan < length(octetstring)*8 AND - (CASE - WHEN length(octetstring)>=128 + (CASE + WHEN length(octetstring)>=128 THEN get_bit(octetstring, (vlan/8)*8+7-(vlan%8)) ELSE get_bit(octetstring,(length(octetstring)*8-vlan+7>>3<<3)-8+(vlan%8)) END) = 1 @@ -576,6 +579,10 @@ INSERT INTO subsystem (name) VALUES ('getDeviceData'); INSERT INTO subsystem (name) VALUES ('devBrowse'); INSERT INTO subsystem (name) VALUES ('maintenance'); INSERT INTO subsystem (name) VALUES ('snmptrapd'); +INSERT INTO subsystem (name) VALUES ('powersupplywatch'); +INSERT INTO subsystem (name) VALUES ('ipdevpoll'); +INSERT INTO subsystem (name) VALUES ('macwatch'); + ------------------------------------------------------------------------------------------ @@ -588,9 +595,9 @@ CREATE TABLE eventtype ( eventtypedesc VARCHAR, stateful CHAR(1) NOT NULL CHECK (stateful='y' OR stateful='n') ); -INSERT INTO eventtype (eventtypeid,eventtypedesc,stateful) VALUES +INSERT INTO eventtype (eventtypeid,eventtypedesc,stateful) VALUES ('boxState','Tells us whether a network-unit is down or up.','y'); -INSERT INTO eventtype (eventtypeid,eventtypedesc,stateful) VALUES +INSERT INTO eventtype (eventtypeid,eventtypedesc,stateful) VALUES ('serviceState','Tells us whether a service on a server is up or down.','y'); INSERT INTO eventtype (eventtypeid,eventtypedesc,stateful) VALUES ('moduleState','Tells us whether a module in a device is working or not.','y'); @@ -614,6 +621,18 @@ INSERT INTO eventtype (eventtypeid,eventtypedesc,stateful) VALUES ('maintenanceState','Tells us if something is set on maintenance','y'); INSERT INTO eventtype (eventtypeid,eventtypedesc,stateful) VALUES ('apState','Tells us whether an access point has disassociated or associated from the controller','y'); +INSERT INTO eventtype (eventtypeid, eventtypedesc, stateful) VALUES + ('snmpAgentState', 'Tells us whether the SNMP agent on a device is down or up.', 'y'); +INSERT INTO eventtype (eventtypeid, eventtypedesc, stateful) VALUES + ('chassisState', 'The state of this chassis has changed', 'y'); +INSERT INTO eventtype (eventtypeid, eventtypedesc, stateful) VALUES + ('aggregateLinkState', 'The state of this aggregated link changed', 'y'); +INSERT INTO eventtype (eventtypeid, eventtypedesc, stateful) VALUES + ('psuState', 'Reports state changes in power supply units', 'y'); +INSERT INTO eventtype (eventtypeid, eventtypedesc, stateful) VALUES + ('fanState', 'Reports state changes in fan units', 'y'); + + CREATE TABLE eventq ( eventqid SERIAL PRIMARY KEY, @@ -621,7 +640,7 @@ CREATE TABLE eventq ( target VARCHAR(32) NOT NULL REFERENCES subsystem (name) ON UPDATE CASCADE ON DELETE CASCADE, deviceid INT4 REFERENCES device ON UPDATE CASCADE ON DELETE CASCADE, netboxid INT4 REFERENCES netbox ON UPDATE CASCADE ON DELETE CASCADE, - subid VARCHAR, + subid VARCHAR NOT NULL DEFAULT '', time TIMESTAMP NOT NULL DEFAULT NOW (), eventtypeid VARCHAR(32) NOT NULL REFERENCES eventtype ON UPDATE CASCADE ON DELETE CASCADE, state CHAR(1) NOT NULL DEFAULT 'x' CHECK (state='x' OR state='s' OR state='e'), -- x = stateless, s = start, e = end @@ -687,13 +706,13 @@ INSERT INTO alerttype (eventtypeid,alerttype,alerttypedesc) VALUES INSERT INTO alerttype (eventtypeid,alerttype,alerttypedesc) VALUES ('info','serialChanged','Serial number for the device has changed.'); INSERT INTO alerttype (eventtypeid,alerttype,alerttypedesc) VALUES - ('boxRestart','coldStart','Tells us that a network-unit has done a coldstart.'); + ('boxRestart','coldStart','The IP device has coldstarted'); INSERT INTO alerttype (eventtypeid,alerttype,alerttypedesc) VALUES - ('boxRestart','warmStart','Tells us that a network-unit has done a warmstart.'); + ('boxRestart','warmStart','The IP device has warmstarted'); INSERT INTO alerttype (eventtypeid,alerttype,alerttypedesc) VALUES - ('deviceState','deviceInIPOperation','Device is in operation as a box.'); + ('deviceState','deviceInIPOperation','The device is now in operation with an active IP address'); INSERT INTO alerttype (eventtypeid,alerttype,alerttypedesc) VALUES - ('deviceState','deviceInStack','Device is in operation as a module.'); + ('deviceState','deviceInStack','The device is now in operation as a chassis module'); INSERT INTO alerttype (eventtypeid,alerttype,alerttypedesc) VALUES ('deviceState','deviceRMA','RMA event for device.'); INSERT INTO alerttype (eventtypeid,alerttype,alerttypedesc) VALUES @@ -706,13 +725,37 @@ INSERT INTO alerttype (eventtypeid,alerttype,alerttypedesc) VALUES ('apState','apUp','AP associated with controller'); INSERT INTO alerttype (eventtypeid,alerttype,alerttypedesc) VALUES ('apState','apDown','AP disassociated from controller'); +INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES + ('snmpAgentState', 'snmpAgentDown', 'SNMP agent is down or unreachable due to misconfiguration.'); +INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES + ('snmpAgentState', 'snmpAgentUp', 'SNMP agent is up.'); +INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES + ('chassisState', 'chassisDown', 'This chassis is no longer visible in the stack'); +INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES + ('chassisState', 'chassisUp', 'This chassis is visible in the stack again'); +INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES + ('aggregateLinkState', 'linkDegraded', 'This aggregate link has been degraded'); +INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES + ('aggregateLinkState', 'linkRestored', 'This aggregate link has been restored'); +INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES + ('info','macWarning','Mac appeared on port'); +INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES + ('psuState', 'psuNotOK', 'A PSU has entered a non-OK state'); +INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES + ('psuState', 'psuOK', 'A PSU has returned to an OK state'); +INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES + ('fanState', 'fanNotOK', 'A fan unit has entered a non-OK state'); +INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES + ('fanState', 'fanOK', 'A fan unit has returned to an OK state'); + + CREATE TABLE alerthist ( alerthistid SERIAL PRIMARY KEY, source VARCHAR(32) NOT NULL REFERENCES subsystem (name) ON UPDATE CASCADE ON DELETE CASCADE, deviceid INT4 REFERENCES device ON UPDATE CASCADE ON DELETE CASCADE, netboxid INT4 REFERENCES netbox ON UPDATE CASCADE ON DELETE SET NULL, - subid VARCHAR, + subid VARCHAR NOT NULL DEFAULT '', start_time TIMESTAMP NOT NULL, end_time TIMESTAMP DEFAULT 'infinity', eventtypeid VARCHAR(32) NOT NULL REFERENCES eventtype ON UPDATE CASCADE ON DELETE CASCADE, @@ -724,7 +767,7 @@ CREATE TABLE alerthist ( -- Rule to automatically close module related alert states when modules are -- deleted. CREATE OR REPLACE RULE close_alerthist_modules AS ON DELETE TO module - DO UPDATE alerthist SET end_time=NOW() + DO UPDATE alerthist SET end_time=NOW() WHERE eventtypeid IN ('moduleState', 'linkState') AND end_time='infinity' AND deviceid=OLD.deviceid; @@ -756,7 +799,7 @@ CREATE TABLE alertq ( source VARCHAR(32) NOT NULL REFERENCES subsystem (name) ON UPDATE CASCADE ON DELETE CASCADE, deviceid INT4 REFERENCES device ON UPDATE CASCADE ON DELETE CASCADE, netboxid INT4 REFERENCES netbox ON UPDATE CASCADE ON DELETE CASCADE, - subid VARCHAR, + subid VARCHAR NOT NULL DEFAULT '', time TIMESTAMP NOT NULL, eventtypeid VARCHAR(32) REFERENCES eventtype ON UPDATE CASCADE ON DELETE CASCADE, alerttypeid INT4 REFERENCES alerttype ON UPDATE CASCADE ON DELETE CASCADE, @@ -928,10 +971,6 @@ CREATE TABLE schema_change_log ( date_applied TIMESTAMP NOT NULL DEFAULT NOW() ); -INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES - ('info','macWarning','Mac appeared on port'); - - CREATE OR REPLACE RULE netbox_status_close_arp AS ON UPDATE TO netbox WHERE NEW.up='n' @@ -965,17 +1004,6 @@ CREATE TABLE manage.powersupply_or_fan ( up CHAR(1) NOT NULL DEFAULT 'u' CHECK (up='y' OR up='n' or up='u' or up='w') ); -INSERT INTO eventtype (eventtypeid, eventtypedesc, stateful) VALUES - ('snmpAgentState', 'Tells us whether the SNMP agent on a device is down or up.', 'y'); - -INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES - ('snmpAgentState', 'snmpAgentDown', 'SNMP agent is down or unreachable due to misconfiguration.'); - -INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES - ('snmpAgentState', 'snmpAgentUp', 'SNMP agent is up.'); - -INSERT INTO subsystem (name) VALUES ('ipdevpoll'); - -- Ensure any associated service alerts are closed when a service is deleted CREATE RULE close_alerthist_services @@ -1015,7 +1043,8 @@ CREATE TABLE manage.unrecognized_neighbor ( remote_id VARCHAR NOT NULL, remote_name VARCHAR NOT NULL, source VARCHAR NOT NULL, - since TIMESTAMP NOT NULL DEFAULT NOW() + since TIMESTAMP NOT NULL DEFAULT NOW(), + ignored_since TIMESTAMP DEFAULT NULL ); COMMENT ON TABLE unrecognized_neighbor IS 'Unrecognized neighboring devices reported by support discovery protocols'; @@ -1030,7 +1059,7 @@ CREATE TABLE manage.ipdevpoll_job_log ( job_name VARCHAR NOT NULL, end_time TIMESTAMP NOT NULL, duration DOUBLE PRECISION, - success BOOLEAN NOT NULL, + success BOOLEAN, "interval" INTEGER, CONSTRAINT ipdevpoll_job_log_netbox_fkey FOREIGN KEY (netboxid) @@ -1061,72 +1090,10 @@ CREATE TRIGGER trig_close_snmpagentstates_on_community_clear FOR EACH ROW EXECUTE PROCEDURE close_snmpagentstates_on_community_clear(); --- also close any currently wrongfully open SNMP states -UPDATE alerthist -SET end_time=NOW() -FROM netbox -WHERE eventtypeid='snmpAgentState' - AND end_time >= 'infinity' - AND alerthist.netboxid = netbox.netboxid - AND COALESCE(netbox.ro, '') = ''; - -INSERT INTO subsystem VALUES ('powersupplywatch'); - --- create new event and alert types for fan and psu alerts - -INSERT INTO eventtype (eventtypeid, eventtypedesc, stateful) VALUES - ('psuState', 'Reports state changes in power supply units', 'y'); - -INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES - ('psuState', 'psuNotOK', 'A PSU has entered a non-OK state'); - -INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES - ('psuState', 'psuOK', 'A PSU has returned to an OK state'); - - -INSERT INTO eventtype (eventtypeid, eventtypedesc, stateful) VALUES - ('fanState', 'Reports state changes in fan units', 'y'); - -INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES - ('fanState', 'fanNotOK', 'A fan unit has entered a non-OK state'); - -INSERT INTO alerttype (eventtypeid, alerttype, alerttypedesc) VALUES - ('fanState', 'fanOK', 'A fan unit has returned to an OK state'); - --- rename logging jobs to ip2mac in ipdevpoll job log table -UPDATE ipdevpoll_job_log SET job_name = 'ip2mac' WHERE job_name = 'logging'; - - -- Notify the eventEngine immediately as new events are inserted in the queue CREATE OR REPLACE RULE eventq_notify AS ON INSERT TO eventq DO ALSO NOTIFY new_event; --- remove useless cam constraints/indexes to prevent index bloat --- On some installs, the index may already have been manually removed. "DROP --- CONSTRAINT IF EXISTS" wasn't introduced until PostgreSQL 9, --- so we make a conditional drop function to accomplish this without errors --- here: - -CREATE OR REPLACE FUNCTION manage.drop_constraint(tbl_schema VARCHAR, tbl_name VARCHAR, const_name VARCHAR) RETURNS void AS $$ -DECLARE - exec_string TEXT; -BEGIN - exec_string := 'ALTER TABLE '; - IF tbl_schema != NULL THEN - exec_string := exec_string || quote_ident(tbl_schema) || '.'; - END IF; - exec_string := exec_string || quote_ident(tb_name) - || ' DROP CONSTRAINT ' - || quote_ident(const_name); - EXECUTE exec_string; -EXCEPTION - WHEN OTHERS THEN - NULL; -END; -$$ LANGUAGE plpgsql; - -SELECT drop_constraint('manage', 'cam', 'cam_netboxid_key'); - -- Create table for netbios names @@ -1152,40 +1119,11 @@ CREATE OR REPLACE VIEW manage.prefix_active_ip_cnt AS -- Create a table for interface stacking information CREATE TABLE manage.interface_stack ( id SERIAL PRIMARY KEY, -- dummy primary key for Django - higher INTEGER REFERENCES interface(interfaceid), - lower INTEGER REFERENCES interface(interfaceid), + higher INTEGER REFERENCES interface(interfaceid) ON DELETE CASCADE ON UPDATE CASCADE, + lower INTEGER REFERENCES interface(interfaceid) ON DELETE CASCADE ON UPDATE CASCADE, UNIQUE (higher, lower) ); -ALTER TABLE subcat DROP catid; -ALTER TABLE subcat RENAME TO netboxgroup; -ALTER TABLE netboxgroup RENAME subcatid TO netboxgroupid; - - --- Fix cascading deletes in interface_stack foreign keys (LP#1246226) - -ALTER TABLE interface_stack DROP CONSTRAINT interface_stack_higher_fkey; -ALTER TABLE interface_stack ADD CONSTRAINT interface_stack_higher_fkey - FOREIGN KEY (higher) - REFERENCES interface(interfaceid) - ON DELETE CASCADE ON UPDATE CASCADE; - -ALTER TABLE interface_stack DROP CONSTRAINT interface_stack_lower_fkey; -ALTER TABLE interface_stack ADD CONSTRAINT interface_stack_lower_fkey - FOREIGN KEY (lower) - REFERENCES interface(interfaceid) - ON DELETE CASCADE ON UPDATE CASCADE; - - -INSERT INTO vendor ( - SELECT 'unknown' AS vendorid - WHERE NOT EXISTS ( - SELECT vendorid FROM vendor WHERE vendorid='unknown')); - --- Fix maintenance tasks that are open "until the end of time" (LP#1273706) -UPDATE maint_task -SET maint_end = 'infinity' -WHERE extract(year from maint_end) = 9999; CREATE OR REPLACE VIEW manage.netboxmac AS @@ -1225,47 +1163,6 @@ SELECT DISTINCT ON (mac) netboxid, mac FROM ( WHERE mac <> '00:00:00:00:00:00' -- exclude invalid MACs ORDER BY mac, netboxid; --- Clean up scale/precision problems of already known APC sensors (LP#1270095) - -UPDATE sensor -SET precision=1, data_scale=NULL -WHERE mib = 'PowerNet-MIB' - AND data_scale = 'deci'; - -UPDATE sensor -SET precision=2, data_scale=NULL -WHERE mib = 'PowerNet-MIB' - AND data_scale = 'centi'; - -INSERT INTO manage.cat (catid, descr, req_snmp) VALUES ('ENV', 'Environmental probes', true); -INSERT INTO manage.cat (catid, descr, req_snmp) VALUES ('POWER', 'Power distribution equipment', true); - --- clean up some alert- and event-type descriptions -UPDATE alerttype SET alerttypedesc = 'The IP device has coldstarted' -WHERE alerttype='coldStart'; - -UPDATE alerttype SET alerttypedesc = 'The IP device has warmstarted' -WHERE alerttype='warmStart'; - -UPDATE alerttype SET alerttypedesc = 'The device is now in operation with an active IP address' -WHERE alerttype='deviceInIPOperation'; - -UPDATE alerttype SET alerttypedesc = 'The device is now in operation as a chassis module' -WHERE alerttype='deviceInStack'; - -ALTER TABLE eventq ALTER COLUMN subid SET NOT NULL; -ALTER TABLE eventq ALTER COLUMN subid SET DEFAULT ''; - -ALTER TABLE alertq ALTER COLUMN subid SET NOT NULL; -ALTER TABLE alertq ALTER COLUMN subid SET DEFAULT ''; - -ALTER TABLE alerthist ALTER COLUMN subid SET NOT NULL; -ALTER TABLE alerthist ALTER COLUMN subid SET DEFAULT ''; - --- allow jobs to be logged with no success indicator, i.e. the job was --- checked but nothing ran. -ALTER TABLE ipdevpoll_job_log ALTER COLUMN success DROP NOT NULL; - CREATE OR REPLACE FUNCTION never_use_null_subid() RETURNS trigger AS $$ BEGIN @@ -1287,7 +1184,7 @@ CREATE TABLE netboxentity ( netboxentityid SERIAL NOT NULL, netboxid INTEGER NOT NULL, - index VARCHAR NOT NULL, + index INTEGER NOT NULL, source VARCHAR NOT NULL, descr VARCHAR, vendor_type VARCHAR, @@ -1307,6 +1204,7 @@ CREATE TABLE netboxentity ( mfg_date TIMESTAMP WITH TIME ZONE, uris VARCHAR, data hstore NOT NULL DEFAULT hstore(''), + gone_since TIMESTAMP, CONSTRAINT netboxentity_pkey PRIMARY KEY (netboxentityid), CONSTRAINT netboxentity_netboxid_fkey @@ -1326,29 +1224,6 @@ CREATE TABLE netboxentity ( ); -ALTER TABLE netboxentity - ADD COLUMN gone_since TIMESTAMP; - ---- --- Insert new event and alert types for stack state events ---- -INSERT INTO eventtype ( - SELECT 'chassisState', 'The state of this chassis has changed', 'y' - WHERE NOT EXISTS (SELECT * FROM eventtype WHERE eventtypeid = 'chassisState')); - ---- --- Insert new alerttypes for chassie state alerts ---- -INSERT INTO alerttype ( - SELECT nextval('alerttype_alerttypeid_seq'), 'chassisState', 'chassisDown', - 'This chassis is no longer visible in the stack' - WHERE NOT EXISTS (SELECT * FROM alerttype WHERE alerttype = 'chassisDown')); - -INSERT INTO alerttype ( - SELECT nextval('alerttype_alerttypeid_seq'), 'chassisState', 'chassisUp', - 'This chassis is visible in the stack again' - WHERE NOT EXISTS (SELECT * FROM alerttype WHERE alerttype = 'chassisUp')); - -- Modernize existing close_alerthist_modules rule CREATE OR REPLACE RULE close_alerthist_modules AS ON DELETE TO module @@ -1377,21 +1252,6 @@ CREATE OR REPLACE RULE close_alerthist_interface AS ON DELETE TO interface AND netboxid = OLD.netboxid AND subid = OLD.interfaceid::text; ---- --- Add field to unrecognized_neighbor indicating ignored state ---- -ALTER TABLE unrecognized_neighbor ADD ignored_since TIMESTAMP DEFAULT NULL; - ---- Remove unique constraints for devices in module table - -ALTER TABLE module DROP CONSTRAINT IF EXISTS module_deviceid_key; - --- Fix data type of netboxentity.index, which, for mysterious reasons, was --- defined as varchar in 4.3.0 -ALTER TABLE netboxentity - ALTER COLUMN index TYPE INTEGER - USING index::INT; - CREATE VIEW enterprise_number AS WITH enterprise AS ( @@ -1414,28 +1274,9 @@ CREATE TABLE manage.interface_aggregate ( UNIQUE (aggregator, interface) ); ---- --- Insert new event and alert types for degraded link events ---- -INSERT INTO eventtype ( - SELECT 'aggregateLinkState', 'The state of this aggregated link changed', 'y' - WHERE NOT EXISTS (SELECT * FROM eventtype WHERE eventtypeid = 'aggregateLinkState')); - ---- --- Insert new alerttypes for degradation and restoration of aggregated links ---- -INSERT INTO alerttype ( - SELECT nextval('alerttype_alerttypeid_seq'), 'aggregateLinkState', 'linkDegraded', - 'This aggregate link has been degraded' - WHERE NOT EXISTS (SELECT * FROM alerttype WHERE alerttype = 'linkDegraded')); - -INSERT INTO alerttype ( - SELECT nextval('alerttype_alerttypeid_seq'), 'aggregateLinkState', 'linkRestored', - 'This aggregate link has been restored' - WHERE NOT EXISTS (SELECT * FROM alerttype WHERE alerttype = 'linkRestored')); -- Create table for storing prefix tags -CREATE TABLE IF NOT EXISTS prefix_usage ( +CREATE TABLE prefix_usage ( prefix_usage_id SERIAL PRIMARY KEY, prefixid INTEGER REFERENCES prefix (prefixid) ON UPDATE CASCADE ON DELETE CASCADE, @@ -1444,15 +1285,5 @@ CREATE TABLE IF NOT EXISTS prefix_usage ( UNIQUE (prefixid, usageid) ); -ALTER TABLE swportblocked - DROP CONSTRAINT swportblocked_pkey; - -ALTER TABLE swportblocked - ADD CONSTRAINT swportblocked_uniq UNIQUE (interfaceid, vlan); - -ALTER TABLE swportblocked - ADD COLUMN swportblockedid SERIAL PRIMARY KEY; - - INSERT INTO schema_change_log (major, minor, point, script_name) VALUES (4, 6, 56, 'initial install'); diff --git a/sql/baseline/manage2.sql b/sql/baseline/manage2.sql index ad9f84514f..8000a2e4ad 100644 --- a/sql/baseline/manage2.sql +++ b/sql/baseline/manage2.sql @@ -23,8 +23,20 @@ CREATE TABLE manage.macwatch ( CONSTRAINT macwatch_unique_mac UNIQUE (mac) ); --- Create table for images +-- Registry of macwatch matches +-- (since watch rules may have wildcards and/or mac prefixes) +CREATE TABLE macwatch_match ( + id SERIAL PRIMARY KEY, + macwatch INT NOT NULL REFERENCES macwatch(id) ON DELETE CASCADE ON UPDATE CASCADE, + cam INT NOT NULL REFERENCES cam(camid) ON DELETE CASCADE ON UPDATE CASCADE, + posted TIMESTAMP DEFAULT NOW() +); + + +------------------------------------------------------------------------------ +-- Create table for room images +------------------------------------------------------------------------------ CREATE TABLE image ( imageid SERIAL PRIMARY KEY, roomid VARCHAR REFERENCES room(roomid) NOT NULL, @@ -36,22 +48,9 @@ CREATE TABLE image ( priority INT ); - -INSERT INTO subsystem ( - SELECT 'macwatch' AS name - WHERE NOT EXISTS ( - SELECT name FROM subsystem WHERE name='macwatch')); - --- Added because macwatch may use mac-address prefixes -CREATE TABLE macwatch_match( - id SERIAL PRIMARY KEY, - macwatch INT NOT NULL REFERENCES macwatch(id) ON DELETE CASCADE ON UPDATE CASCADE, - cam INT NOT NULL REFERENCES cam(camid) ON DELETE CASCADE ON UPDATE CASCADE, - posted TIMESTAMP DEFAULT NOW() -); - +------------------------------------------------------------------------------ -- Create basic token storage for api tokens - +------------------------------------------------------------------------------ CREATE TABLE apitoken ( id SERIAL PRIMARY KEY, token VARCHAR not null, @@ -61,10 +60,14 @@ CREATE TABLE apitoken ( created TIMESTAMP DEFAULT now(), last_used TIMESTAMP, comment TEXT, - revoked BOOLEAN default FALSE + revoked BOOLEAN default FALSE, + endpoints hstore ); +------------------------------------------------------------------------------ +-- Threshold rules and related functions +------------------------------------------------------------------------------ CREATE TABLE manage.thresholdrule ( id SERIAL PRIMARY KEY, target VARCHAR NOT NULL, @@ -82,22 +85,6 @@ CREATE TABLE manage.thresholdrule ( ); -CREATE TABLE manage.alerthist_ack ( - alert_id INTEGER PRIMARY KEY NOT NULL, - account_id INTEGER NOT NULL, - comment VARCHAR DEFAULT NULL, - date TIMESTAMPTZ DEFAULT NOW(), - - CONSTRAINT alerthistory_ack_alert FOREIGN KEY (alert_id) - REFERENCES manage.alerthist (alerthistid) - ON UPDATE CASCADE ON DELETE CASCADE, - - CONSTRAINT alerthistory_ack_user FOREIGN KEY (account_id) - REFERENCES profiles.account (id) - ON UPDATE CASCADE ON DELETE CASCADE - -); - -- automatically close thresholdState when threshold rules are removed CREATE OR REPLACE FUNCTION close_thresholdstate_on_thresholdrule_delete() RETURNS TRIGGER AS $$ @@ -120,4 +107,23 @@ CREATE TRIGGER trig_close_thresholdstate_on_thresholdrule_delete AFTER UPDATE OR DELETE ON manage.thresholdrule FOR EACH ROW EXECUTE PROCEDURE close_thresholdstate_on_thresholdrule_delete(); -ALTER TABLE apitoken ADD COLUMN endpoints hstore; + + +------------------------------------------------------------------------------ +-- Alerthist acknowledgements +------------------------------------------------------------------------------ +CREATE TABLE manage.alerthist_ack ( + alert_id INTEGER PRIMARY KEY NOT NULL, + account_id INTEGER NOT NULL, + comment VARCHAR DEFAULT NULL, + date TIMESTAMPTZ DEFAULT NOW(), + + CONSTRAINT alerthistory_ack_alert FOREIGN KEY (alert_id) + REFERENCES manage.alerthist (alerthistid) + ON UPDATE CASCADE ON DELETE CASCADE, + + CONSTRAINT alerthistory_ack_user FOREIGN KEY (account_id) + REFERENCES profiles.account (id) + ON UPDATE CASCADE ON DELETE CASCADE + +); diff --git a/sql/baseline/navprofiles.sql b/sql/baseline/navprofiles.sql index 7986561910..bd9a01482a 100644 --- a/sql/baseline/navprofiles.sql +++ b/sql/baseline/navprofiles.sql @@ -57,6 +57,7 @@ CREATE TABLE Account ( name varchar DEFAULT 'Noname', password varchar, ext_sync varchar, + preferences manage.hstore DEFAULT manage.hstore(''), CONSTRAINT account_pkey PRIMARY KEY(id), CONSTRAINT account_login_key UNIQUE(login) @@ -176,11 +177,11 @@ CREATE TABLE alertaddress ( FOREIGN KEY(accountid) REFERENCES Account(id) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT alertaddress_type_fkey + CONSTRAINT alertaddress_type_fkey FOREIGN KEY(type) REFERENCES alertsender(id) ON DELETE CASCADE ON UPDATE CASCADE - + ); ALTER SEQUENCE alertaddress_id_seq OWNED BY alertaddress.id; @@ -193,7 +194,7 @@ A table for alertprofile. Only one profile can be active simultanously. It is po name The name of the profile daily_dispatch_time Related to queueing. When daily queueing is selected, this attrubute specify when on a day enqueued alerts will be sent. -weekly_dispatch_day Related to queueing. When weekly queueing is selected, this attribute specify which +weekly_dispatch_day Related to queueing. When weekly queueing is selected, this attribute specify which weekday enqueued alerts will be sent on. 0 is monday, 6 is sunday. weekly_dispatch_time Related to queueing. When weekly queueing is selected, this attribute specify which time on the day enqueued alerts will be sent. @@ -249,7 +250,7 @@ CREATE TABLE alertpreference ( A table specifying a time period. This could be though of as an element in a timetable. A time period is related to a set of relation between equipmentgroups and alertaddresses. -start_time this attribute speficies the start time of this time period. The time period end time is +start_time this attribute speficies the start time of this time period. The time period end time is implicit given by the start time by the next time period. valid_during Speficies wether this time period is for weekdays or weekend or both. @@ -275,7 +276,7 @@ ALTER SEQUENCE timeperiod_id_seq OWNED BY timeperiod.id; /* -- 9 FILTERGROUP -Equipment group. An equipment is a composite of equipment filters. Equipment group is specified by a +Equipment group. An equipment is a composite of equipment filters. Equipment group is specified by a ennumerated (by priority) list of equipment filters. An equipment group could either be owned by an user, or shared among administrators. name The name of the equipment group @@ -343,8 +344,8 @@ ALTER SEQUENCE alertsubscription_id_seq OWNED BY alertsubscription.id; Permissions. -This table contatins a relation from a user group to an equipment group. It gives all members of the -actual user group permission to set up notofication for alerts matching this filter. The relation +This table contatins a relation from a user group to an equipment group. It gives all members of the +actual user group permission to set up notofication for alerts matching this filter. The relation usergroup <-> equipment group is many to many. */ CREATE SEQUENCE filtergroup_group_permission_id_seq; @@ -400,7 +401,7 @@ means that each row has a priority. include. If true the related filter is included in the group. positive. If this is false, the filter is inverted, which implies that true is false, and false is true. -priority. The list will be traversed in ascending priority order. Which means that the higher +priority. The list will be traversed in ascending priority order. Which means that the higher number, the higher priority. */ CREATE SEQUENCE filtergroupcontent_id_seq; @@ -449,7 +450,7 @@ CREATE TABLE MatchField ( value_id varchar, value_name varchar, value_sort varchar, - list_limit integer DEFAULT 300, + list_limit integer DEFAULT 1000, data_type integer NOT NULL DEFAULT 0, show_list boolean, @@ -800,42 +801,51 @@ INSERT INTO AccountGroupPrivilege (accountgroupid, privilegeid, target) VALUES ( INSERT INTO AccountGroupPrivilege (accountgroupid, privilegeid, target) VALUES (2, 2, E'^/maintenance/(calendar|active|historic|planned|view)\\b'); INSERT INTO AccountGroupPrivilege (accountgroupid, privilegeid, target) VALUES (2, 2, E'^/geomap$'); INSERT INTO AccountGroupPrivilege (accountgroupid, privilegeid, target) VALUES (2, 2, E'^/geomap/open'); +-- Grant web access to unauthorized ajax requests +INSERT INTO AccountGroupPrivilege (accountgroupid, privilegeid, target) VALUES (2, 2, '^/ajax/open/?'); +-- Grant web access to osm map redirects +INSERT INTO AccountGroupPrivilege (accountgroupid, privilegeid, target) VALUES (2, 2, '^/search/osm_map_redirect/?'); +-- Give everyone access to navlets +INSERT INTO AccountGroupPrivilege (accountgroupid, privilegeid, target) VALUES (2, 2, '^/navlets/.*'); + -- Define minimum privileges for authenticated users -INSERT INTO AccountGroupPrivilege (accountgroupid, privilegeid, target) VALUES (3, 2, '^/(report|status|alertprofiles|machinetracker|browse|preferences|cricket|stats|ipinfo|l2trace|logger|ipdevinfo|geomap)/?'); +INSERT INTO AccountGroupPrivilege (accountgroupid, privilegeid, target) VALUES (3, 2, '^/(report|status|alertprofiles|machinetracker|browse|preferences|cricket|stats|ipinfo|l2trace|logger|ipdevinfo|geomap|info|netmap|graphite|search|index/dashboard)/?'); + -- Give alert_by privilege to SMS group -INSERT INTO AccountGroupPrivilege (accountgroupid, privilegeid, target) +INSERT INTO AccountGroupPrivilege (accountgroupid, privilegeid, target) VALUES ((SELECT id FROM AccountGroup WHERE name='SMS'), 3, 'sms'); -- Alert senders INSERT INTO alertsender VALUES (1, 'Email', 'email'); INSERT INTO alertsender VALUES (2, 'SMS', 'sms'); -INSERT INTO alertsender VALUES (3, 'Jabber', 'jabber'); +INSERT INTO alertsender VALUES (3, 'Jabber', 'jabber'); +INSERT INTO alertsender VALUES (4, 'Slack', 'slack'); -- Matchfields -/* +/* Matchfield.Datatype string: 0 integer: 1 ip adr: 2 */ -INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES -(10, 0, 'Event type', 'eventtype.eventtypeid', 'eventtype.eventtypedesc', 'eventtype.eventtypeid', true, +INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES +(10, 0, 'Event type', 'eventtype.eventtypeid', 'eventtype.eventtypedesc', 'eventtype.eventtypeid', true, 'Event type: An event type describes a category of alarms. (Please note that alarm type is a more refined attribute. There are a set of alarm types within an event type.)'); INSERT INTO Operator (operator_id, match_field_id) VALUES (0, 10); INSERT INTO Operator (operator_id, match_field_id) VALUES (11, 10); -INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES -(11, 0, 'Alert type', 'alerttype.alerttype', 'alerttype.alerttypedesc', 'alerttype.alerttypeid', true, +INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES +(11, 0, 'Alert type', 'alerttype.alerttype', 'alerttype.alerttypedesc', 'alerttype.alerttype', true, 'Alert type: An alert type describes the various values an event type may take.'); INSERT INTO Operator (operator_id, match_field_id) VALUES (0, 11); INSERT INTO Operator (operator_id, match_field_id) VALUES (11, 11); -INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description, value_help) VALUES +INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description, value_help) VALUES (12, 1, 'Severity', 'alertq.severity', null, null, false, 'Severity: Limit your alarms based on severity.', 'Range: Severities are in the range 0-100, where 100 is most severe.'); @@ -847,19 +857,19 @@ INSERT INTO Operator (operator_id, match_field_id) VALUES (4, 12); INSERT INTO Operator (operator_id, match_field_id) VALUES (5, 12); -INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES +INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES (13, 0, 'Category', 'cat.catid', 'cat.descr', 'cat.catid', true, 'Category: All equipment is categorized in 7 main categories.'); INSERT INTO Operator (operator_id, match_field_id) VALUES (0, 13); INSERT INTO Operator (operator_id, match_field_id) VALUES (11, 13); -INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES -(14, 0, 'Sub category', 'subcat.subcatid', 'subcat.descr', 'subcat.descr', true, -'Sub category: Within a catogory user-defined subcategories may exist.'); +INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES +(14, 0, 'Group', 'netboxgroup.netboxgroupid', 'netboxgroup.descr', 'netboxgroup.descr', true, +'Group: netboxes may belong to a group that is independent of type and category'); INSERT INTO Operator (operator_id, match_field_id) VALUES (0, 14); INSERT INTO Operator (operator_id, match_field_id) VALUES (11, 14); -INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description, value_help) VALUES +INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description, value_help) VALUES (15, 0, 'Sysname', 'netbox.sysname', null, null, false, 'Sysname: Limit your alarms based on sysname.', E'Sysname examples:
@@ -875,7 +885,7 @@ INSERT INTO Operator (operator_id, match_field_id) VALUES (8, 15); INSERT INTO Operator (operator_id, match_field_id) VALUES (9, 15); -INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description, value_help) VALUES +INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description, value_help) VALUES (16, 2, 'IP address', 'netbox.ip', null, null, false, 'Limit your alarms based on an IP address/range (prefix)', 'examples:
@@ -886,42 +896,42 @@ INSERT INTO Operator (operator_id, match_field_id) VALUES (0, 16); INSERT INTO Operator (operator_id, match_field_id) VALUES (11, 16); -INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES +INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES (17, 0, 'Room', 'room.roomid', 'room.descr', 'room.roomid', true, 'Room: Limit your alarms based on room.'); INSERT INTO Operator (operator_id, match_field_id) VALUES (0, 17); INSERT INTO Operator (operator_id, match_field_id) VALUES (11, 17); -INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES -(18, 0, 'Location', 'location.locationid', 'location.descr', 'location.descr', true, +INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES +(18, 0, 'Location', 'location.locationid', 'location.descr', 'location.descr', true, 'Location: Limit your alarms based on location (a location contains a set of rooms) '); INSERT INTO Operator (operator_id, match_field_id) VALUES (0, 18); INSERT INTO Operator (operator_id, match_field_id) VALUES (11, 18); -INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES +INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES (19, 0, 'Organization', 'org.orgid', 'org.descr', 'org.descr', true, 'Organization: Limit your alarms based on the organization ownership of the alarm in question.'); INSERT INTO Operator (operator_id, match_field_id) VALUES (0, 19); INSERT INTO Operator (operator_id, match_field_id) VALUES (11, 19); -INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES +INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES (20, 0, 'Usage', 'usage.usageid', 'usage.descr', 'usage.descr', true, 'Usage: Different network prefixes are mapped to usage areas.'); INSERT INTO Operator (operator_id, match_field_id) VALUES (0, 20); INSERT INTO Operator (operator_id, match_field_id) VALUES (11, 20); -INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES +INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES (21, 0, 'Type', 'type.typename', 'type.descr', 'type.descr', true, 'Type: Limit your alarms equipment type'); INSERT INTO Operator (operator_id, match_field_id) VALUES (0, 21); INSERT INTO Operator (operator_id, match_field_id) VALUES (11, 21); -INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES +INSERT INTO MatchField (id, data_type, name, value_id, value_name, value_sort, show_list, description) VALUES (22, 0, 'Equipment vendor', 'vendor.vendorid', 'vendor.vendorid', 'vendor.vendorid', true, 'Equipment vendor: Limit alert by the vendor of the netbox.'); INSERT INTO Operator (operator_id, match_field_id) VALUES (0, 22); @@ -1048,16 +1058,25 @@ INSERT INTO statuspreference (id, name, position, type, accountid, states) VALUE INSERT INTO statuspreference (id, name, position, type, accountid, states) VALUES (3, 'IP devices on maintenance', 3, 'netbox_maintenance', 0, 'y,n,s'); INSERT INTO statuspreference (id, name, position, type, accountid, states) VALUES (4, 'Modules down/in shadow', 4, 'module', 0, 'n,s'); INSERT INTO statuspreference (id, name, position, type, accountid, states) VALUES (5, 'Services down', 5, 'service', 0, 'n,s'); +INSERT INTO statuspreference (id, name, position, type, accountid) VALUES (6, 'Thresholds exceeded', 6, 'threshold', 0); +INSERT INTO statuspreference (id, name, position, type, accountid) VALUES (7, 'SNMP agents down', 7, 'snmpagent', 0); +INSERT INTO statuspreference (id, name, position, type, accountid) VALUES (8, 'Links down', 8, 'linkstate', 0); + -- netmap_view CREATE TABLE profiles.netmap_view ( viewid SERIAL, owner INT4 NOT NULL REFERENCES account ON UPDATE CASCADE ON DELETE CASCADE, title VARCHAR NOT NULL, - link_types VARCHAR NOT NULL, zoom VARCHAR NOT NULL, is_public BOOLEAN NOT NULL DEFAULT FALSE, last_modified TIMESTAMP NOT NULL DEFAULT NOW(), + topology INT4 NOT NULL, + display_elinks BOOLEAN NOT NULL DEFAULT false, + display_orphans BOOLEAN NOT NULL DEFAULT false, + description TEXT DEFAULT null, + location_room_filter varchar NOT NULL DEFAULT '', + PRIMARY KEY (viewid) ); COMMENT ON TABLE netmap_view IS 'Stored views with settings for NetMap'; @@ -1078,13 +1097,6 @@ CREATE TABLE profiles.netmap_view_nodeposition ( PRIMARY KEY (viewid, netboxid) ); -TRUNCATE TABLE netmap_view CASCADE; -ALTER TABLE netmap_view ADD COLUMN topology INT4 NOT NULL; -ALTER TABLE netmap_view DROP COLUMN link_types; -ALTER TABLE netmap_view ADD COLUMN display_elinks BOOLEAN NOT NULL DEFAULT false; -ALTER TABLE netmap_view ADD COLUMN display_orphans BOOLEAN NOT NULL DEFAULT false; -ALTER TABLE netmap_view ADD COLUMN description TEXT DEFAULT null; - -- netmap_view_defaultview CREATE TABLE profiles.netmap_view_defaultview ( id SERIAL, @@ -1097,9 +1109,11 @@ COMMENT ON TABLE netmap_view_defaultview IS 'Stores default views for users in N CREATE TABLE profiles.accounttool( account_tool_id SERIAL PRIMARY KEY, toolname VARCHAR, - accountid INTEGER NOT NULL REFERENCES account(id) ON UPDATE CASCADE ON DELETE CASCADE, + accountid INTEGER NOT NULL, display BOOLEAN DEFAULT TRUE, - priority INTEGER DEFAULT 0 + priority INTEGER DEFAULT 0, + + FOREIGN KEY (accountid) REFERENCES account(id) ON DELETE CASCADE ON UPDATE CASCADE ); -- Django database-backed sessions are now being used by NAV. @@ -1109,103 +1123,31 @@ CREATE TABLE profiles.django_session ( "expire_date" timestamp with time zone NOT NULL ); --- Map topology id to match OSI layer number -UPDATE profiles.netmap_view SET topology = 3 where topology = 2; -UPDATE profiles.netmap_view SET topology = 2 where topology = 1; +--- Create table for storing multiple dashboards +CREATE TABLE profiles.account_dashboard ( + id SERIAL PRIMARY KEY, + name VARCHAR DEFAULT 'My dashboard', + is_default BOOLEAN DEFAULT FALSE, + num_columns INT, + account_id INT REFERENCES account(id) ON UPDATE CASCADE ON DELETE CASCADE +); -- Create table for storing navlet information for a user CREATE TABLE IF NOT EXISTS profiles.account_navlet ( id SERIAL PRIMARY KEY, + dashboard_id INT REFERENCES account_dashboard(id) ON UPDATE CASCADE ON DELETE CASCADE, navlet VARCHAR NOT NULL, - account INT REFERENCES profiles.account(id), + account INT, col INT, displayorder INT NOT NULL, - preferences VARCHAR -); - --- Grant web access to unauthorized ajax requests -INSERT INTO AccountGroupPrivilege (accountgroupid, privilegeid, target) - SELECT 2, 2, '^/ajax/open/?' WHERE NOT EXISTS ( - SELECT * FROM AccountGroupPrivilege WHERE accountgroupid=2 AND privilegeid=2 AND target='^/ajax/open/?' - ) -; - --- Grant web access to osm map redirects -INSERT INTO AccountGroupPrivilege (accountgroupid, privilegeid, target) - SELECT 2, 2, '^/info/osm_map_redirect/?' WHERE NOT EXISTS ( - SELECT * FROM AccountGroupPrivilege WHERE accountgroupid=2 AND privilegeid=2 AND target = '^/info/osm_map_redirect/?' - ) -; - --- Grant web access to /info for authenticated users -UPDATE AccountGroupPrivilege SET - target = '^/(report|status|alertprofiles|machinetracker|browse|preferences|cricket|stats|ipinfo|l2trace|logger|ipdevinfo|geomap|info|netmap)/?' - WHERE target = '^/(report|status|alertprofiles|machinetracker|browse|preferences|cricket|stats|ipinfo|l2trace|logger|ipdevinfo|geomap)/?' -; - ---- --- Give everyone access to navlets ---- -INSERT INTO AccountGroupPrivilege (accountgroupid, privilegeid, target) - SELECT 2, 2, '^/navlets/.*' WHERE NOT EXISTS ( - SELECT * FROM AccountGroupPrivilege WHERE accountgroupid = 2 AND privilegeid = 2 AND target = '^/navlets/.*' - ); - - ---- --- Insert default navlets for every existing user ---- -CREATE OR REPLACE FUNCTION insert_default_navlets_for_existing_users() RETURNS void AS $$ -DECLARE - account RECORD; -BEGIN - FOR account IN SELECT * FROM account LOOP - RAISE NOTICE 'Adding default navlets for %s', quote_ident(account.login); - INSERT INTO account_navlet (navlet, account, displayorder, col) VALUES - ('nav.web.navlets.welcome.WelcomeNavlet', account.id, 0, 1), - ('nav.web.navlets.linklist.LinkListNavlet', account.id, 0, 2), - ('nav.web.navlets.messages.MessagesNavlet', account.id, 1, 2); - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT insert_default_navlets_for_existing_users(); - - --- Fix cascading deletes in accounttool foreign keys (LP#1293621) + preferences VARCHAR, -ALTER TABLE accounttool DROP CONSTRAINT accounttool_accountid_fkey; -ALTER TABLE accounttool ADD CONSTRAINT accounttool_accountid_fkey - FOREIGN KEY (accountid) - REFERENCES account(id) - ON DELETE CASCADE ON UPDATE CASCADE; - --- Add new blog navlet to all users. Exclude those that have already activated it. -DO $$DECLARE account_record RECORD; -BEGIN - FOR account_record IN SELECT * FROM account WHERE id NOT IN (SELECT account FROM account_navlet WHERE navlet = 'nav.web.navlets.navblog.NavBlogNavlet') LOOP - INSERT INTO account_navlet (navlet, account, col, displayorder, preferences) VALUES - ('nav.web.navlets.navblog.NavBlogNavlet', account_record.id, 2, 0, '(dp0 -S''refresh_interval'' -p1 -I600000 -s.'); - END LOOP; -END$$; - -UPDATE accountgroupprivilege SET target = '^/search/osm_map_redirect/?' WHERE target = '^/info/osm_map_redirect/?'; - -ALTER TABLE account_navlet DROP CONSTRAINT account_navlet_account_fkey; -ALTER TABLE account_navlet ADD CONSTRAINT account_navlet_account_fkey - FOREIGN KEY (account) - REFERENCES account(id) - ON DELETE CASCADE ON UPDATE CASCADE; + CONSTRAINT account_navlet_account_fkey + FOREIGN KEY (account) REFERENCES account(id) + ON DELETE CASCADE ON UPDATE CASCADE +); ---- --- Delete all widgets from all users ---- -DELETE FROM account_navlet; --- -- Insert default widgets for every existing user @@ -1216,12 +1158,12 @@ DECLARE BEGIN FOR account IN SELECT * FROM account LOOP RAISE NOTICE 'Adding default navlets for %s', quote_ident(account.login); - INSERT INTO account_navlet (navlet, account, displayorder, col) VALUES - ('nav.web.navlets.gettingstarted.GettingStartedWidget', account.id, 0, 1), - ('nav.web.navlets.status.StatusNavlet', account.id, 1, 1), - ('nav.web.navlets.messages.MessagesNavlet', account.id, 2, 1), - ('nav.web.navlets.navblog.NavBlogNavlet', account.id, 0, 2), - ('nav.web.navlets.linklist.LinkListNavlet', account.id, 1, 2); + INSERT INTO account_navlet (navlet, account, displayorder, col, preferences) VALUES + ('nav.web.navlets.gettingstarted.GettingStartedWidget', account.id, 0, 1, NULL), + ('nav.web.navlets.status2.Status2Widget', account.id, 1, 1, '{"status_filter": "event_type=boxState&stateless_threshold=24", "refresh_interval": 60000}'), + ('nav.web.navlets.messages.MessagesNavlet', account.id, 2, 1, NULL), + ('nav.web.navlets.navblog.NavBlogNavlet', account.id, 0, 2, NULL), + ('nav.web.navlets.linklist.LinkListNavlet', account.id, 1, 2, NULL); END LOOP; END; $$ LANGUAGE plpgsql; @@ -1234,69 +1176,6 @@ SELECT insert_default_navlets_for_existing_users(); DELETE FROM account_navlet WHERE account=0 AND navlet='nav.web.navlets.gettingstarted.GettingStartedWidget'; ---- --- Give authenticated users access to Graphite graphs and stuffz ---- -INSERT INTO AccountGroupPrivilege (accountgroupid, privilegeid, target) - SELECT 3, 2, '^/graphite/?' WHERE NOT EXISTS ( - SELECT * FROM AccountGroupPrivilege WHERE accountgroupid = 3 AND privilegeid = 2 AND target = '^/graphite/?' - ); - - ---- --- Give authenticated users access to search ---- -INSERT INTO AccountGroupPrivilege (accountgroupid, privilegeid, target) - SELECT 3, 2, '^/search/?' WHERE NOT EXISTS ( - SELECT * FROM AccountGroupPrivilege WHERE accountgroupid = 3 AND privilegeid = 2 AND target = '^/search/?' - ); - -ALTER TABLE netmap_view ADD COLUMN location_room_filter varchar NOT NULL DEFAULT ''; - ---- --- Replace old status widget with new one. ---- -UPDATE account_navlet - SET navlet='nav.web.navlets.status2.Status2Widget', - preferences = '{"status_filter": "event_type=boxState&stateless_threshold=24", "refresh_interval": 60000}' - WHERE navlet='nav.web.navlets.status.StatusNavlet'; - -INSERT INTO alertsender (id, name, handler) VALUES (4, 'Slack', 'slack'); - -ALTER TABLE account ADD COLUMN preferences manage.hstore DEFAULT manage.hstore(''); - --- Save all properties from accountproperty as preferences in account table. -DO $$DECLARE accountproperty RECORD; -BEGIN - FOR accountproperty IN SELECT * FROM accountproperty LOOP - UPDATE account - SET preferences = preferences || manage.hstore(accountproperty.property, accountproperty.value) - WHERE account.id = accountproperty.accountid; - END LOOP; -END$$; - --- Set refresh interval on existing message widgets -UPDATE account_navlet -SET preferences = '{"refresh_interval": 60000}' -WHERE navlet = 'nav.web.navlets.messages.MessagesNavlet'; - ---- Create table for storing multiple dashboards -CREATE TABLE profiles.account_dashboard ( - id SERIAL PRIMARY KEY, - name VARCHAR DEFAULT 'My dashboard', - is_default BOOLEAN DEFAULT FALSE, - num_columns INT, - account_id INT REFERENCES account(id) ON UPDATE CASCADE ON DELETE CASCADE -); - - ---- Widgets should now be a part of a dashboard -ALTER TABLE account_navlet - ADD dashboard_id INT - REFERENCES account_dashboard(id) - ON UPDATE CASCADE ON DELETE CASCADE; - - --- Create a dashboard for each user and move all widgets there DO $$DECLARE thisaccount RECORD; BEGIN @@ -1313,6 +1192,11 @@ BEGIN END LOOP; END$$; +-- +-- Function and trigger to ensure the default account's dashboard setup is +-- copied to every new account that is created +-- + -- Create a new dashboard and copy all the widgets from the default user to -- the dashboard CREATE OR REPLACE FUNCTION create_new_dashboard() RETURNS trigger AS $$ @@ -1335,32 +1219,7 @@ CREATE TRIGGER add_default_dashboard_on_account_create AFTER INSERT ON account FOR EACH ROW EXECUTE PROCEDURE create_new_dashboard(); ---- --- Give authenticated users access to dashboard urls ---- -INSERT INTO AccountGroupPrivilege (accountgroupid, privilegeid, target) - SELECT 3, 2, '^/index/dashboard/?' WHERE NOT EXISTS ( - SELECT * FROM AccountGroupPrivilege WHERE accountgroupid = 3 AND privilegeid = 2 AND target = '^/index/dashboard/?' - ); - ---- --- Sort Alert Types when modifying Alert Profiles ---- -UPDATE MatchField SET value_sort='alerttype.alerttype' WHERE id=11 AND value_sort='alerttype.alerttypeid'; - -INSERT INTO statuspreference (id, name, position, type, accountid) VALUES (6, 'Thresholds exceeded', 6, 'threshold', 0); -INSERT INTO statuspreference (id, name, position, type, accountid) VALUES (7, 'SNMP agents down', 7, 'snmpagent', 0); -INSERT INTO statuspreference (id, name, position, type, accountid) VALUES (8, 'Links down', 8, 'linkstate', 0); - -UPDATE matchfield SET list_limit=1000 WHERE list_limit < 1000; -UPDATE matchfield SET - name='Group', - value_id='netboxgroup.netboxgroupid', - value_name='netboxgroup.descr', - value_sort='netboxgroup.descr', - description='Group: netboxes may belong to a group that is independent of type and category' - WHERE id=14; /* ------------------------------------------------------ EOF diff --git a/sql/baseline/types.sql b/sql/baseline/types.sql index c1dd73eb9c..471c656b2e 100644 --- a/sql/baseline/types.sql +++ b/sql/baseline/types.sql @@ -7,6 +7,7 @@ -- First, vendors +INSERT INTO vendor (vendorid) VALUES ('unknown'); INSERT INTO vendor (vendorid) VALUES ('alcatel'); INSERT INTO vendor (vendorid) VALUES ('allied'); INSERT INTO vendor (vendorid) VALUES ('avaya'); diff --git a/sql/changes/sc.04.07.0110.sql b/sql/changes/sc.04.07.0110.sql index 374c4ba20f..03a415761c 100644 --- a/sql/changes/sc.04.07.0110.sql +++ b/sql/changes/sc.04.07.0110.sql @@ -1,3 +1 @@ -BEGIN; INSERT INTO subsystem (name) VALUES ('portadmin'); -COMMIT; diff --git a/sql/changes/sc.04.08.0001.sql b/sql/changes/sc.04.08.0001.sql index 0c64dbb862..089202fadc 100644 --- a/sql/changes/sc.04.08.0001.sql +++ b/sql/changes/sc.04.08.0001.sql @@ -6,9 +6,9 @@ DROP FUNCTION IF EXISTS close_thresholdstate_on_threshold_delete(); -- Since bootstrapping from a new baseline already puts it in the correct -- schema, and moving it to the schema it already is in raises an error, we -- move it around a bit first :-D -ALTER FUNCTION create_new_dashboard() SET SCHEMA public; -ALTER FUNCTION public.create_new_dashboard() SET SCHEMA profiles; +ALTER FUNCTION create_new_dashboard() SET SCHEMA arnold; +ALTER FUNCTION arnold.create_new_dashboard() SET SCHEMA profiles; -ALTER FUNCTION insert_default_navlets_for_existing_users() SET SCHEMA public; -ALTER FUNCTION public.insert_default_navlets_for_existing_users() SET SCHEMA profiles; +ALTER FUNCTION insert_default_navlets_for_existing_users() SET SCHEMA arnold; +ALTER FUNCTION arnold.insert_default_navlets_for_existing_users() SET SCHEMA profiles; diff --git a/sql/changes/sc.04.08.0020.sql b/sql/changes/sc.04.08.0020.sql index 340d93909f..3ed78d6889 100644 --- a/sql/changes/sc.04.08.0020.sql +++ b/sql/changes/sc.04.08.0020.sql @@ -1,4 +1,4 @@ -CREATE OR REPLACE VIEW netboxmac as +CREATE OR REPLACE VIEW manage.netboxmac as SELECT DISTINCT ON (foo.mac) foo.netboxid, foo.mac FROM ( SELECT DISTINCT netbox.netboxid, diff --git a/sql/changes/sc.04.08.0050.sql b/sql/changes/sc.04.08.0050.sql index 7ed748668b..3323f3f9b6 100644 --- a/sql/changes/sc.04.08.0050.sql +++ b/sql/changes/sc.04.08.0050.sql @@ -1,4 +1,4 @@ -CREATE TABLE IF NOT EXISTS report_subscription ( +CREATE TABLE IF NOT EXISTS profiles.report_subscription ( id SERIAL PRIMARY KEY, account_id INT REFERENCES account ON DELETE CASCADE ON UPDATE CASCADE, address_id INT REFERENCES alertaddress ON DELETE CASCADE ON UPDATE CASCADE, diff --git a/sql/changes/sc.04.08.0410.sql b/sql/changes/sc.04.08.0410.sql index 426cac1995..0dcc286464 100644 --- a/sql/changes/sc.04.08.0410.sql +++ b/sql/changes/sc.04.08.0410.sql @@ -1,4 +1,4 @@ -CREATE TABLE poegroup ( +CREATE TABLE manage.poegroup ( poegroupid SERIAL PRIMARY KEY, netboxid INTEGER NOT NULL REFERENCES netbox ON DELETE CASCADE, moduleid INTEGER REFERENCES module ON DELETE CASCADE, @@ -8,7 +8,7 @@ CREATE TABLE poegroup ( UNIQUE (netboxid, index) ); -CREATE TABLE poeport ( +CREATE TABLE manage.poeport ( poeportid SERIAL PRIMARY KEY, netboxid INTEGER NOT NULL REFERENCES netbox ON DELETE CASCADE, poegroupid INTEGER NOT NULL REFERENCES poegroup ON DELETE CASCADE, diff --git a/sql/changes/sc.04.08.1000.sql b/sql/changes/sc.04.08.1000.sql new file mode 100644 index 0000000000..5e5a03403c --- /dev/null +++ b/sql/changes/sc.04.08.1000.sql @@ -0,0 +1,35 @@ +-- Some objects may have been installed in the wrong schema over time, due to +-- changes in how navsyncdb handles changes to the PostgreSQL search path. +-- +-- We attempt to move potentially affected objects to the correct schema here. +-- However, it is a PostgreSQL error move an object to a schema it is already +-- in, so we move objects back and forth to ensure this changescript works no +-- matter whether the object had been installed originally in the correct +-- schema. + +ALTER VIEW enterprise_number SET SCHEMA arnold; +ALTER VIEW arnold.enterprise_number SET SCHEMA manage; + +ALTER VIEW netboxmac SET SCHEMA arnold; +ALTER VIEW arnold.netboxmac SET SCHEMA manage; + +ALTER TABLE poeport SET SCHEMA arnold; +ALTER TABLE arnold.poeport SET SCHEMA manage; + +ALTER TABLE poegroup SET SCHEMA arnold; +ALTER TABLE arnold.poegroup SET SCHEMA manage; + +ALTER TABLE report_subscription SET SCHEMA arnold; +ALTER TABLE arnold.report_subscription SET SCHEMA profiles; + +ALTER FUNCTION close_snmpagentstates_on_community_clear() SET SCHEMA arnold; +ALTER FUNCTION arnold.close_snmpagentstates_on_community_clear() SET SCHEMA manage; + +ALTER FUNCTION close_thresholdstate_on_thresholdrule_delete() SET SCHEMA arnold; +ALTER FUNCTION arnold.close_thresholdstate_on_thresholdrule_delete() SET SCHEMA manage; + +ALTER FUNCTION never_use_null_subid() SET SCHEMA arnold; +ALTER FUNCTION arnold.never_use_null_subid() SET SCHEMA manage; + +ALTER FUNCTION peersession_update_timestamp() SET SCHEMA arnold; +ALTER FUNCTION arnold.peersession_update_timestamp() SET SCHEMA manage; diff --git a/sql/changes/sc.04.08.1001.sql b/sql/changes/sc.04.08.1001.sql new file mode 100644 index 0000000000..664b9ed864 --- /dev/null +++ b/sql/changes/sc.04.08.1001.sql @@ -0,0 +1,12 @@ +-- remove obsolete things that seem to hang around on some, but not all, +-- upgraded installations (i.e. these things are just fine in the baseline, +-- but may have become issues for those who have been upgrading NAV versions +-- repeatedly for a long time). + +DROP FUNCTION IF EXISTS drop_constraint(); + +ALTER TABLE cam + DROP CONSTRAINT IF EXISTS cam_netboxid_sysname_module_port_mac_start_time_key, + DROP CONSTRAINT IF EXISTS cam_netboxid_key; + +ALTER INDEX IF EXISTS subcat_pkey RENAME TO netboxgroup_pkey;