
-- EMS 2.14_01, table 'sysProperty', add data for new table.

-- EMS 2.14_04, table 'params', delete default row for 'id=1'
-- EMS 2.14_04, table 'broker', change default row for new column 'enable' to 1
-- EMS 2.14_04, table 'agentsdriver', change default row for column 'name' to polling-1, column 'delayread' to 0
    
-- EMS 2.20_01, table 'nodes', add new product FRM220A
-- EMS 2.20_01, table 'node_types', add new product FRM220A
-- EMS 2.20_01, table 'treelinks', add new product FRM220A

-- EMS 2.31_01, table 'nodes', add new product FRM220A-1000EAS/X
-- EMS 2.31_01, table 'nodes', remove record 'Series_Standalone' id 7
-- EMS 2.31_01, table 'nodes', modify record 'FRM220100AS2' id 70 to 'FRM220-10/100AS-2' id 43
-- EMS 2.31_01, table 'node_types', add new product FRM220A-1000EAS/X
-- EMS 2.31_01, table 'node_types', modify record 'FRM220100AS2' id 70 to FRM220-10/100AS-2 id 43
-- EMS 2.31_01, table 'treelinks', add new product FRM220A-1000EAS/X
-- EMS 2.31_01, table 'treelinks', modify record 'FRM220100AS2' child_id 70 to 'FRM220-10/100AS-2' child_id 43
-- EMS 2.31_01, table 'treelinks', remove record 'Series_Standalone' child_id 7

-- EMS 2.35_01, table 'nodes', add new product FMUX04E
-- EMS 2.35_01, table 'node_types', add new product FMUX04E
-- EMS 2.35_01, table 'treelinks', add new product FMUX04E

-- EMS 2.35_07, table 'nodes', add new product ERM-MUX/Plus
-- EMS 2.35_07, table 'node_types', add new product ERM-MUX/Plus
-- EMS 2.35_07, table 'treelinks', add new product ERM-MUX/Plus

-- EMS 2.45_06, table 'sysProperty', add radius authentication paramaters

-- EMS 2.51_10, table 'sysProperty', rename and add trap paramaters

-- EMS 2.51_13, table 'sysProperty', add syslog paramaters

-- EMS 2.54_02, table 'nodes', add new product FRM220B
-- EMS 2.54_02, table 'node_types', add new product FRM220B
-- EMS 2.54_02, table 'treelinks', add new product FRM220B

-- EMS 2.57_01, table 'nodes', add new series Industrial
-- EMS 2.57_01, table 'nodes', add new product IMC-1000M
-- EMS 2.57_01, table 'node_types', add new product IMC-1000M
-- EMS 2.57_01, table 'treelinks', add new series Industrial
-- EMS 2.57_01, table 'treelinks', add new product IMC-1000M

-- EMS 2.58_01, table 'nodes', add new product FRM220A-1000EAS/X-1
-- EMS 2.58_01, table 'node_types', add new product FRM220A-1000EAS/X-1
-- EMS 2.58_01, table 'treelinks', add new product FRM220A-1000EAS/X-1

-- EMS 2.60_01, modify table 'nodes', add record for new model PHB200
-- EMS 2.60_01, modify table 'node_types', add record for new model PHB200
-- EMS 2.60_01, modify table 'treelinks', add record for new model PHB200

-- EMS 2.61_01, table 'nodes', add new product IGS-803
-- EMS 2.61_01, table 'node_types', add new product IGS-803
-- EMS 2.61_01, table 'treelinks', add new product IGS-803

-- EMS 2.62_01, table 'nodes', add new product CHT-FRM220-1000EAS
-- EMS 2.62_01, table 'node_types', add new product CHT-FRM220-1000EAS
-- EMS 2.62_01, table 'treelinks', add new product CHT-FRM220-1000EAS

-- EMS 2.62_03, table 'nodes', add new product MSW202
-- EMS 2.62_03, table 'node_types', add new product MSW202
-- EMS 2.62_03, table 'treelinks', add new product MSW202

-- EMS 2.62_03, table 'nodes', add new product CHT-FRM220
-- EMS 2.62_03, table 'node_types', add new product CHT-FRM220
-- EMS 2.62_03, table 'treelinks', add new product CHT-FRM220

-- EMS 2.62_03, table 'nodes', add new product IGS-402
-- EMS 2.62_03, table 'node_types', add new product IGS-402
-- EMS 2.62_03, table 'treelinks', add new product IGS-402

-- EMS 2.63_01, table 'nodes', rename product CHT-FRM220-1000EAS to FRM220-1000EAS
-- EMS 2.63_01, table 'node_types', rename product CHT-FRM220-1000EAS to FRM220-1000EAS

-- EMS 2.63_01, table 'nodes', remove product CHT-FRM220 id 49
-- EMS 2.63_01, table 'node_types', remove product CHT-FRM220
-- EMS 2.63_01, table 'treelinks', remove product CHT-FRM220
-- EMS 2.63_01, table 'alarmType', create new table data
-- EMS 2.63_01, table 'alarm', create new table data for IGS803
-- EMS 2.63_01, table 'alarm', create new table data for IGS402
-- EMS 2.63_01, table 'alarm', create new table data for MSW202

-- EMS 2.64_01, table 'alarmType', rename type 4 to 'Fault On'
-- EMS 2.64_01, table 'alarmType', add type 8,9,10,11
-- EMS 2.64_01, remove table 'node_types' all data
-- EMS 2.64_01, remove table 'alarm' all data

-- EMS 2.66_01, table 'sysProperty', add upgrade paramaters

-- EMS 2.68_01, table 'nodes', add new product IMC-100M
-- EMS 2.68_01, table 'treelinks', add new product IMC-100M
-- EMS 2.68_01, table 'nodes', add new product MX210
-- EMS 2.68_01, table 'treelinks', add new product MX210
-- EMS 2.68_01, table 'alarmType', add type 12~19

-- EMS 2.70_01, table 'nodes', add new product IGS812
-- EMS 2.70_01, table 'treelinks', add new product IGS812
-- EMS 2.70_01, table 'nodes', add new product IGS1604
-- EMS 2.70_01, table 'treelinks', add new product IGS1604

-- EMS 2.71_01, table 'sysProperty', remove upgrade parameters upgradeDeviceType
-- EMS 2.71_01, table 'alarmType', add type 'Fiber FEF On'

-- EMS 2.72_01, table 'alarmTemplate', create new table data
-- EMS 2.72_01, table 'nodes', add new product IGS404
-- EMS 2.72_01, table 'treelinks', add new product IGS404

-- EMS 2.73_01, table 'nodes', add new product FMUX160/80/1600/800
-- EMS 2.73_01, table 'treelinks', add new product FMUX160/80/1600/800
-- EMS 2.73_01, table 'alarmType', add new type 21~25
-- EMS 2.73_01, table 'alarmTemplate', add new template FMUX160/80/1600/800

-- EMS 2.74_01, table 'sysProperty', add performance paramaters 

-- EMS 2.75_01, table 'alarmType', rename type 21~24
-- EMS 2.75_01, table 'alarmType', add new type 26~42 
-- EMS 2.75_01, table 'alarmTemplate', add new template iMUX4T/S, iMUX5T/S, iMUX8T/S, iMUX16T/S
-- EMS 2.75_01, table 'alarmTemplate', add new template 1000T(S)
-- EMS 2.75_01, add new alarm template FTEC
-- EMS 2.75_01, add new alarm template FXOFXS
-- EMS 2.75_01, add new alarm template FXOFXS4

-- EMS 2.75_01, table 'nodes', add new product FRM220-100AS-1, FRM220-1000EAS/X-2F
-- EMS 2.75_01, table 'treelinks', add new product FRM220-100AS-1, FRM220-1000EAS/X-2F
-- EMS 2.75_01, add new alarm templates for FRM220A-1000EAS/X, FRM220A-1000EAS/X-1, FRM220-100AS-1, FRM220-1000EAS/X-2F
-- EMS 2.75_01, add new alarm template GFOM04

-- EMS 2.75_01, table 'nodes', add new product IPS-803
-- EMS 2.75_01, table 'treelinks', add new product IPS-803
-- EMS 2.75_01, add new alarm template IPS-803

-- EMS 2.76_01, table 'sysProperty', add topology paramaters
-- EMS 2.77_01, modify table 'alarmTemplate', change max ring number from 10 to 5

-- EMS 2.78_01, table 'sysProperty', add upgrade scheduler paramaters

-- EMS 2.79_01, add new alarm template for NMC line card 1000EAS/X-2F and 100AS-1

-- EMS 2.81_01, table 'userRole', add column 'function'
-- EMS 2.81_01, table 'nodes', remove column 'acl'
-- EMS 2.81_01, table 'client', remove column 'acl'
-- EMS 2.81_01, table 'clientRole', user 'admin' belongs to role 'Administrator'

-- EMS 2.82_01, add new alarm template for NMC line card 16G-3R

-- EMS 2.86_01, table 'nodes', add new product IGS-804
-- EMS 2.86_01, table 'treelinks', add new product IGS-804
-- EMS 2.86_01, add new alarm template IGS-804

-- dont drop table data since database schema has been dropped before install table data
-- EMS 2.14_01, truncate new table 'sysProperty'
-----------------------------------------------------------------------------------------
--PRINT ''
--PRINT '--- delete table data ---'

--truncate table params

--truncate table messenger

--truncate table client
--truncate table privilege
--truncate table clientLog
--truncate table clientlogact
--truncate table clientAction

--truncate table device_props
--truncate table device_prop_items

--truncate table nodes
--truncate table node_types
--truncate table agent
--truncate table alias
--truncate table trees
--truncate table treelinks

--truncate table trapList
--truncate table pmList

--truncate table sysProperty			

--truncate table adlinks
--truncate table agentsdriver
--truncate table broker

--GO



PRINT ''

-- EMS 2.14_04, table 'params', delete default row for 'id=1'
-----------------------------------------------------------------------------------------
PRINT '--- insert data to table params ---'

--insert into params values(1,'active broker','val',1)	
insert into params values(21001,'exec broker_getactive','getBroker',1)
insert into params values(21002,'exec broker_getdrivers','getDrivers',1)
insert into params values(21003,'exec broker_getagents','getAgents',1)
--insert into params values(21101,'insert into trapalarm(agent_id,rack,slot,alarm_id,timestamp_device,timestamp_system) select id,?,?,?,?,getdate() from agent where ip_address like ?','setTrapAlarm',1)
--insert into params values(21102,'insert into traprackfound(agent_id,count_rack,timestamp_device,timestamp_system) select id,?,?,getdate() from agent where ip_address like ?','setTrapRackFound',1)
insert into params values(21103,'exec set_trapagent ?,?,?,?','setTrap',1)
insert into params values(21196,'exec set_traplist ?,?,?,?','setTrapList',1)
insert into params values(21197,'exec set_threshold ?,?,?,?','setThreshold',1)
insert into params values(21104,'insert into E101dayPMEntry select ?,getdate(),?,?,?,?,?,?,?,?,?,?,?,?,?','setE101dayPMEntry',1)
insert into params values(21105,'insert into HDSL01dayPMEntry select ?,getdate(),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?','setHDSL01dayPMEntry',1)
insert into params values(21106,'exec check_Worker ?,?,?','checkWorker',1)
insert into params values(21107,'exec get_Worker ?,?,?','getWorker',1)
insert into params values(21108,'exec set_WorkerProperties ?,?,?','setWorkerProperties',1)
insert into params values(21109,'exec getTreeList ?','getTreeList',1)
insert into params values(21115,'exec inzert ?,?,?,?,?','inzert',1)
insert into params values(21110,'exec getRoot ?','getRoot',1)
insert into params values(21111,'exec getChild ?,?,?','getChild',1)
insert into params values(21112,'exec getChildCount ?,?','getChildCount',1)
insert into params values(21113,'exec getIndexOfChild ?,?,?','getIndexOfChild',1)
insert into params values(21114,'exec getParent ?,?','getParent',1)
insert into params values(21116,'exec remove ?,?,?,?','remove',1)
insert into params values(21117,'exec createRoot ?,?,?','createRoot',1)
insert into params values(21118,'exec createNode ?,?,?','createNode',1)
insert into params values(21119,'exec getTreeNodes ?','getTreeNodes',1)
insert into params values(21120,'exec getTreeLinks ?','getTreeLinks',1)
insert into params values(21121,'exec insertAgent10 ?,?,?,?,?','insertAgent10',1)
insert into params values(21122,'exec createAgent10 ?,?','createAgent10',1)
insert into params values(21123,'exec copyNode ?,?,?,?,?,?','copyNode',1)
insert into params values(21124,'exec selectNodeLinks ?,?','selectNodeLinks',1)
insert into params values(21125,'exec selectNodes ?,?','selectNodes',1)
insert into params values(21126,'exec removeTree ?,?','removeTree',1)
insert into params values(21127,'exec createBatch ?,?,?,?','createBatch',1)
insert into params values(21128,'exec insertToBatch ?,?,?,?,?,?','insertToBatch',1)
insert into params values(21129,'exec getBatches ?,?','getBatches',1)
insert into params values(21130,'exec getBatchLines ?','getBatchLines',1)
insert into params values(21131,'exec runBatch ?','runBatch',1)
insert into params values(21132,'exec updateNode ?,?,?','updateNode',1)
insert into params values(21133,'exec createTemplate ?,?,?,?','createTemplate',1)
insert into params values(21134,'exec insertToTemplate ?,?,?,?,?,?','insertToTemplate',1)
insert into params values(21135,'exec getTemplates ?,?','getTemplates',1)
insert into params values(21136,'exec getTemplateLines ?','getTemplateLines',1)
insert into params values(21137,'exec removeTemplate ?,?','removeTemplate',1)
insert into params values(21138,'exec removeFromTemplate ?,?','removeFromTemplate',1)
insert into params values(21150, 'update params set val = ? where id = 1','setBrokerActive',1)
insert into params values(21151, 'insert into broker(name,ip_address,scanningperiod,port) values(?,?,?,?)','BrokerInsert',1)
insert into params values(21153, 'insert into agentsdriver(broker_id,name,delayread,pollingperiod,pollinginterval,type) values(?,?,?,?,?,?)','DriverInsert',1)
insert into params values(21155, 'exec admin_brokergetitem ?','getBrokerItem',1)
insert into params values(21156, 'exec admin_brokerupdate ?,?,?,?,?','BrokerUpdate',1)
insert into params values(21154, 'exec admin_brokerdelete ?','BrokerDelete',1)
insert into params values(21157, 'exec admin_driverupdate ?,?,?,?,?,?','DriverUpdate',1)
insert into params values(21158, 'exec admin_drivergetitem ?,?,?,?,?,?','getDriverItem',1)
insert into params values(21159, 'exec admin_driverdelete ?','DriverDelete',1)
insert into params values(21160, 'exec admin_getagents_in_driver ?','getagents_in_driver',1)
insert into params values(21161, 'exec admin_getagents_out_driver ?','getagents_out_driver',1)
insert into params values(21162, 'exec admin_agentaddindriver ?,?','AddAgentInDriver',1)
insert into params values(21163, 'exec admin_agentdelfromriver ?,?','DeleteAgentFromDriver',1)
insert into params values(21164,'exec admin_agentreadlist','agentreadlist',1)
insert into params values(21165,'exec admin_agentinsert ?,?,?,?,?,?,?,?,?,?','agentinsert',1)
insert into params values(21166,'exec admin_agentgetitem ?','agentgetitem',1)
insert into params values(21167,'exec admin_agentupdate ?,?,?,?,?,?,?,?,?,?,?','agentupdate',1)
insert into params values(21168,'exec admin_agentdelete ?','agentdelete',1)
insert into params values(21169,'exec admin_clientreadlist','clientreadlist',1)
insert into params values(21170,'exec admin_clientinsert ?,?,?,?,?,?,?,?,?','clientinsert',1)
insert into params values(21171,'exec admin_clientgetitem ?','clientgetitem',1)
insert into params values(21172,'exec admin_clientupdate ?,?,?,?,?,?,?,?,?,?','clientupdate',1)
insert into params values(21173,'exec admin_clientdelete ?','clientdelete',1)
insert into params values(21198,'exec admin_traplist_clear ?','traplistclear',1)
insert into params values(21199,'exec admin_threshold_clear ?','thresholdclear',1)
insert into params values(21200,'exec admin_clientlog_clear ?','clientlogclear',1)
insert into params values(21201,'exec admin_clientlogreadlist','clientlogreadlist',1)
insert into params values(21202,'exec admin_clientaction_clear ?','clientactionclear',1)
insert into params values(21180,'exec alarm_getagents','alarm_getagents',1)
insert into params values(21181,'exec alarm_readlist','alarm_readlist',1)
insert into params values(21185,'exec objtreenode_put ?,?,?','objtreenodeput',1)
insert into params values(21186,'exec objtreenode_get ?,?','objtreenodeget',1)
insert into params values(21187,'exec objtreenode_clr ?,?','objtreenodeclr',1)
insert into params values(21188,'exec obj_put ?,?,?','obj_put',1)
insert into params values(21189,'exec obj_get ?,?','obj_get',1)
insert into params values(21190,'exec obj_clr ?,?','obj_clr',1)
insert into params values(21191,'exec obj_readlist','obj_readlist',1)
insert into params values(21192,'exec register ?,?,?','register',1)
insert into params values(21193,'exec createAgent ?,?,?','createAgent',1)
insert into params values(21194,'exec get_device_props ?','get_device_props',1)
insert into params values(21195,'exec get_device_prop_items ?,?','get_device_prop_items',1)
insert into params values(21196,'exec admin_clientaction_clear ?','clientactionclear',1)
GO


-- EMS 2.14_04, table 'broker', change default row for new column 'enable' to 1
-----------------------------------------------------------------------------------------
PRINT '--- insert data to table broker ---'

insert into broker(name,ip_address,scanningperiod,port, enable) values('Broker-1','127.0.0.1',1000,900, 1)
GO


-- EMS 2.14_04, table 'agentsdriver', change default row for column 'name' to polling-1, column 'delayread' to 0
-----------------------------------------------------------------------------------------
PRINT '--- insert data to table agentsdriver ---'

insert into agentsdriver (broker_id,name,delayread,interval,timeout,type,thread) values(1,'Polling-1',0,1,3,0,1)    
GO


-- EMS 2.81_01, table 'client', remove column 'acl'
-----------------------------------------------------------------------------------------
PRINT '--- insert data to table client ---'

-- add administrator information, first row(id=1), sql operator, is administrator 
insert into client (name,password,phone,division,address,description,default_tree) 
    values('admin', '0000', '', 'IT Dep.', '', 'administrator', 0)
GO

-- EMS 2.81_01, table 'userRole', add column 'function'
-----------------------------------------------------------------------------------------
PRINT '--- insert data to table userRole ---'

/*  
    privilege for user to operate client GUI 
    administator: do all thing
    read-write  : do tree edit, snmp tool set  
    read-only   : do nothing  
*/
insert into userRole(name,description,[function]) values('Administrator', 'administrator', '1111') 
insert into userRole(name,description,[function]) values('Operator',      'read-write',    '1111') 
insert into userRole(name,description,[function]) values('User',          'read-only',     '0000') 
GO

-- EMS 2.81_01, table 'clientRole', user 'admin' belongs to role 'Administrator'
-----------------------------------------------------------------------------------------
PRINT '--- insert data to table clientRole ---'
insert into clientRole values(1,1)
GO

-----------------------------------------------------------------------------------------
PRINT '--- insert data to table clientlogact ---'

insert into clientlogact (code,action) values(0,'Client Login')
insert into clientlogact (code,action) values(1,'Client Logout')
GO


-- EMS 2.20_01, table 'nodes', add new product FRM220A
-- EMS 2.31_01, table 'nodes', add new product FRM220A-1000EAS/X 
-- EMS 2.31_01, table 'nodes', remove record 'Series_Standalone' id 7
-- EMS 2.31_01, table 'nodes', modify record 'FRM220100AS2' id 70 to 'FRM220-10/100AS-2' id 43
-- EMS 2.35_01, table 'nodes', add new product FMUX04E
-- EMS 2.35_07, table 'nodes', add new product ERM-MUX/Plus
-- EMS 2.54_02, table 'nodes', add new product FRM220B
-- EMS 2.57_01, table 'nodes', add new series Industrial
-- EMS 2.57_01, table 'nodes', add new product IMC-1000M
-- EMS 2.58_01, table 'nodes', add new product FRM220A-1000EAS/X-1
-- EMS 2.60_01, table 'nodes', add new product PHB200
-- EMS 2.61_01, table 'nodes', add new product IGS-803
-- EMS 2.62_01, table 'nodes', add new product CHT-FRM220-1000EAS
-- EMS 2.62_03, table 'nodes', add new product MSW202
-- EMS 2.62_03, table 'nodes', add new product CHT-FRM220
-- EMS 2.62_03, table 'nodes', add new product IGS-402
-- EMS 2.63_01, table 'nodes', rename product CHT-FRM220-1000EAS to FRM220-1000EAS
-- EMS 2.63_01, table 'nodes', remove product CHT-FRM220 id 49
-- EMS 2.68_01, table 'nodes', add new product IMC-100M
-- EMS 2.68_01, table 'nodes', add new product MX210
-- EMS 2.70_01, table 'nodes', add new product IGS812
-- EMS 2.70_01, table 'nodes', add new product IGS1604
-- EMS 2.72_01, table 'nodes', add new product IGS404
-- EMS 2.73_01, table 'nodes', add new product FMUX160/80/1600/800
-- EMS 2.75_01, table 'nodes', add new product FRM220-100AS-1, FRM220-1000EAS/X-2F
-- EMS 2.75_01, table 'nodes', add new product IPS-803
-- EMS 2.81_01, table 'nodes', remove column 'acl'
-- EMS 2.86_01, table 'nodes', add new product IGS-804
-----------------------------------------------------------------------------------------
PRINT '--- insert data to table nodes ---'

/*
    id: 1-10 for product series, series*10 for series agents, 1000 above for nodes user created  
    type_id: 1:gerenic , 2:map
*/
insert into nodes (id,name,type_id,client_id) values(    1, 'Products',            1,1)
insert into nodes (id,name,type_id,client_id) values(    2, 'Series_PDH',          1,1)
insert into nodes (id,name,type_id,client_id) values(    3, 'Series_FOM',          1,1)
insert into nodes (id,name,type_id,client_id) values(    4, 'Series_Fiber',        1,1)
insert into nodes (id,name,type_id,client_id) values(    5, 'Series_WDM',          1,1)
insert into nodes (id,name,type_id,client_id) values(    6, 'Series_Generic',      1,1)	-- update: 20091027   (Release by v2.07)
insert into nodes (id,name,type_id,client_id) values(    7, 'Series_Industrial',   1,1) -- update: 20131023
insert into nodes (id,name,type_id,client_id) values(   21, 'ETU01A',              1,1)
insert into nodes (id,name,type_id,client_id) values(   22, 'ERM01',               1,1)
insert into nodes (id,name,type_id,client_id) values(   23, 'ERM04',               1,1)
insert into nodes (id,name,type_id,client_id) values(   24, 'ELINK',               1,1)
insert into nodes (id,name,type_id,client_id) values(   25, 'ERM-MUX/Plus',        1,1)
insert into nodes (id,name,type_id,client_id) values(   30, 'FMUX01A',             1,1)
insert into nodes (id,name,type_id,client_id) values(   31, 'FMUX01APlus',         1,1)
insert into nodes (id,name,type_id,client_id) values(   32, 'FMUX04',	           1,1)		-- update: 20090921   (Release by v2.06)
insert into nodes (id,name,type_id,client_id) values(   33, 'FMUX04E',	           1,1)
insert into nodes (id,name,type_id,client_id) values(   34, 'FMUX160',	           1,1)
insert into nodes (id,name,type_id,client_id) values(   35, 'FMUX80',	           1,1)
insert into nodes (id,name,type_id,client_id) values(   36, 'FMUX1600',	           1,1)
insert into nodes (id,name,type_id,client_id) values(   37, 'FMUX800',	           1,1)
insert into nodes (id,name,type_id,client_id) values(   40, 'FRM220',              1,1)
insert into nodes (id,name,type_id,client_id) values(   41, 'FRM220A',             1,1)
insert into nodes (id,name,type_id,client_id) values(   42, 'FRM220A-1000EAS/X',   1,1)
insert into nodes (id,name,type_id,client_id) values(   43, 'FRM220-10/100AS-2',   1,1)
insert into nodes (id,name,type_id,client_id) values(   44, 'FRM220B',	           1,1)
insert into nodes (id,name,type_id,client_id) values(   45, 'FRM220A-1000EAS/X-1', 1,1)
insert into nodes (id,name,type_id,client_id) values(   46, 'PHB200',              1,1)
insert into nodes (id,name,type_id,client_id) values(   47, 'FRM220-1000EAS',      1,1)
insert into nodes (id,name,type_id,client_id) values(   48, 'MSW202',              1,1)
insert into nodes (id,name,type_id,client_id) values(   49, 'MX210',               1,1)
insert into nodes (id,name,type_id,client_id) values(   50, 'SML2000',	           1,1)		-- update: 20091217   (Release by v2.09)
insert into nodes (id,name,type_id,client_id) values(   51, 'SML5000',	           1,1)		-- update: 20091217   (Release by v2.09)
insert into nodes (id,name,type_id,client_id) values(   71, 'IMC-1000M',           1,1)		-- update: 20131023
insert into nodes (id,name,type_id,client_id) values(   72, 'IFS/IGS-803SM',       1,1)		-- update: 20140124
insert into nodes (id,name,type_id,client_id) values(   73, 'IFS/IGS-402SM',       1,1)		-- update: 20140325
insert into nodes (id,name,type_id,client_id) values(   74, 'IMC-100M',            1,1)
insert into nodes (id,name,type_id,client_id) values(   75, 'IFS/IGS-803SM',       1,1)
insert into nodes (id,name,type_id,client_id) values(   76, 'IFS/IGS-1604SM',      1,1)
insert into nodes (id,name,type_id,client_id) values(   77, 'IFS/IGS-404SM',       1,1)
insert into nodes (id,name,type_id,client_id) values(   78, 'IPS-803SM',           1,1)
insert into nodes (id,name,type_id,client_id) values(   79, 'IFS/IGS-804SM',       1,1)
insert into nodes (id,name,type_id,client_id) values(   80, 'FRM220-100AS-1',      1,1)
insert into nodes (id,name,type_id,client_id) values(   81, 'FRM220-1000EAS/X-2F', 1,1)
insert into nodes (id,name,type_id,client_id) values(   0,  'Generic',             1,1)      -- update: 20091027   (Release by v2.07)

--insert into nodes (id,name,type_id,client_id,acl) values(10000, 'User_Mark',      1,1,1)	--user nodes from this id
GO


-----------------------------------------------------------------------------------------
PRINT '--- insert data to table trees ---'

/*
    repository: 0:normal, 
                1:default tree for tree id=1
    type: 0:private, 
          1:public
*/
insert into trees (node_id,repository,type) values(1, 1, 0)
GO


-- EMS 2.20_01, table 'treelinks', add new product FRM220A
-- EMS 2.31_01, table 'treelinks', add new product FRM220A-1000EAS/X
-- EMS 2.31_01, table 'treelinks', modify record 'FRM220100AS2' child_id 70 to 'FRM220-10/100AS-2' child_id 43
-- EMS 2.31_01, table 'treelinks', remove record 'Series_Standalone' child_id 7
-- EMS 2.35_01, table 'treelinks', add new product FMUX04E
-- EMS 2.35_07, table 'treelinks', add new product ERM-MUX/Plus
-- EMS 2.54_02, table 'treelinks', add new product FRM220B
-- EMS 2.57_01, table 'treelinks', add new series  Industrial
-- EMS 2.57_01, table 'treelinks', add new product IMC-1000M
-- EMS 2.58_01, table 'treelinks', add new product FRM220A-EAS/X-1
-- EMS 2.60_01, table 'treelinks', add new product PHB200
-- EMS 2.61_01, table 'treelinks', add new product IGS-803
-- EMS 2.62_01, table 'treelinks', add new product CHT-FRM220-1000EAS
-- EMS 2.62_03, table 'treelinks', add new product MSW202
-- EMS 2.62_03, table 'treelinks', add new product CHT-FRM220
-- EMS 2.62_03, table 'treelinks', add new product IGS-402
-- EMS 2.63_01, table 'treelinks', remove  product CHT-FRM220
-- EMS 2.68_01, table 'treelinks', add new product IMC-100M
-- EMS 2.68_01, table 'treelinks', add new product MX210
-- EMS 2.70_01, table 'treelinks', add new product IGS812
-- EMS 2.70_01, table 'treelinks', add new product IGS1604
-- EMS 2.72_01, table 'treelinks', add new product IGS404
-- EMS 2.73_01, table 'treelinks', add new product FMUX160/80/1600/800
-- EMS 2.75_01, table 'treelinks', add new product FRM220-100AS-1, FRM220-1000EAS/X-2F
-- EMS 2.75_01, table 'treelinks', add new product IPS-803
-- EMS 2.86_01, table 'treelinks', add new product IGS-804
-----------------------------------------------------------------------------------------
PRINT '--- insert data to table treelinks ---'

/*
    Join agent into parent category in default product tree 
    tree_id:   default product tree, id=1
    parent_id: category node
    child_id:  new agent
    idx:       agent index in parent category, never mind the order, EMS will re-order by itself
    lvl:       agent level from root node
*/ 
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1, -1,  1, 0, 0)      
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  1,  2, 0, 1)  -- parent_id 1 is Products
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  1,  3, 1, 1) 
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  1,  4, 2, 1)
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  1,  5, 3, 1)
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  1,  6, 4, 1)  -- update: 20091027		(Release by v2.07)
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  1,  7, 5, 1)  -- update: 20131023
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  2, 21, 0, 2)  -- parent_id 2 is Series_PDH
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  2, 24, 1, 2)
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  2, 22, 2, 2)
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  2, 23, 3, 2)
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  2, 25, 4, 2)  -- ERM-MUX/Plus
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  3, 30, 0, 2)  -- parent_id 3 is Series_FOM
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  3, 31, 1, 2)
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  3, 32, 2, 2)  -- update: 20090921		(Release by v2.06)
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  3, 33, 3, 2)
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  3, 34, 4, 2)
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  3, 35, 5, 2)
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  3, 36, 6, 2)
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  3, 37, 7, 2)
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  4, 40, 0, 2)  -- parent_id 4 is Series_Fiber
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  4, 41, 1, 2)  -- FRM220A
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  4, 42, 2, 2)  -- FRM220A-1000EAS/X
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  4, 43, 3, 2)  -- FRM220A-100AS
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  4, 44, 4, 2)  -- FRM220B
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  4, 45, 5, 2)  -- FRM220A-1000EAS/X-1
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  4, 46, 6, 2)  -- PHB200
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  4, 47, 7, 2)  -- FRM220-1000EAS
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  4, 48, 8, 2)  -- MSW202
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  4, 49, 9, 2)  -- MX210
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  4, 80, 10, 2) -- FRM220-100AS-1
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  4, 81, 11, 2) -- FRM220-1000EAS/X-2F
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  5, 50, 0, 2)  -- parent_id 5: Series_WDM       -- update:20091217   (Release by v2.09)
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  5, 51, 1, 2)  -- update:20091217   (Release by v2.09)
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  6,  0, 0, 2)  -- parent_id 6: Series_Generic   -- update: 20091027		(Release by v2.07)
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  7, 71, 0, 2)  --
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  7, 72, 1, 2)  --
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  7, 73, 2, 2)  --
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  7, 74, 3, 2)  --
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  7, 75, 4, 2)  --
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  7, 76, 5, 2)  --
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  7, 77, 6, 2)  --
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  7, 78, 7, 2)  --
insert into treelinks (tree_id,parent_id,child_id,idx,lvl) values(1,  7, 79, 8, 2)  -- IGS-804
GO


-- EMS 2.63_01, table 'alarmType', create new table data
-- EMS 2.64_01, table 'alarmType', rename type 4 to 'Fault On'
-- EMS 2.64_01, table 'alarmType', add type 8,9,10,11
-- EMS 2.68_01, table 'alarmType', add type 12~19
-- EMS 2.71_01, table 'alarmType', add type 'Fiber FEF On'
-- EMS 2.73_01, table 'alarmType', add new type 21~25
-- EMS 2.75_01, table 'alarmType', rename type 21~24
-- EMS 2.75_01, table 'alarmType', add new type 26~43
-----------------------------------------------------------------------------------------
PRINT '--- insert data to table alarmType ---'

INSERT INTO alarmType (id, name) VALUES (1, 'Power Off')
INSERT INTO alarmType (id, name) VALUES (2, 'UTP Link Down')
INSERT INTO alarmType (id, name) VALUES (3, 'Fiber Link Down')
INSERT INTO alarmType (id, name) VALUES (4, 'Fault On')
INSERT INTO alarmType (id, name) VALUES (5, 'PoE Power Buget Exceed')
INSERT INTO alarmType (id, name) VALUES (6, 'PoE PD overload')
INSERT INTO alarmType (id, name) VALUES (7, 'Ring Fault')
INSERT INTO alarmType (id, name) VALUES (8, 'Fan Off')
INSERT INTO alarmType (id, name) VALUES (9, 'Alarm On')
INSERT INTO alarmType (id, name) VALUES (10, 'Remote Power Off')
INSERT INTO alarmType (id, name) VALUES (11, 'Fiber Loopback Test')
INSERT INTO alarmType (id, name) VALUES (12, 'Fiber Rx Power Low')
INSERT INTO alarmType (id, name) VALUES (13, 'Fiber Rx Power Error')
INSERT INTO alarmType (id, name) VALUES (14, 'Fiber Temperature Abnormal')
INSERT INTO alarmType (id, name) VALUES (15, 'Fiber Tx Fail')
INSERT INTO alarmType (id, name) VALUES (16, 'Fiber Tx BERT Test')
INSERT INTO alarmType (id, name) VALUES (17, 'Fiber Rx BERT Test')
INSERT INTO alarmType (id, name) VALUES (18, 'Card Error')
INSERT INTO alarmType (id, name) VALUES (19, 'Fiber Wave Length Abnormal')
INSERT INTO alarmType (id, name) VALUES (20, 'Fiber FEF On')
INSERT INTO alarmType (id, name) VALUES (21, 'E1/T1 Rx Loss')
INSERT INTO alarmType (id, name) VALUES (22, 'E1/T1 AIS On')
INSERT INTO alarmType (id, name) VALUES (23, 'E1/T1 Tx Fail')
INSERT INTO alarmType (id, name) VALUES (24, 'E1/T1 Loopback Test')
INSERT INTO alarmType (id, name) VALUES (25, 'Fiber Bit Error')
INSERT INTO alarmType (id, name) VALUES (26, 'Fiber Has No Optical Signal')
INSERT INTO alarmType (id, name) VALUES (27, 'E1 Alarm On')
INSERT INTO alarmType (id, name) VALUES (28, 'E1 AIS On')
INSERT INTO alarmType (id, name) VALUES (29, 'E1 RAI On')
INSERT INTO alarmType (id, name) VALUES (30, 'E1 LOMF On')
INSERT INTO alarmType (id, name) VALUES (31, 'E1 Defected')
INSERT INTO alarmType (id, name) VALUES (32, 'E1 Signal Loss')
INSERT INTO alarmType (id, name) VALUES (33, 'E1 Sync Loss')
INSERT INTO alarmType (id, name) VALUES (34, 'E1 Loopback Test')
INSERT INTO alarmType (id, name) VALUES (35, 'E1 BERT Test')
INSERT INTO alarmType (id, name) VALUES (36, 'E1 BERT Test Has Error')
INSERT INTO alarmType (id, name) VALUES (37, 'T1 Signal Loss')
INSERT INTO alarmType (id, name) VALUES (38, 'T1 Sync Loss')
INSERT INTO alarmType (id, name) VALUES (39, 'T1 Alarm On')
INSERT INTO alarmType (id, name) VALUES (40, 'T1 AIS On')
INSERT INTO alarmType (id, name) VALUES (41, 'T1 Loopback Test')
INSERT INTO alarmType (id, name) VALUES (42, 'Front Panel Loopback Test')

GO


-- EMS 2.14_01, table 'sysProperty', add data for new table.
-- EMS 2.45_06, table 'sysProperty', add radius authentication paramaters
-- EMS 2.51_10, table 'sysProperty', rename and add trap paramaters
-- EMS 2.51_13, table 'sysProperty', add syslog paramaters
-- EMS 2.66_01, table 'sysProperty', add upgrade paramaters
-- EMS 2.71_01, table 'sysProperty', remove upgrade parameters upgradeDeviceType
-- EMS 2.74_01, table 'sysProperty', add performance paramaters 
-- EMS 2.76_01, table 'sysProperty', add topology paramaters
-- EMS 2.78_01, table 'sysProperty', add upgrade scheduler paramaters
-----------------------------------------------------------------------------------------
PRINT '--- insert data to table sysProperty ---'

/*
    system setting for server
*/ 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('backupAuto',        '0')   
INSERT INTO [sysProperty] ([name], [value]) VALUES ('backupRule',        '1')    
INSERT INTO [sysProperty] ([name], [value]) VALUES ('backupStartTime',   '')    
INSERT INTO [sysProperty] ([name], [value]) VALUES ('backupEndTime',     '')     
INSERT INTO [sysProperty] ([name], [value]) VALUES ('backupRestoreTime', '')   
INSERT INTO [sysProperty] ([name], [value]) VALUES ('historyPeriodRecord', '3')     
INSERT INTO [sysProperty] ([name], [value]) VALUES ('historyPeriodFile', '3')     
INSERT INTO [sysProperty] ([name], [value]) VALUES ('historyAutoFile',   '0')  
INSERT INTO [sysProperty] ([name], [value]) VALUES ('pmInterval',        '15') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('pmThread',          '2') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('radiusEnable',      '0')  		
INSERT INTO [sysProperty] ([name], [value]) VALUES ('radiusAddress',     '10.1.1.1')  		
INSERT INTO [sysProperty] ([name], [value]) VALUES ('radiusPort',        '1812')  		
INSERT INTO [sysProperty] ([name], [value]) VALUES ('radiusSecret',      'secret')  
INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogEnable',      '0')  
INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogAddress',     '10.1.1.1')  
INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogPort',        '514')  
INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogUserLog',     '0')  
INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogActionLog',   '0')  
INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogFacUser',     '4')  
INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogFacAction',   '10')  
INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogSevUser',     '5')  
INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogSevAction',   '5') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('topologyLock',      '0') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('topologyName',      '1') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('trapEnable',        '0')  
INSERT INTO [sysProperty] ([name], [value]) VALUES ('trapReceiverIP',    '10.1.1.1')  
INSERT INTO [sysProperty] ([name], [value]) VALUES ('trapPort',          '162')  
INSERT INTO [sysProperty] ([name], [value]) VALUES ('trapCommunity',     'public')  
INSERT INTO [sysProperty] ([name], [value]) VALUES ('trapDeviceName',    '0')  
INSERT INTO [sysProperty] ([name], [value]) VALUES ('trapForwarding',    '0')  
INSERT INTO [sysProperty] ([name], [value]) VALUES ('trapDeviceDisconnect', '0')  
INSERT INTO [sysProperty] ([name], [value]) VALUES ('upgradeInterval',        '3') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('upgradeTftpAddress',     '10.1.1.1') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('upgradeTftpFile',        'firmware.img')
INSERT INTO [sysProperty] ([name], [value]) VALUES ('upgradeSchedulerEnable', '0') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('upgradeSchedulerTime',   '0') 
GO

-- EMS 2.72_01, table 'alarmTemplate', create new table data
-- EMS 2.73_01, table 'alarmTemplate', add new template FMUX160/80/1600/800
-----------------------------------------------------------------------------------------
PRINT '--- insert data to table alarmTemplate ---'

DECLARE @cnt INT  -- loop counter
DECLARE @dvc INT  -- device type or card Id
DECLARE @sid INT
DECLARE @ena INT
	    
SET @sid = 0  -- 0 for local, not used so far (2014-0710), no model needs another template for remtoe. New template may need it some day.
SET @ena = 1  -- default 1 to enable alarm
	    
----- DEVICE_IGS803(72)
SET @dvc = 72
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 1, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 2, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,4, 1, 4,@ena,'') -- ALARM_FAULT_ON(4), SEVERITY_MINOR(4)    
    
	WHILE (@cnt <= 8) -- 8 UTP
	BEGIN		
		IF (@cnt <= 5) -- 5 Ring
		BEGIN
			IF (@cnt <= 3)  -- 3 FIBER
			BEGIN
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)        
			END
		
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,7, @cnt, 4,@ena,'') -- ALARM_RING_FAULT(7), SEVERITY_MINOR(4)        
		END	
			
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2, @cnt, 5,@ena,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)        
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,5, @cnt, 3,@ena,'') -- ALARM_POEBUDGET_EXCEED(5), SEVERITY_MAJOR(3)        
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,6, @cnt, 3,@ena,'') -- ALARM_POEPD_OVERLOAD(6), SEVERITY_MAJOR(3)        
		
		SET @cnt = @cnt + 1
	END
END


----- DEVICE_IGS402(73)
SET @dvc = 73
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 1, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 2, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,4, 1, 4,@ena,'') -- ALARM_FAULT_ON(4), SEVERITY_MINOR(4)    
    
	WHILE (@cnt <= 4) -- 4 UTP
	BEGIN		
		IF (@cnt <= 3) -- 3 Ring
		BEGIN
			IF (@cnt <= 2)  -- 2 FIBER
			BEGIN
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)        
			END
		
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,7, @cnt, 4,@ena,'') -- ALARM_RING_FAULT(7), SEVERITY_MINOR(4)        
		END	
			
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2, @cnt, 5,@ena,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)        
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,5, @cnt, 3,@ena,'') -- ALARM_POEBUDGET_EXCEED(5), SEVERITY_MAJOR(3)        
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,6, @cnt, 3,@ena,'') -- ALARM_POEPD_OVERLOAD(6), SEVERITY_MAJOR(3)        
		
		SET @cnt = @cnt + 1
	END
END

----- DEVICE_IGS404(77)
SET @dvc = 77
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 1, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 2, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,4, 1, 4,@ena,'') -- ALARM_FAULT_ON(4), SEVERITY_MINOR(4)    
    
	WHILE (@cnt <= 4) -- 4 UTP, 4 FIBER, 4 Ring
	BEGIN		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,7,  @cnt, 4,@ena,'')    -- ALARM_RING_FAULT(7), SEVERITY_MINOR(4)	
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)        
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,5,  @cnt, 3,@ena,'')    -- ALARM_POEBUDGET_EXCEED(5), SEVERITY_MAJOR(3)        
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,6,  @cnt, 3,@ena,'')    -- ALARM_POEPD_OVERLOAD(6), SEVERITY_MAJOR(3)        
		
		SET @cnt = @cnt + 1
	END
END

-- EMS 2.77_01, modify table 'alarmTemplate', change max ring number from 10 to 5
----- DEVICE_IGS812(75)
SET @dvc = 75
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 1, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 2, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,4, 1, 4,@ena,'') -- ALARM_FAULT_ON(4), SEVERITY_MINOR(4)    
    
	WHILE (@cnt <= 12) -- 12 FIBER
	BEGIN
		IF (@cnt <= 8) -- 8 UTP, IGS812 No POE
		BEGIN
			IF (@cnt <= 5)  -- 5 Ring
			BEGIN
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,7, @cnt, 4,@ena,'') -- ALARM_RING_FAULT(7), SEVERITY_MINOR(4)
			END
			
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,2, @cnt, 5,@ena,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
		END	
			
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)
		
		SET @cnt = @cnt + 1
	END
END

-- EMS 2.77_01, modify table 'alarmTemplate', change max ring number from 10 to 5
----- DEVICE_IGS1604 (76)
SET @dvc = 76
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 1, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 2, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,4, 1, 4,@ena,'') -- ALARM_FAULT_ON(4), SEVERITY_MINOR(4)    
    
	WHILE (@cnt <= 16) -- 16 UTP, IGS1604 No POE
	BEGIN
		IF (@cnt <= 5) -- 5 Ring
		BEGIN
			IF (@cnt <= 4)  -- 4 FIBER
			BEGIN
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
			END	
			
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,7, @cnt, 4,@ena,'') -- ALARM_RING_FAULT(7), SEVERITY_MINOR(4)        
		END	
			
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2, @cnt, 5,@ena,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
		
		SET @cnt = @cnt + 1
	END
END

----- DEVICE_IGS404(77)
SET @dvc = 77
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 1, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 2, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,4, 1, 4,@ena,'') -- ALARM_FAULT_ON(4), SEVERITY_MINOR(4)    
    
	WHILE (@cnt <= 4) -- 4 UTP
	BEGIN		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)        
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,5,  @cnt, 3,@ena,'')    -- ALARM_POEBUDGET_EXCEED(5), SEVERITY_MAJOR(3)        
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,6,  @cnt, 3,@ena,'')    -- ALARM_POEPD_OVERLOAD(6), SEVERITY_MAJOR(3)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,7,  @cnt, 4,@ena,'')    -- ALARM_RING_FAULT(7), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)        
		
		SET @cnt = @cnt + 1
	END
END

	
----- DEVICE_MSW202(48)
SET @dvc = 48
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 3) -- 3 UTP
	BEGIN
		IF (@cnt <= 2)  -- 2 FIBER, 2 Ring
		BEGIN
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,7,  @cnt, 4,@ena,'')    -- ALARM_RING_FAULT(7), SEVERITY_MINOR(4)
		END	
			
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2, @cnt, 5,@ena,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
		
		SET @cnt = @cnt + 1
	END	
END


----- DEVICE_MX210(49)
SET @dvc = 49
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 3) -- 3 FIBER
	BEGIN
		IF (@cnt <= 2)  -- 2 UTP, 2 Ring
		BEGIN
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,2, @cnt, 5,@ena,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,7, @cnt, 4,@ena,'') -- ALARM_RING_FAULT(7), SEVERITY_MINOR(4)
		END	
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END	
END
GO

DECLARE @cnt INT  -- loop counter
DECLARE @dvc INT  -- device type or card Id
DECLARE @sid INT
DECLARE @ena INT
	    
SET @sid = 0  -- 0 for local, not used so far (2014-0710), no model needs another template for remtoe. New template may need it some day.
SET @ena = 1  -- default 1 to enable alarm

----- DEVICE_FRM220_1000EAS(47)
SET @dvc = 47
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 2) -- 2 FIBER, 2 UTP
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END	
END


----- DEVICE_FRM220A(41)
SET @dvc = 41
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 4) -- 4 FIBER, 4 UTP
	BEGIN
		IF (@cnt <= 2)  -- 2 Power, 2 Fan, 2 Alarm
		BEGIN
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,1,  @cnt, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,8,  @cnt, 4,@ena,'') -- ALARM_FAN_OFF(8), SEVERITY_MINOR(4)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,9,  @cnt, 4,@ena,'') -- ALARM_ALARM_ON(9), SEVERITY_MINOR(4)
		END
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'') -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		SET @cnt = @cnt + 1
	END	
END

	
----- CARD_NMC(1001)
SET @dvc = 1001
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 2) -- 2 Power, 2 Fan, 2 Alarm
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,1,  @cnt, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,8,  @cnt, 4,@ena,'') -- ALARM_FAN_OFF(8), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,9,  @cnt, 4,@ena,'') -- ALARM_ALARM_ON(9), SEVERITY_MINOR(4)
		
		SET @cnt = @cnt + 1
	END		
END


----- CARD_1000EASX(1002)
SET @dvc = 1002
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 2) -- 2 FIBER, 2 UTP
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END		
END


----- CARD_1000EAS(1003)
SET @dvc = 1003
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 2) -- 2 FIBER, 2 UTP
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END		
END

    
----- CARD_1000EAS_2F(1004)
SET @dvc = 1004
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 2) -- 2 FIBER, 0 UTP
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END		    
END

    
----- CARD_1000EA_2F(1005)
SET @dvc = 1005
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 2) -- 2 FIBER, 0 UTP
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END		        
END

    
----- CARD_1000EAS_1(1006)
SET @dvc = 1006
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
END


----- CARD_1000EA_1(1007)
SET @dvc = 1007
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
END
GO


DECLARE @cnt INT  -- loop counter
DECLARE @dvc INT  -- device type or card Id
DECLARE @sid INT
DECLARE @ena INT
	    
SET @sid = 0  -- 0 for local, not used so far (2014-0710), no model needs another template for remtoe. New template may need it some day.
SET @ena = 1  -- default 1 to enable alarm

----- CARD_2R4G_2S(1008)
SET @dvc = 1008
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 2) -- 2 FIBER, 0 UTP
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,15, @cnt, 5,@ena,'')    -- ALARM_FIBER_TX_FAIL(15), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END		
END

    
----- CARD_2R4G_3S(1009)
SET @dvc = 1009
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 3) -- 3 FIBER, 0 UTP
	BEGIN
		IF(@cnt<=2)
		BEGIN
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')  -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		END
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,15, @cnt, 5,@ena,'')    -- ALARM_FIBER_TX_FAIL(15), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END		    
END

    
----- CARD_3R27G_2S(1010)
SET @dvc = 1010
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 2) -- 2 FIBER, 0 UTP
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,15, @cnt, 5,@ena,'')    -- ALARM_FIBER_TX_FAIL(15), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END		    
END

    
----- CARD_3R27G_3S(1011)
SET @dvc = 1011
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 3) -- 3 FIBER, 0 UTP
	BEGIN
		IF(@cnt<=2)
		BEGIN
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')  -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		END
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,15, @cnt, 5,@ena,'')    -- ALARM_FIBER_TX_FAIL(15), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END		    
END

    
----- CARD_3R10G_SS(1012)
SET @dvc = 1012
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,18, @cnt, 3,@ena,'') -- ALARM_CARD_ERROR(18), SEVERITY_MAJOR(3)
		
	WHILE (@cnt <= 2) -- 2 FIBER, 0 UTP
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,15, @cnt, 5,@ena,'')    -- ALARM_FIBER_TX_FAIL(15), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END		    
END

    
----- CARD_10G_SX(1013)
SET @dvc = 1013
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,18, @cnt, 3,@ena,'') -- ALARM_CARD_ERROR(18), SEVERITY_MAJOR(3)
		
	WHILE (@cnt <= 2) -- 2 FIBER, 0 UTP
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END		        
END


----- CARD_10G_XX(1014)
SET @dvc = 1014
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,18, @cnt, 3,@ena,'') -- ALARM_CARD_ERROR(18), SEVERITY_MAJOR(3)
		
	WHILE (@cnt <= 2) -- 2 FIBER, 0 UTP
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END		            
END

	
----- CARD_10G_SXX(1015)
SET @dvc = 1015
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,18, @cnt, 3,@ena,'') -- ALARM_CARD_ERROR(18), SEVERITY_MAJOR(3)
		
	WHILE (@cnt <= 3) -- 3 FIBER, 0 UTP
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		-- CHT only, must be filtered out in GUI.
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,16, @cnt, 7,@ena,'') -- ALARM_FIBER_TX_BERT_TEST(16), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,17, @cnt, 7,@ena,'') -- ALARM_FIBER_RX_BERT_TEST(17), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,19, @cnt, 3,@ena,'') -- ALARM_FIBER_WAVELENGTH_ABNORMAL(19), SEVERITY_MAJOR(3)	
		
		SET @cnt = @cnt + 1
	END		            	
END

-- EMS 2.82_01, add new alarm template for NMC line card 16G-3R
----- CARD_16G_3R(1047)
SET @dvc = 1047
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
    WHILE (@cnt <= 4) -- 4 FIBER, 0 UTP
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,15, @cnt, 5,@ena,'')    -- ALARM_FIBER_TX_FAIL(15), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END		            	
END
    
----- CARD_1000DS(1016)
SET @dvc = 1016
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 2) -- 2 FIBER, 0 UTP
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,15, @cnt, 5,@ena,'')    -- ALARM_FIBER_TX_FAIL(15), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END		        
END
GO
    
DECLARE @cnt INT  -- loop counter
DECLARE @dvc INT  -- device type or card Id
DECLARE @sid INT
DECLARE @ena INT
	    
SET @sid = 0  -- 0 for local, not used so far (2014-0710), no model needs another template for remtoe. New template may need it some day.
SET @ena = 1  -- default 1 to enable alarm    
    
----- CARD_100M(1017)
----- CARD_100MS(1018)
----- CARD_1000M(1019)
----- CARD_1000MS(1020)
----- CARD_IMC_100M(1021)
----- CARD_IMC_100MS(1022)
----- CARD_IMC_1000M(1023)
----- CARD_IMC_1000MS(1024)
	SET @dvc = 1017
	SET @cnt = 1    
    WHILE (@dvc <= 1024)
	BEGIN
		IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
		BEGIN
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
			IF(@dvc >= 1021) -- IMC only
			BEGIN
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 1, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 2, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)    
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,4, 1, 4,@ena,'') -- ALARM_FAULT_ON(4), SEVERITY_MINOR(4)
			END
			
			SET @dvc = @dvc + 1
		END	
	END
    
    
----- CARD_MSW202(1025)
SET @dvc = 1025
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 2) -- 2 FIBER, 2 UTP, 2 Ring
	BEGIN			
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,7,  @cnt, 4,@ena,'')    -- ALARM_RING_FAULT(7), SEVERITY_MINOR(4)
		
		SET @cnt = @cnt + 1
	END	        
END

        
----- CARD_MX210(1026)
SET @dvc = 1026
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 3) -- 3 FIBER
	BEGIN
		IF (@cnt <= 2)  -- 2 Ring
		BEGIN
			IF (@cnt <= 1)  -- 1 UTP
			BEGIN
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,2, @cnt, 5,@ena,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
			END
		
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,7, @cnt, 4,@ena,'') -- ALARM_RING_FAULT(7), SEVERITY_MINOR(4)
		END	
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END	            
END
GO

DECLARE @cnt INT  -- loop counter
DECLARE @dvc INT  -- device type or card Id
DECLARE @sid INT
DECLARE @ena INT
	    
SET @sid = 0  -- 0 for local, not used so far (2014-0710), no model needs another template for remtoe. New template may need it some day.
SET @ena = 1  -- default 1 to enable alarm    

----- CARD_1000EASX_1(1027)
SET @dvc = 1027
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)
END

-- EMS 2.79_01, add new alarm template for NMC line card 1000EAS/X-2F and 100AS-1
----- CARD_100AS_1(1045)
SET @dvc = 1045
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)
END

----- CARD_1000EASX_2F(1046)
SET @dvc = 1046
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 2) -- 2 FIBER, no UTP
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END		
END

----- CARD_100I(1028)
SET @dvc = 1028
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN   
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,20, @cnt, 4,@ena,'')    -- ALARM_FIBER_FEF_ON(20), SEVERITY_MINOR(4) 
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)
END

----- CARD_FMC_100I(1029)
SET @dvc = 1029
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN   
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,20, @cnt, 4,@ena,'')    -- ALARM_FIBER_FEF_ON(20), SEVERITY_MINOR(4) 
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)
END

GO


DECLARE @cnt INT  -- loop counter
DECLARE @dvc INT  -- device type or card Id
DECLARE @sid INT
DECLARE @ena INT
	    
SET @sid = 0  -- 0 for local, not used so far (2014-0807), no model needs another template for remtoe. New template may need it some day.
SET @ena = 1  -- default 1 to enable alarm
    
----- DEVICE_FMUX160(34)
----- DEVICE_FMUX80(35)
----- DEVICE_FMUX1600(36)
----- DEVICE_FMUX800(37)
	SET @dvc = 34
	WHILE (@dvc <= 37)
	BEGIN
		IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
		BEGIN
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,1,  1, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,1,  2, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,25, 1, 4,@ena,'') -- ALARM_FIBER_BIT_ERROR(25), SEVERITY_MINOR(4)
			
			DECLARE @e1Num INT
			
			IF @dvc IN (34, 36)
				SET @e1Num = 16
			
			IF @dvc IN (35, 37)
				SET @e1Num = 8
			
			SET @cnt = 1
			WHILE (@cnt <= @e1Num) -- 8/16 E1
			BEGIN
				IF (@cnt <= 4)  -- 4 UTP
				BEGIN
					IF (@cnt <= 2)  -- 2 FIBER
					BEGIN
						INSERT INTO alarmTemplate VALUES(@dvc,@sid,15, @cnt, 3,@ena,'')    -- ALARM_FIBER_TX_FAIL(15), SEVERITY_MAJOR(3)
						INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
						INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
						INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
						INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
						INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)							
					END
				
					INSERT INTO alarmTemplate VALUES(@dvc,@sid,2, @cnt, 5,@ena,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
				END	
				
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,21, @cnt, 5,@ena,'') -- ALARM_E1Chan_RX_LOSS(21), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,22, @cnt, 4,@ena,'') -- ALARM_E1Chan_AIS_ON(22), SEVERITY_MINOR(4)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,23, @cnt, 3,@ena,'') -- ALARM_E1Chan_TX_FAIL(23), SEVERITY_MAJOR(3)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,24, @cnt, 7,@ena,'') -- ALARM_E1Chan_LOOPBACK_TEST(24), SEVERITY_TESTING(7)	
				
				SET @cnt = @cnt + 1
			END	
		END
		
		SET @dvc = @dvc + 1
	END
GO

-- EMS 2.75_01, table 'alarmTemplate', add new template iMUX4T/S, iMUX5T/S, iMUX8T/S, iMUX16T/S
DECLARE @cnt INT  -- loop counter
DECLARE @dvc INT  -- device type or card Id
DECLARE @sid INT
DECLARE @ena INT
	    
SET @sid = 0  -- 0 for local, not used so far (2014-0807), no model needs another template for remtoe. New template may need it some day.
SET @ena = 1  -- default 1 to enable alarm
    
----- CARD_4E1ET100T(1030)
----- CARD_4E1ET100S(1031)
----- CARD_5E1ET100T(1032)
----- CARD_5E1ET100S(1033)
	SET @dvc = 1030
	WHILE (@dvc <= 1033)
	BEGIN
		IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
		BEGIN
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, 1, 3,@ena,'') -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
			
			IF @dvc IN (1030, 1032) -- UTP
			BEGIN
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  1, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
			END
			
			IF @dvc IN (1031, 1033) -- FIBER
			BEGIN
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  1, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,26, 1, 5,@ena,'')    -- ALARM_FIBER_PORT_HAS_NO_OPTICAL_SIGNAL(26), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, 1, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, 1, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, 1, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)		
			END
			
			SET @cnt = 1
			DECLARE @e1Num INT
			
			IF @dvc IN (1030, 1031)
				SET @e1Num = 4
			
			IF @dvc IN (1032, 1033)
				SET @e1Num = 5
			
			WHILE (@cnt <= @e1Num)
			BEGIN
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,34, @cnt, 7,@ena,'') -- ALARM_E1_LOOPBACK_TEST(34), SEVERITY_TESTING(7)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,35, @cnt, 7,@ena,'') -- ALARM_E1_BERT_TEST(35), SEVERITY_TESTING(7)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,36, @cnt, 7,@ena,'') -- ALARM_E1_BERT_TEST_HAS_ERROR(36), SEVERITY_TESTING(7)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,32, @cnt, 4,@ena,'') -- ALARM_E1_SIGNAL_LOSS(32), SEVERITY_MINOR(4)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,33, @cnt, 4,@ena,'') -- ALARM_E1_SYNC_LOSS(33), SEVERITY_MINOR(4)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,28, @cnt, 5,@ena,'') -- ALARM_E1_AIS_ON(28), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,29, @cnt, 5,@ena,'') -- ALARM_E1_RAI_ON(29), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,30, @cnt, 5,@ena,'') -- ALARM_E1_LOMF_ON(30), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,31, @cnt, 5,@ena,'') -- ALARM_E1_DEFECTED(31), SEVERITY_WARNING(5)
			
				SET @cnt = @cnt + 1
			END
		END
		
		SET @dvc = @dvc + 1
	END
	
GO

DECLARE @cnt INT  -- loop counter
DECLARE @dvc INT  -- device type or card Id
DECLARE @sid INT
DECLARE @ena INT
	    
SET @sid = 0  -- 0 for local, not used so far (2014-0807), no model needs another template for remtoe. New template may need it some day.
SET @ena = 1  -- default 1 to enable alarm
    
----- CARD_8E1ET100T(1034)
----- CARD_8E1ET100S(1035)
	SET @dvc = 1034
	WHILE (@dvc <= 1035)
	BEGIN
		IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
		BEGIN
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, 1, 3,@ena,'') -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
			
			IF @dvc = 1034 -- UTP
			BEGIN
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  1, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
			END
			
			IF @dvc = 1035 -- FIBER
			BEGIN
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  1, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,26, 1, 5,@ena,'')    -- ALARM_FIBER_PORT_HAS_NO_OPTICAL_SIGNAL(26), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, 1, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, 1, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, 1, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)		
			END
			
			SET @cnt = 1
			DECLARE @e1Num INT
			SET @e1Num = 8
			
			WHILE (@cnt <= @e1Num)
			BEGIN
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,34, @cnt, 7,@ena,'') -- ALARM_E1_LOOPBACK_TEST(34), SEVERITY_TESTING(7)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,35, @cnt, 7,@ena,'') -- ALARM_E1_BERT_TEST(35), SEVERITY_TESTING(7)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,36, @cnt, 7,@ena,'') -- ALARM_E1_BERT_TEST_HAS_ERROR(36), SEVERITY_TESTING(7)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,32, @cnt, 4,@ena,'') -- ALARM_E1_SIGNAL_LOSS(32), SEVERITY_MINOR(4)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,33, @cnt, 4,@ena,'') -- ALARM_E1_SYNC_LOSS(33), SEVERITY_MINOR(4)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,28, @cnt, 5,@ena,'') -- ALARM_E1_AIS_ON(28), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,29, @cnt, 5,@ena,'') -- ALARM_E1_RAI_ON(29), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,30, @cnt, 5,@ena,'') -- ALARM_E1_LOMF_ON(30), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,31, @cnt, 5,@ena,'') -- ALARM_E1_DEFECTED(31), SEVERITY_WARNING(5)
			
				SET @cnt = @cnt + 1
			END
		END
		
		SET @dvc = @dvc + 1
	END
	
GO

DECLARE @cnt INT  -- loop counter
DECLARE @dvc INT  -- device type or card Id
DECLARE @sid INT
DECLARE @ena INT
	    
SET @sid = 0  -- 0 for local, not used so far (2014-0807), no model needs another template for remtoe. New template may need it some day.
SET @ena = 1  -- default 1 to enable alarm
    
----- CARD_16E1ET100T(1036)
----- CARD_16E1ET100S(1037)
	SET @dvc = 1036
	WHILE (@dvc <= 1037)
	BEGIN
		IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
		BEGIN
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, 1, 3,@ena,'') -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
			
			IF @dvc = 1036 -- UTP
			BEGIN
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  1, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
			END
			
			IF @dvc = 1037 -- FIBER
			BEGIN
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  1, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,26, 1, 5,@ena,'')    -- ALARM_FIBER_PORT_HAS_NO_OPTICAL_SIGNAL(26), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, 1, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, 1, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, 1, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)		
			END
			
			SET @cnt = 1
			DECLARE @e1Num INT
			SET @e1Num = 16
			
			WHILE (@cnt <= @e1Num)
			BEGIN
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,34, @cnt, 7,@ena,'') -- ALARM_E1_LOOPBACK_TEST(34), SEVERITY_TESTING(7)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,35, @cnt, 7,@ena,'') -- ALARM_E1_BERT_TEST(35), SEVERITY_TESTING(7)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,36, @cnt, 7,@ena,'') -- ALARM_E1_BERT_TEST_HAS_ERROR(36), SEVERITY_TESTING(7)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,32, @cnt, 4,@ena,'') -- ALARM_E1_SIGNAL_LOSS(32), SEVERITY_MINOR(4)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,33, @cnt, 4,@ena,'') -- ALARM_E1_SYNC_LOSS(33), SEVERITY_MINOR(4)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,28, @cnt, 5,@ena,'') -- ALARM_E1_AIS_ON(28), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,29, @cnt, 5,@ena,'') -- ALARM_E1_RAI_ON(29), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,30, @cnt, 5,@ena,'') -- ALARM_E1_LOMF_ON(30), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,31, @cnt, 5,@ena,'') -- ALARM_E1_DEFECTED(31), SEVERITY_WARNING(5)
			
				SET @cnt = @cnt + 1
			END
		END
		
		SET @dvc = @dvc + 1
	END
	
GO

-- EMS 2.75_01, table 'alarmTemplate', add new template 1000T(S)
DECLARE @cnt INT  -- loop counter
DECLARE @dvc INT  -- device type or card Id
DECLARE @sid INT
DECLARE @ena INT
	    
SET @sid = 0  -- 0 for local, not used so far (2014-0807), no model needs another template for remtoe. New template may need it some day.
SET @ena = 1  -- default 1 to enable alarm
    
----- CARD_1000T(1038)
SET @dvc = 1038
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
END

----- CARD_1000TS(1039)
SET @dvc = 1039
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)
END

GO

----- EMS 2.75_01, add new alarm template FTEC
DECLARE @cnt INT  -- loop counter
DECLARE @dvc INT  -- model Id
DECLARE @sid INT
DECLARE @ena INT
	    
SET @sid = 0  -- 0 for local, not used so far (2014-0925), no model needs another template for remtoe. New template may need it some day.
SET @ena = 1  -- default 1 to enable alarm
    
----- MODEL_FTEC(1040)
	SET @dvc = 1040
	IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,32, 1, 4,@ena,'') -- ALARM_E1_SIGNAL_LOSS(32), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,33, 1, 4,@ena,'') -- ALARM_E1_SYNC_LOSS(33), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,27, 1, 5,@ena,'') -- ALARM_E1_ALARM_ON(27), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,28, 1, 5,@ena,'') -- ALARM_E1_AIS_ON(28), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,34, 1, 7,@ena,'') -- ALARM_E1_LOOPBACK_TEST(34), SEVERITY_TESTING(7)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,37, 1, 4,@ena,'') -- ALARM_T1_SIGNAL_LOSS(37), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,38, 1, 4,@ena,'') -- ALARM_T1_SYNC_LOSS(38), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,39, 1, 5,@ena,'') -- ALARM_T1_ALARM_ON(39), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,40, 1, 5,@ena,'') -- ALARM_T1_AIS_ON(40), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,41, 1, 7,@ena,'') -- ALARM_T1_LOOPBACK_TEST(41), SEVERITY_TESTING(7)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,42, 1, 7,@ena,'') -- ALARM_FRONT_LOOPBACK_TEST(42), SEVERITY_TESTING(7)	
	END
GO

-- EMS 2.75_01, add new alarm template FXOFXS
-- EMS 2.75_01, add new alarm template FXOFXS4
DECLARE @cnt INT  -- loop counter
DECLARE @dvc INT  -- model Id
DECLARE @sid INT
DECLARE @ena INT
	    
SET @sid = 0  -- 0 for local, not used so far (2014-0925), no model needs another template for remtoe. New template may need it some day.
SET @ena = 1  -- default 1 to enable alarm
    
----- MODEL_FXOFXS(1041)
----- MODEL_FXOFXS4(1042)
SET @dvc = 1041
	
WHILE (@dvc <= 1042)
BEGIN
	IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  1, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,20, 1, 4,@ena,'')    -- ALARM_FIBER_FEF_ON(20), SEVERITY_MINOR(4)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, 1, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, 1, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, 1, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)
	END
	
	SET @dvc = @dvc + 1
END
GO

-- EMS 2.75_01, add new alarm templates for FRM220A-1000EAS/X, FRM220A-1000EAS/X-1, FRM220-100AS-1, FRM220-1000EAS/X-2F
DECLARE @cnt INT  -- loop counter
DECLARE @dvc INT  -- model Id
DECLARE @sid INT
DECLARE @ena INT
	    
SET @sid = 0  -- 0 for local, not used so far (2014-0925), no model needs another template for remtoe. New template may need it some day.
SET @ena = 1  -- default 1 to enable alarm

----- DEVICE_FRM220A_1000EASX(42)
SET @dvc = 42
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 2) -- 2 FIBER, 2 UTP
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,20, @cnt, 4,@ena,'')    -- ALARM_FIBER_FEF_ON(20), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
						
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END		        
END

----- DEVICE_FRM220A_1000EASX1(45)
SET @dvc = 45
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,20, @cnt, 4,@ena,'')    -- ALARM_FIBER_FEF_ON(20), SEVERITY_MINOR(4)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
						
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)		        
END

----- DEVICE_FRM220_100AS1(80)
SET @dvc = 80
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,20, @cnt, 4,@ena,'')    -- ALARM_FIBER_FEF_ON(20), SEVERITY_MINOR(4)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
						
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)		        
END

----- DEVICE_FRM220_1000EASX2F(81)
SET @dvc = 81
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 2) -- 2 FIBER, 0 UTP
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, @cnt, 3,@ena,'')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,20, @cnt, 4,@ena,'')    -- ALARM_FIBER_FEF_ON(20), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, @cnt, 7,@ena,'')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
						
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
		
		SET @cnt = @cnt + 1
	END		        
END

GO

-- EMS 2.75_01, add new alarm template GFOM04
DECLARE @cnt INT  -- loop counter
DECLARE @dvc INT  -- model Id
DECLARE @sid INT
DECLARE @ena INT
	    
SET @sid = 0  -- 0 for local, not used so far (2014-0925), no model needs another template for remtoe. New template may need it some day.
SET @ena = 1  -- default 1 to enable alarm

----- MODEL_GFOM04(1043)
SET @dvc = 1043
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,10, 1, 3,@ena,'') -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,20, 1, 4,@ena,'') -- ALARM_FIBER_FEF_ON(20), SEVERITY_MINOR(4)	
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,25, 1, 4,@ena,'') -- ALARM_FIBER_BIT_ERROR(25), SEVERITY_MINOR(4)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,11, 1, 7,@ena,'') -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)			
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,2,  1, 5,@ena,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
			
	DECLARE @e1Num INT
	SET @e1Num = 4
			
	SET @cnt = 1
	WHILE (@cnt <= @e1Num) -- 4 E1/T1
	BEGIN
		IF (@cnt <= 2)  -- 2 FIBER
		BEGIN
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,15, @cnt, 3,@ena,'')    -- ALARM_FIBER_TX_FAIL(15), SEVERITY_MAJOR(3)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)							
		END
				
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,21, @cnt, 5,@ena,'') -- ALARM_E1Chan_RX_LOSS(21), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,22, @cnt, 4,@ena,'') -- ALARM_E1Chan_AIS_ON(22), SEVERITY_MINOR(4)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,23, @cnt, 3,@ena,'') -- ALARM_E1Chan_TX_FAIL(23), SEVERITY_MAJOR(3)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,24, @cnt, 7,@ena,'') -- ALARM_E1Chan_LOOPBACK_TEST(24), SEVERITY_TESTING(7)	
				
		SET @cnt = @cnt + 1
	END	
END

GO

-- EMS 2.75_01, add new alarm template IPS-803
DECLARE @cnt INT  -- loop counter
DECLARE @dvc INT  -- device type or card Id
DECLARE @sid INT
DECLARE @ena INT
	    
SET @sid = 0  -- 0 for local, not used so far (2014-0807), no model needs another template for remtoe. New template may need it some day.
SET @ena = 1  -- default 1 to enable alarm
    
----- DEVICE_IPS803(78)
SET @dvc = 78
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 1, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 2, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 3, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,4, 1, 4,@ena,'') -- ALARM_FAULT_ON(4), SEVERITY_MINOR(4)    
    
	WHILE (@cnt <= 8) -- 8 UTP
	BEGIN		
		IF (@cnt <= 5) -- 5 Ring
		BEGIN
			IF (@cnt <= 3)  -- 3 FIBER
			BEGIN
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)        
			END
		
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,7, @cnt, 4,@ena,'') -- ALARM_RING_FAULT(7), SEVERITY_MINOR(4)        
		END	
			
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2, @cnt, 5,@ena,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)        
		
		SET @cnt = @cnt + 1
	END
END

-- EMS 2.86_01, add new alarm template IGS-804
----- DEVICE_IGS804(79)
SET @dvc = 79
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 1, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,1, 2, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,4, 1, 4,@ena,'') -- ALARM_FAULT_ON(4), SEVERITY_MINOR(4)    
    
	WHILE (@cnt <= 8) -- 8 UTP
	BEGIN		
		IF (@cnt <= 5) -- 5 Ring
		BEGIN
			IF (@cnt <= 4)  -- 4 FIBER
			BEGIN
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,13, @cnt, 3,@ena,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,12, @cnt, 4,@ena,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
				INSERT INTO alarmTemplate VALUES(@dvc,@sid,14, @cnt, 4,@ena,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)        
			END
		
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,7, @cnt, 4,@ena,'') -- ALARM_RING_FAULT(7), SEVERITY_MINOR(4)        
		END	
			
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,2, @cnt, 5,@ena,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)        
		-- IGS-804 has no PoE
		
		SET @cnt = @cnt + 1
	END
END


GO

