
-- 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

----- EMS 2.88_01, table 'clientActionClassify', add id 1~6
----- EMS 2.88_01, table 'clientActionCode', add id 101~604
----- EMS 2.88_01, table 'clientActionContentCode', add id 1~19

----- EMS 2.88_01, modify table 'sysProperty', add syslog parameters 'Login', 'Logout', 'Configure Param'
----- EMS 2.88_01, modify table 'sysProperty', add disk usage parameter
----- EMS 2.88_01, modify table 'sysProperty', add user idle parameter 

----- EMS 2.88_01, table 'pmParamErrCode', add id 0~3
----- EMS 2.88_01, table 'pmParamDataType', add id 0~7

----- EMS 2.88_01, modify table 'nodes', add record for new model FRM220R4
----- EMS 2.88_01, modify table 'treelinks', add record for new model FRM220R4

----- EMS 2.88_01, modify table 'alarmType', add new type 43~47
----- EMS 2.88_01, modify table 'alarmType', add new type 50,51,52
----- EMS 2.88_01, modify table 'alarmType', add new type 53,54,55
----- EMS 2.88_01, modify table 'alarmType', rename type 26 to 'Signal Loss'
----- EMS 2.88_01, add new alarm template NMC-R4
----- EMS 2.88_01, add new alarm template for NMC-R4 line card 12G-3R
----- EMS 2.88_01, add new alarm template for NMC-R4 line card Protection

----- EMS 2.90_01, modify table 'nodes', add record for new model MSW404
----- EMS 2.90_01, modify table 'nodes', add record for new model ICSG24S4X
----- EMS 2.90_01, modify table 'nodes', add record for new model ICSG24S2X
----- EMS 2.90_01, modify table 'nodes', add record for new model IGS-S2804TM
----- EMS 2.90_01, modify table 'nodes', add record for new model MSW4424A

----- EMS 2.90_01, modify table 'treelinks', add record for new model MSW404
----- EMS 2.90_01, modify table 'treelinks', add record for new model ICSG24S4X
----- EMS 2.90_01, modify table 'treelinks', add record for new model ICSG24S2X
----- EMS 2.90_01, modify table 'treelinks', add record for new model IGS-S2804TM
----- EMS 2.90_01, modify table 'treelinks', add record for new model MSW4424A

-- EMS 2.90_01, add new alarm template MSW404
-- EMS 2.90_01, add new alarm template MSW4424A
-- EMS 2.90_01, add new alarm template ICSG24S4X
-- EMS 2.90_01, add new alarm template ICSG24S2X
-- EMS 2.90_01, add new alarm template IGS-S2804TM

----- EMS 2.90_01, modify table 'alarmType', add new type 49
----- EMS 2.90_01, modify table 'sysProperty', add ntpServerAddress paramaters


----- EMS 2.91_01, modify table 'nodes', add record for new model GSW3208M2
----- EMS 2.91_01, modify table 'treelinks', add record for new model GSW3208M2
----- EMS 2.91_01, add new alarm template GSW3208M2

----- EMS 2.92_01, modify table 'nodes', add record for new model GSW1005MS
----- EMS 2.92_01, modify table 'treelinks', add record for new model GSW1005MS
----- EMS 2.92_01, add new alarm template GSW1005MS
----- EMS 2.92_01, modify table 'alarmType', add type 56,57
----- EMS 2.92_01, modify table 'alarmType', rename type 11-17,19 to add 'Fiber' description
----- EMS 2.92_01, modify table 'alarmTemplate', add FRM220A template type 56,57

----- EMS 2.93_01, modify table 'clientACL', add empty ip/mac for users not in white list
----- EMS 2.94_01, modify table 'timeSynchornizer', add rows disable/ntp/ems

----- EMS 2.99_01, modify table 'alarmType', add type 58 to 64
----- EMS 2.99_01, add new alarm template NMC-R3 line card Eoe1/GS
----- EMS 2.99_01, add new alarm template for NMC-R3 line card OPS51
----- EMS 2.99_01, modify table 'nodes', add record for new model MSW4424C
----- EMS 2.99_01, modify table 'treelinks', add record for new model MSW4424C
----- EMS 2.99_01, add new alarm template MSW4424C
----- EMS 2.99_01, add new alarm template for NMC-R3 line card FMC1000MS

-- EMS 2.100_01, table 'sysProperty', add 'trapDeviceAlarm'
-- EMS 2.100_01, table 'alarmType', add type 65    
-- EMS 2.100_01, table 'alarmTemplate', add NMC-R4 template type 65

-- EMS 2.101, table 'alarmType', add type 66  
-- EMS 2.101, table 'alarmTemplate', add id 1055 FRM220-OAB15 template.

-- EMS 2.102, table 'nodes', add IGS-1608SM-8PH
-- EMS 2.102, table 'nodes', add IFS-1608GSM-8PH
-- EMS 2.102, table 'nodes', add IGS-1608SM-SE
-- EMS 2.102, table 'treelinks', add IGS-1608SM-8PH
-- EMS 2.102, table 'treelinks', add IFS-1608GSM-8PH
-- EMS 2.102, table 'treelinks', add IGS-1608SM-SE
-- EMS 2.102, table 'alarmTemplate', add IGS-1608SM-8PH
-- EMS 2.102, table 'alarmTemplate', add IFS-1608GSM-8PH
-- EMS 2.102, table 'alarmTemplate', add IGS-1608SM-SE

-- EMS 2.200, remove data for table 'clientlogact'

-- EMS 3.004, table 'nodes', add GSW-3424FM
-- EMS 3.004, table 'treelinks', add GSW-3424FM
-- EMS 3.004, table 'alarmTemplate', add GSW-3424FM
-- EMS 3.004, table 'userRole', add column 'radius_id' setting

-- EMS 3.005, table 'alarmTemplate', add id 1056 FRM220-E1/DATA template.

-- EMS 3.007, table 'nodes', add MSW-4428X
-- EMS 3.007, table 'treelinks', add MSW-4428X
-- EMS 3.007, table 'alarmTemplate', add MSW-4428X

-- EMS 3.008, table 'nodes', add IWA-AR114
-- EMS 3.008, table 'treelinks', add IWA-AR114
-- EMS 3.008, table 'alarmTemplate', add MSW-4428X alarm type 8, 12, 13, 14
-- EMS 3.008, table 'alarmTemplate', add IWA-AR114

-- EMS 3.009.7, table 'sysProperty', add timeSyncInterval
-- EMS 3.009.7, table 'sysProperty', add timeSyncZone

-- EMS 3.014, table 'sysProperty', add timeMode
-- EMS 3.014, table 'sysProperty', remove timeSyncInterval
-- EMS 3.014, table 'sysProperty', rename timeSyncZone to timeZone
-- EMS 3.014, table 'sysProperty', rename ntpServerAddress to timeNtpAddress
-- EMS 3.014, table 'alarmTemplate', add MSW4424A alarm type 1, 8

-- EMS 3.015, table 'nodes', add IACCESS
-- EMS 3.015, table 'treelinks', add IACCESS
-- EMS 3.015, table 'alarmTemplate', add IACCESS
-- EMS 3.015, table 'alarmTemplate', add line card 12G TP
-- EMS 3.015, table 'alarmTemplate', add line card DMUX16SP
-- EMS 3.015, table 'alarmType', add type 67, 68   

-- EMS 3.016, table 'nodes', add FRM220A-N
-- EMS 3.016, table 'treelinks', add FRM220A-N
-- EMS 3.016, table 'alarmTemplate', add FRM220A-N

-- EMS 3.016.3, table 'alarmTemplate', add FRM220A-N alarm type 12, 13, 14, 56, 57

-- EMS 3.016.12, table 'sysProperty', add userSecure, userExpire, userAttempt, userLockout, userPassword
-- EMS 3.016.12, table 'client', add column 'modify', 'next', 'first', 'attempt', 'lock'
-- EMS 3.016.12, table 'sysProperty', rename userIdleLogoutEnable to userIdleEnable
-- EMS 3.016.12, table 'sysProperty', rename userIdleLogoutMinutes to userIdle

-- EMS 3.017, table 'userRole', remove column 'radius_id'

-- EMS 3.019, table 'sysProperty', add topologyDiscoverLink

-- EMS 3.020, table 'alarmTemplate', add FRM220 card GFOM08 

-- EMS 3.026, table 'nodes', add 2000EAS-4F
-- EMS 3.026, table 'treelinks', add 2000EAS-4F
-- EMS 3.026, table 'alarmTemplate', add 2000EAS-4F


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'
-- EMS 3.016.12, table 'client', add column 'modify', 'next', 'first', 'attempt', 'lock'
-----------------------------------------------------------------------------------------
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, modify, next, first, attempt, lock) 
    values('admin', '0000', '', 'IT Dep.', '', 'administrator', 0, GETDATE(), 0, 0, 0, '')
GO

-- EMS 2.81_01, table 'userRole', add column 'function'
-- EMS 3.004, table 'userRole', add column 'radius_id' setting
-- EMS 3.017, table 'userRole', remove column 'radius_id'
-----------------------------------------------------------------------------------------
PRINT '--- insert data to table userRole ---'

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

-- 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
----- EMS 2.88_01, modify table 'nodes', add record for new model FRM220R4
----- EMS 2.90_01, modify table 'nodes', add record for new model MSW404
----- EMS 2.90_01, modify table 'nodes', add record for new model ICSG24S4X
----- EMS 2.90_01, modify table 'nodes', add record for new model ICSG24S2X
----- EMS 2.90_01, modify table 'nodes', add record for new model IGS-S2804TM
----- EMS 2.90_01, modify table 'nodes', add record for new model MSW4424A
----- EMS 2.91_01, modify table 'nodes', add record for new model GSW3208M2
----- EMS 2.92_01, modify table 'nodes', add record for new model GSW1005MS
----- EMS 2.99_01, modify table 'nodes', add record for new model MSW4424C
-- EMS 2.102, table 'nodes', add IGS-1608SM-8PH
-- EMS 2.102, table 'nodes', add IFS-1608GSM-8PH
-- EMS 2.102, table 'nodes', add IGS-1608SM-SE
-- EMS 3.004, table 'nodes', add GSW-3424FM
-- EMS 3.007, table 'nodes', add MSW-4428X
-- EMS 3.008, table 'nodes', add IWA-AR114
-- EMS 3.015, table 'nodes', add IACCESS
-- EMS 3.016, table 'nodes', add FRM220A-N
-- EMS 3.026, table 'nodes', add 2000EAS-4F


-----------------------------------------------------------------------------------------
PRINT '--- insert data to table nodes ---'

/*
    id: 1-10 product series, 10000+ user nodes 
    type_id: 1:gerenic , 2:map
*/
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) 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-812SM',       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(   82, 'MSW4424C',            1,1)
insert into nodes(id,name,type_id,client_id) values(   83, 'FRM220-R4',           1,1)
insert into nodes(id,name,type_id,client_id) values(   84, 'MSW404',              1,1)
insert into nodes(id,name,type_id,client_id) values(   85, 'MSW4424A',            1,1)
insert into nodes(id,name,type_id,client_id) values(   86, 'GSW3208M2',           1,1)
insert into nodes(id,name,type_id,client_id) values(   87, 'GSW1005MS',           1,1)
insert into nodes(id,name,type_id,client_id) values(   93, 'ICS-G24S4X',		  1,1)
insert into nodes(id,name,type_id,client_id) values(   94, 'ICS-G24S2X',		  1,1)
insert into nodes(id,name,type_id,client_id) values(   95, 'IGS-S2804TM',		  1,1)
insert into nodes(id,name,type_id,client_id) values(   96, 'IGS-1608SM-8PH',	  1,1)
insert into nodes(id,name,type_id,client_id) values(   97, 'IFS-1608GSM-8PH',	  1,1)
insert into nodes(id,name,type_id,client_id) values(   98, 'IGS-1608SM-SE',	      1,1)
insert into nodes(id,name,type_id,client_id) values(   99, 'GSW-3424FM',	      1,1)
insert into nodes(id,name,type_id,client_id) values(  100, 'MSW-4428X',	          1,1)
insert into nodes(id,name,type_id,client_id) values(  101, 'IWA-AR114',	          1,1)
insert into nodes(id,name,type_id,client_id) values(  102, 'IACCESS',	          1,1)
insert into nodes(id,name,type_id,client_id) values(  103, 'FRM220A-N',	          1,1)
insert into nodes(id,name,type_id,client_id) values(  104, '2000EAS-4F',	      1,1)
--insert into nodes (id,name,type_id,client_id,acl) values(10000, 'user_node',      1,1,1)	-- user nodes from here
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
----- EMS 2.88_01, modify table 'treelinks', add record for new model FRM220R4
----- EMS 2.90_01, modify table 'treelinks', add record for new model MSW404
----- EMS 2.90_01, modify table 'treelinks', add record for new model ICSG24S4X
----- EMS 2.90_01, modify table 'treelinks', add record for new model ICSG24S2X
----- EMS 2.90_01, modify table 'treelinks', add record for new model IGS-S2804TM
----- EMS 2.90_01, modify table 'treelinks', add record for new model MSW4424A
----- EMS 2.91_01, modify table 'treelinks', add record for new model GSW3208M2
----- EMS 2.92_01, modify table 'treelinks', add record for new model GSW1005MS
----- EMS 2.99_01, modify table 'treelinks', add record for new model MSW4424C
-- EMS 2.102, table 'treelinks', add IGS-1608SM-8PH
-- EMS 2.102, table 'treelinks', add IFS-1608GSM-8PH
-- EMS 2.102, table 'treelinks', add IGS-1608SM-SE
-- EMS 3.004, table 'treelinks', add GSW-3424FM
-- EMS 3.007, table 'treelinks', add MSW-4428X
-- EMS 3.008, table 'treelinks', add IWA-AR114
-- EMS 3.015, table 'treelinks', add IACCESS
-- EMS 3.016, table 'treelinks', add FRM220A-N
-- EMS 3.026, table 'treelinks', add 2000EAS-4F

-----------------------------------------------------------------------------------------
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,  4,  83, 12, 2) -- FRM220-R4
insert into treelinks(tree_id,parent_id,child_id,idx,lvl) values(1,  4,  84, 13, 2)
insert into treelinks(tree_id,parent_id,child_id,idx,lvl) values(1,  4,  85, 14, 2)
insert into treelinks(tree_id,parent_id,child_id,idx,lvl) values(1,  4,  86, 15, 2) -- GSW-3208M2
insert into treelinks(tree_id,parent_id,child_id,idx,lvl) values(1,  4,  87, 16, 2) -- GSW-1005MS
insert into treelinks(tree_id,parent_id,child_id,idx,lvl) values(1,  4,  82, 17, 2) -- MSW-4424C
insert into treelinks(tree_id,parent_id,child_id,idx,lvl) values(1,  4,  99, 18, 2) -- GSW-3424FM
insert into treelinks(tree_id,parent_id,child_id,idx,lvl) values(1,  4, 100, 19, 2) -- GSW-4428X
insert into treelinks(tree_id,parent_id,child_id,idx,lvl) values(1,  4, 102, 20, 2) -- IACCESS
insert into treelinks(tree_id,parent_id,child_id,idx,lvl) values(1,  4, 103, 21, 2) -- FRM220A-N
insert into treelinks(tree_id,parent_id,child_id,idx,lvl) values(1,  4, 104, 22, 2) -- 2000EAS-4F
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
insert into treelinks(tree_id,parent_id,child_id,idx,lvl) values(1,  7,  93,  9, 2)
insert into treelinks(tree_id,parent_id,child_id,idx,lvl) values(1,  7,  94, 10, 2)
insert into treelinks(tree_id,parent_id,child_id,idx,lvl) values(1,  7,  95, 11, 2)
insert into treelinks(tree_id,parent_id,child_id,idx,lvl) values(1,  7,  96, 12, 2) -- IGS-1608SM-8PH
insert into treelinks(tree_id,parent_id,child_id,idx,lvl) values(1,  7,  97, 13, 2) -- IFS-1608GSM-8PH
insert into treelinks(tree_id,parent_id,child_id,idx,lvl) values(1,  7,  98, 14, 2) -- IGS-1608SM-SE
insert into treelinks(tree_id,parent_id,child_id,idx,lvl) values(1,  7, 101, 15, 2) -- IWA-AR114

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

----- EMS 2.88_01, modify table 'alarmType', add new type 43~47
----- EMS 2.88_01, modify table 'alarmType', add new type 50,51,52
----- EMS 2.88_01, modify table 'alarmType', add new type 53,54,55
----- EMS 2.88_01, modify table 'alarmType', rename type 26 to 'Signal Loss'
----- EMS 2.90_01, modify table 'alarmType', add new type 49
----- EMS 2.92_01, modify table 'alarmType', add type 56,57
----- EMS 2.92_01, modify table 'alarmType', rename type 11-17,19 to add 'Fiber' description
----- EMS 2.99_01, modify table 'alarmType', add type 58 to 64
-- EMS 2.100_01, table 'alarmType', add type 65       
-- EMS 2.101, table 'alarmType', add type 66    
-- EMS 3.015, table 'alarmType', add type 67, 68   
-----------------------------------------------------------------------------------------
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, 'Signal Loss') ----- EMS 2.88_01, modify table 'alarmType', rename type 26 to 'Signal Loss'
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')
INSERT INTO alarmType (id, name) VALUES (43, 'Fiber CV Abnormal')    
INSERT INTO alarmType (id, name) VALUES (44, 'Fiber ES Abnormal')    
INSERT INTO alarmType (id, name) VALUES (45, 'Fiber SES Abnormal')    
INSERT INTO alarmType (id, name) VALUES (46, 'Fiber UAS Abnormal')    
INSERT INTO alarmType (id, name) VALUES (47, 'All Slots Link Down')
INSERT INTO alarmType (id, name) VALUES (49, 'Port Link Down')        
INSERT INTO alarmType (id, name) VALUES (50, 'Working path (primary channel) signal loss')    
INSERT INTO alarmType (id, name) VALUES (51, 'Working path (secondary channel) signal loss')    
INSERT INTO alarmType (id, name) VALUES (52, 'Both channels signal loss') 
INSERT INTO alarmType (id, name) VALUES (53, 'Working path signal loss')    
INSERT INTO alarmType (id, name) VALUES (54, 'Primary channel signal loss')    
INSERT INTO alarmType (id, name) VALUES (55, 'Secondary channel signal loss')            
INSERT INTO alarmType (id, name) VALUES (56, 'CPU Temperature Abnormal')
INSERT INTO alarmType (id, name) VALUES (57, 'Board Temperature Abnormal')
INSERT INTO alarmType (id, name) VALUES (58, 'Loopback Test')
INSERT INTO alarmType (id, name) VALUES (59, 'BERT Test')
INSERT INTO alarmType (id, name) VALUES (60, 'BERT Test Has Error')
INSERT INTO alarmType (id, name) VALUES (61, 'E1 CRC ON')
INSERT INTO alarmType (id, name) VALUES (62, 'E1 BPV ON')
INSERT INTO alarmType (id, name) VALUES (63, 'E1 LOS')
INSERT INTO alarmType (id, name) VALUES (64, 'E1 LOF')
INSERT INTO alarmType (id, name) VALUES (65, 'Card Unplug')    
INSERT INTO alarmType (id, name) VALUES (66, 'Pump Inactive')    
INSERT INTO alarmType (id, name) VALUES (67, 'Fiber Signal Loss')  
INSERT INTO alarmType (id, name) VALUES (68, 'Fiber CDR Unlock')  
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
-- EMS 2.88_01, modify table 'sysProperty', add disk usage parameter
-- EMS 2.88_01, modify table 'sysProperty', add user idle parameter 
-- EMS 2.90_01, modify table 'sysProperty', add ntpServerAddress paramaters
-- EMS 2.100_01, table 'sysProperty', add 'trapDeviceAlarm'
-- EMS 3.009.7, table 'sysProperty', add timeSyncInterval 
-- EMS 3.009.7, table 'sysProperty', add timeSyncZone
-- EMS 3.014, table 'sysProperty', add timeMode
-- EMS 3.014, table 'sysProperty', remove timeSyncInterval
-- EMS 3.014, table 'sysProperty', rename timeSyncZone to timeZone
-- EMS 3.014, table 'sysProperty', rename ntpServerAddress to timeNtpAddress
-- EMS 3.016.12, table 'sysProperty', add userSecure, userExpire, userAttempt, userLockout, userPassword
-- EMS 3.016.12, table 'sysProperty', rename userIdleLogoutEnable to userIdleEnable
-- EMS 3.016.12, table 'sysProperty', rename userIdleLogoutMinutes to userIdle
-- EMS 3.019, table 'sysProperty', add topologyDiscoverLink
-----------------------------------------------------------------------------------------
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 ('diskUsageWarn',     '80')
INSERT INTO [sysProperty] ([name], [value]) VALUES ('diskUsageStop',     '99')
INSERT INTO [sysProperty] ([name], [value]) VALUES ('diskUsageStopAutoRestart', '0') 
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 ('timeMode',          '1') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('timeNtpAddress',    '211.22.103.158')
INSERT INTO [sysProperty] ([name], [value]) VALUES ('timeZone',          '0') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('topologyLock',      '0') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('topologyName',      '1') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('topologyDiscoverLink', '0') 
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 ('trapDeviceAlarm',   '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') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('userAttempt', '5') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('userExpire', '90') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('userIdle', '30') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('userIdleEnable', '1') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('userLockout', '30') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('userPassword', '0') 
INSERT INTO [sysProperty] ([name], [value]) VALUES ('userSecure', '0') 
GO

----- EMS 2.88_01, modify table 'sysProperty', add syslog parameters 'Login', 'Logout', 'Configure Param'
DECLARE @oldUserEnable varchar(4),@oldUserFac varchar(4),@oldUserSev varchar(4),
		@oldActEnable varchar(4),@oldActFac varchar(4),@oldActSev varchar(4) 
SET @oldUserEnable = '0' 
SET @oldUserFac    = '4' 
SET @oldUserSev    = '5' 
SET @oldActEnable  = '0' 
SET @oldActFac     = '10' 
SET @oldActSev     = '5' 

IF EXISTS (SELECT * FROM [dbo].[sysProperty] WHERE [name]='syslogUserLog') 
BEGIN
	SET @oldUserEnable = (SELECT value FROM sysProperty WHERE name='syslogUserLog') 
	SET @oldUserFac    = (SELECT value FROM sysProperty WHERE name='syslogFacUser')
	SET @oldUserSev    = (SELECT value FROM sysProperty WHERE name='syslogSevUser')
	SET @oldActEnable  = (SELECT value FROM sysProperty WHERE name='syslogActionLog') 
	SET @oldActFac     = (SELECT value FROM sysProperty WHERE name='syslogFacAction')
	SET @oldActSev     = (SELECT value FROM sysProperty WHERE name='syslogSevAction')
	
	DELETE FROM sysProperty WHERE name='syslogUserLog' 
	DELETE FROM sysProperty WHERE name='syslogFacUser' 
	DELETE FROM sysProperty WHERE name='syslogSevUser' 
	DELETE FROM sysProperty WHERE name='syslogActionLog' 
	DELETE FROM sysProperty WHERE name='syslogFacAction' 
	DELETE FROM sysProperty WHERE name='syslogSevAction' 
END
	
-- enable or not
IF NOT EXISTS (SELECT * FROM [dbo].[sysProperty] WHERE [name]='syslogLogin')   
    INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogLogin', @oldUserEnable)
    
IF NOT EXISTS (SELECT * FROM [dbo].[sysProperty] WHERE [name]='syslogLogout')   
    INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogLogout', @oldUserEnable)

IF NOT EXISTS (SELECT * FROM [dbo].[sysProperty] WHERE [name]='syslogConfigParam')   
    INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogConfigParam', @oldActEnable)

-- facility
IF NOT EXISTS (SELECT * FROM [dbo].[sysProperty] WHERE [name]='syslogFacLogin')   
    INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogFacLogin', @oldUserFac)

IF NOT EXISTS (SELECT * FROM [dbo].[sysProperty] WHERE [name]='syslogFacLogout')   
    INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogFacLogout', @oldUserFac)

IF NOT EXISTS (SELECT * FROM [dbo].[sysProperty] WHERE [name]='syslogFacConfigParam')   
    INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogFacConfigParam', @oldActFac)  

-- severity
IF NOT EXISTS (SELECT * FROM [dbo].[sysProperty] WHERE [name]='syslogSevLogin')   
    INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogSevLogin', @oldUserSev)

IF NOT EXISTS (SELECT * FROM [dbo].[sysProperty] WHERE [name]='syslogSevLogout')   
    INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogSevLogout', @oldUserSev)

IF NOT EXISTS (SELECT * FROM [dbo].[sysProperty] WHERE [name]='syslogSevConfigParam')   
    INSERT INTO [sysProperty] ([name], [value]) VALUES ('syslogSevConfigParam', @oldActSev)  
    
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

----- EMS 2.92_01, modify table 'alarmTemplate', add FRM220A template type 56,57
----- 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	
	
	SET @cnt = 1
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,56, @cnt, 4,@ena,'') -- ALARM_CPU_TEMPERATURE_ABNORMAL(56), SEVERITY_MINOR(4)
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,57, @cnt, 4,@ena,'') -- ALARM_BOARD_TEMPERATURE_ABNORMAL(57), SEVERITY_MINOR(4)
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
	END
		
	SET @dvc = @dvc + 1
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

----- EMS 2.88_01, table 'clientActionClassify', add id 1~6
----- EMS 2.88_01, table 'clientActionCode', add id 101~604
----- EMS 2.88_01, table 'clientActionContentCode', add id 1~19

-- insert action classification
INSERT INTO clientActionClassify VALUES (1,'Login')
INSERT INTO clientActionClassify VALUES (2,'Logout')
INSERT INTO clientActionClassify VALUES (3,'By Role Function System')
INSERT INTO clientActionClassify VALUES (4,'By Role Function Network')
INSERT INTO clientActionClassify VALUES (5,'By Role Function Device')
INSERT INTO clientActionClassify VALUES (6,'By Role Function Alarm')

-- insert action code
-- login
INSERT INTO clientActionCode VALUES (101,'Client Login')
INSERT INTO clientActionCode VALUES (102,'Login Failed, Wrong Username or Password')
INSERT INTO clientActionCode VALUES (103,'Login Failed, ACL Match Failed')

-- logout
INSERT INTO clientActionCode VALUES (201,'Client Logout')
INSERT INTO clientActionCode VALUES (202,'Idle Logout')
INSERT INTO clientActionCode VALUES (203,'Loss Connect')
INSERT INTO clientActionCode VALUES (204,'Force Logout, ACL Match Failed')

-- by role function system
INSERT INTO clientActionCode VALUES (301,'Edit Inventory')
INSERT INTO clientActionCode VALUES (302,'Delete Inventory')
INSERT INTO clientActionCode VALUES (303,'Check Duplicated SN')
INSERT INTO clientActionCode VALUES (304,'PM Setting')
INSERT INTO clientActionCode VALUES (305,'Enable Device PM')
INSERT INTO clientActionCode VALUES (306,'Disable Device PM')
    
-- by role function network
INSERT INTO clientActionCode VALUES (401,'Add Tree') 
INSERT INTO clientActionCode VALUES (402,'Add Node') 
INSERT INTO clientActionCode VALUES (403,'Delete Node') 
INSERT INTO clientActionCode VALUES (404,'Move Node Up') 
INSERT INTO clientActionCode VALUES (405,'Move Node Down') 
INSERT INTO clientActionCode VALUES (406,'Edit Name') 
INSERT INTO clientActionCode VALUES (407,'Edit Role Access') 
INSERT INTO clientActionCode VALUES (408,'Edit Alias') 
INSERT INTO clientActionCode VALUES (409,'Topology Add Device Link') 
INSERT INTO clientActionCode VALUES (410,'Topology Add Equip Link') 
INSERT INTO clientActionCode VALUES (411,'Topology Edit Device Link') 
INSERT INTO clientActionCode VALUES (412,'Topology Edit Equip Link') 
INSERT INTO clientActionCode VALUES (413,'Topology Delete Device Link') 
INSERT INTO clientActionCode VALUES (414,'Topology Delete Equip Link') 
INSERT INTO clientActionCode VALUES (415,'Topology Map Setting') 
INSERT INTO clientActionCode VALUES (416,'Topology Add Image') 
INSERT INTO clientActionCode VALUES (417,'Topology Delete Image') 
INSERT INTO clientActionCode VALUES (418,'Topology Import Image') 
INSERT INTO clientActionCode VALUES (419,'Topology Map Scale') 
INSERT INTO clientActionCode VALUES (420,'Topology Add Node') 
INSERT INTO clientActionCode VALUES (421,'Topology Delete Node') 
INSERT INTO clientActionCode VALUES (422,'Topology Drag Location Node')
INSERT INTO clientActionCode VALUES (423,'Topology Drag Device Node') 
INSERT INTO clientActionCode VALUES (424,'Topology Drag Equip Node') 
INSERT INTO clientActionCode VALUES (425,'Topology Location Node Icon')
INSERT INTO clientActionCode VALUES (426,'Topology Device Node Icon') 
INSERT INTO clientActionCode VALUES (427,'Topology Equip Node Icon') 

-- by role function device
INSERT INTO clientActionCode VALUES (501,'Configure Parameter') 
INSERT INTO clientActionCode VALUES (502,'Upgrade') 
INSERT INTO clientActionCode VALUES (503,'Backup Parameter') 
INSERT INTO clientActionCode VALUES (504,'Restore Parameter') 
INSERT INTO clientActionCode VALUES (505,'Copy Parameter') 

-- by role function alarm
INSERT INTO clientActionCode VALUES (601,'Ack Alarm') 
INSERT INTO clientActionCode VALUES (602,'Ack Trap')
INSERT INTO clientActionCode VALUES (603,'Edit Device Alarm')
INSERT INTO clientActionCode VALUES (604,'Edit Template Alarm')

-- insert message code
INSERT INTO clientActionContentCode VALUES (1,'Node')
INSERT INTO clientActionContentCode VALUES (2,'Location')
INSERT INTO clientActionContentCode VALUES (3,'Topology Device Link')
INSERT INTO clientActionContentCode VALUES (4,'Topology Equip Link')
INSERT INTO clientActionContentCode VALUES (5,'Alarm Log')
INSERT INTO clientActionContentCode VALUES (6,'Trap Log')
INSERT INTO clientActionContentCode VALUES (7,'Template Alarm')
INSERT INTO clientActionContentCode VALUES (8,'Interval Minutes')
INSERT INTO clientActionContentCode VALUES (9,'Parent')
INSERT INTO clientActionContentCode VALUES (10,'Child')
INSERT INTO clientActionContentCode VALUES (11,'Tree')
INSERT INTO clientActionContentCode VALUES (12,'Alias')
INSERT INTO clientActionContentCode VALUES (13,'Map Scale')
INSERT INTO clientActionContentCode VALUES (14,'Map Image')
INSERT INTO clientActionContentCode VALUES (15,'Position X')
INSERT INTO clientActionContentCode VALUES (16,'Position Y')
INSERT INTO clientActionContentCode VALUES (17,'Width')
INSERT INTO clientActionContentCode VALUES (18,'Height')
INSERT INTO clientActionContentCode VALUES (19,'Alarm Model')

GO

----- EMS 2.88_01, table 'pmParamErrCode', add id 0~3
----- EMS 2.88_01, table 'pmParamDataType', add id 0~7
INSERT INTO [pmParamErrCode] VALUES ('0', 'No Error')
INSERT INTO [pmParamErrCode] VALUES ('1', 'Disconnected')
INSERT INTO [pmParamErrCode] VALUES ('2', 'Timeout')  
INSERT INTO [pmParamErrCode] VALUES ('3', 'Over Time')  
INSERT INTO [pmParamDataType] VALUES ('0', 'None')
INSERT INTO [pmParamDataType] VALUES ('1', 'PMNormal')
INSERT INTO [pmParamDataType] VALUES ('2', 'PM15Min')
INSERT INTO [pmParamDataType] VALUES ('3', 'PMNormal,PM15Min')
INSERT INTO [pmParamDataType] VALUES ('4', 'PM24Hr')
INSERT INTO [pmParamDataType] VALUES ('5', 'PMNormal,PM24Hr')
INSERT INTO [pmParamDataType] VALUES ('6', 'PM15Min,PM24Hr')
INSERT INTO [pmParamDataType] VALUES ('7', 'PMNormal,PM15Min,PM24Hr')

GO

----- EMS 2.88_01, add new alarm template NMC-R4
----- EMS 2.88_01, add new alarm template for NMC-R4 line card 12G-3R
----- EMS 2.88_01, add new alarm template for NMC-R4 line card Protection
-- EMS 2.100_01, table 'alarmTemplate', add NMC-R4 template type 65
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_NMC_R4(1048)
SET @dvc = 1048
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,47, @cnt, 3,@ena,'')    -- ALARM_ALL_SLOTS_LINK_DOWN(47), SEVERITY_MAJOR(3)
	    
	WHILE (@cnt <= 4) -- 4 Fan
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,8,  @cnt, 4,@ena,'') -- ALARM_FAN_OFF(8), SEVERITY_MINOR(4)
		
		IF (@cnt <= 2) -- 2 Power, 2 Alarm, 2 Fiber, 2 UTP
		BEGIN
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,1,  @cnt, 4,@ena,'') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
			INSERT INTO alarmTemplate VALUES(@dvc,@sid,9,  @cnt, 4,@ena,'') -- ALARM_ALARM_ON(9), 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,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
		
		SET @cnt = @cnt + 1
	END	
	
    SET @cnt = 1
	WHILE (@cnt <= 8)
	BEGIN		
        INSERT INTO alarmTemplate VALUES(@dvc,@sid,65, @cnt, 5,@ena,'')  -- ALARM_CARD_UNPLUG(65), SEVERITY_WARNING(5)
        
        SET @cnt = @cnt + 1
    END
END

----- CARD_12G_3R, CARD_TP(1049)
SET @dvc = 1049
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,43, @cnt, 5,@ena,'72')  -- ALARM_FIBER_CV_Abnormal(43), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,44, @cnt, 5,@ena,'72')  -- ALARM_FIBER_ES_Abnormal(44), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,45, @cnt, 5,@ena,'2')   -- ALARM_FIBER_SES_Abnormal(45), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,46, @cnt, 5,@ena,'10')  -- ALARM_FIBER_UAS_Abnormal(46), SEVERITY_WARNING(5)
		
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,15, @cnt, 5,@ena,'')    -- ALARM_FIBER_TX_FAIL(15), SEVERITY_WARNING(5)
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,26, @cnt, 5,@ena,'')    -- ALARM_FIBER_HAS_NO_OPTICAL_SIGNAL(26), 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

SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc AND type=3) = 0)
BEGIN    
    WHILE (@cnt <= 4) -- 4 FIBER, 0 UTP
	BEGIN
		INSERT INTO alarmTemplate VALUES(@dvc,@sid,3,  @cnt, 5,@ena,'')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
		
		SET @cnt = @cnt + 1
	END		            	
END

----- CARD_Protection(1050)
SET @dvc = 1050
SET @cnt = 1

DELETE FROM alarmTemplate WHERE id=@dvc AND type IN (50,51,52) -- ALARM_WORKPATH_PRI_SIGLOSS(50),ALARM_WORKPATH_SEC_SIGLOSS(51),ALARM_BOTH_CHAN_SIGLOSS(52)

IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc AND type IN (18)) = 0)
BEGIN    
    INSERT INTO alarmTemplate VALUES(@dvc,@sid,18, @cnt, 3,@ena,'')  -- ALARM_CARD_ERROR(18), SEVERITY_MAJOR(3)
END

IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc AND type IN (53,54,55)) = 0)
BEGIN    
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,53, @cnt, 3,@ena,'')  -- ALARM_WORKPATH_SIGLOSS(53), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,54, @cnt, 5,@ena,'')  -- ALARM_PRI_CHAN_SIGLOSS(54), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,55, @cnt, 5,@ena,'')  -- ALARM_SEC_CHAN_SIGLOSS(55), SEVERITY_WARNING(5)			            	
END
GO

-- EMS 2.90_01, add new alarm template MSW404

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_MSW404(84)
SET @dvc = 84
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	WHILE (@cnt <= 4) -- 4 FIBER, 4 UTP, 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)
		
		SET @cnt = @cnt + 1
	END	
END
GO

-- EMS 2.90_01, add new alarm template MSW4424A
-- EMS 3.014, table 'alarmTemplate', add MSW4424A alarm type 1, 8
DECLARE @i INT
 
SET @i=1
WHILE (@i <= 2)   
BEGIN
    INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(85, 0, 1, @i, 4, 1, '')  -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
    SET @i=@i+1
END

INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(85, 0, 8, 1, 4, 1,'')  -- ALARM_FAN_OFF(8), SEVERITY_MINOR(4)

SET @i=1
WHILE (@i <= 28)
BEGIN
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(85, 0, 3,  @i, 5, 1, '')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(85, 0, 13, @i, 3, 1, '')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(85, 0, 12, @i, 4, 1, '-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(85, 0, 14, @i, 4, 1, '80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
	
	SET @i=@i+1
END	
GO

-- EMS 2.90_01, add new alarm template ICSG24S4X

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_ICSG24S4X(93)
SET @dvc = 93
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,9, 1, 4,@ena,'')  -- ALARM_ALARM_ON(9), SEVERITY_MINOR(4)
		    
	WHILE (@cnt <= 29) -- 29 port
	BEGIN
		IF (@cnt <= 28)  -- 28 port
		BEGIN
			IF (@cnt <= 14)  -- 14 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,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,49, @cnt, 5,@ena,'')  -- ALARM_PORT_LINK_DOWN(49), SEVERITY_WARNING(5)
		
		SET @cnt = @cnt + 1
	END	            
END
GO

-- EMS 2.90_01, add new alarm template ICSG24S2X

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_ICSG24S2X(94)
SET @dvc = 94
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,9, 1, 4,@ena,'')  -- ALARM_ALARM_ON(9), SEVERITY_MINOR(4)
		    
	WHILE (@cnt <= 27) -- 27 port
	BEGIN
		IF (@cnt <= 26)  -- 26 port
		BEGIN
			IF (@cnt <= 13)  -- 13 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,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,49, @cnt, 5,@ena,'')  -- ALARM_PORT_LINK_DOWN(49), SEVERITY_WARNING(5)
		
		SET @cnt = @cnt + 1
	END	            
END
GO

-- EMS 2.90_01, add new alarm template IGS-S2804TM

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_IGS-S2804TM(95)
SET @dvc = 95
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,9, 1, 4,@ena,'')  -- ALARM_ALARM_ON(9), SEVERITY_MINOR(4)
		    
	WHILE (@cnt <= 29) -- 29 port
	BEGIN
		IF (@cnt <= 28)  -- 28 port
		BEGIN
			IF (@cnt <= 14)  -- 14 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,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,49, @cnt, 5,@ena,'')  -- ALARM_PORT_LINK_DOWN(49), SEVERITY_WARNING(5)
		
		SET @cnt = @cnt + 1
	END	            
END
GO

----- EMS 2.93_01, modify table 'clientACL', add empty ip/mac for users not in white list
INSERT INTO clientACL 
	SELECT id,'','' FROM client 
	WHERE id NOT IN (SELECT client_id FROM clientACL)
	
GO

----- EMS 2.94_01, modify table 'timeSynchornizer', add rows disable/ntp/ems
INSERT INTO timeSynchornizer VALUES(0, 'disable')	
INSERT INTO timeSynchornizer VALUES(1, 'sync. with NTP server')	
INSERT INTO timeSynchornizer VALUES(2, 'sync. with EMS server')
		
GO		


----- EMS 2.91_01, add new alarm template GSW3208M2
----- EMS 2.92_01, add new alarm template GSW1005MS
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_GSW3208M2(86)
SET @dvc = 86
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,9, 1, 4,@ena,'')  -- ALARM_ALARM_ON(9), SEVERITY_MINOR(4)
		    
	WHILE (@cnt <= 8) -- 8 utp
	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,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
		
		SET @cnt = @cnt + 1
	END	            
END

----- DEVICE_GSW1005MS(87)
SET @dvc = 87
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN
	WHILE (@cnt <= 5) -- 5 utp
	BEGIN
		IF (@cnt <= 1)  -- 1 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,2,  @cnt, 5,@ena,'')    -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
		
		SET @cnt = @cnt + 1
	END	            
END

GO

----- EMS 2.99_01, add new alarm template NMC-R3 line card Eoe1/GS
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
    
----- MODEL_EOE1GS(1052)
SET @dvc = 1052

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,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)		
	
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,58, 1, 7,@ena,'') -- ALARM_LOOPBACK_TEST(58), SEVERITY_TESTING(7)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,59, 1, 7,@ena,'') -- ALARM_BERT_TEST(59), SEVERITY_TESTING(7)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,60, 1, 7,@ena,'') -- ALARM_BERT_TEST_HAS_ERROR(60), SEVERITY_TESTING(7)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,63, 1, 5,@ena,'') -- ALARM_E1_LOS(63), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,64, 1, 5,@ena,'') -- ALARM_E1_LOF(64), 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,29, 1, 5,@ena,'') -- ALARM_E1_RAI_ON(29), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,61, 1, 5,@ena,'') -- ALARM_E1_CRC_ON(61), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,62, 1, 5,@ena,'') -- ALARM_E1_BPV_ON(62), SEVERITY_WARNING(5)
END

----- EMS 2.99_01, add new alarm template for NMC-R3 line card OPS51
----- MODEL_OPS51(1053)
SET @dvc = 1053
SET @cnt = 1
IF( (SELECT COUNT(*) FROM alarmTemplate WHERE id=@dvc) = 0)
BEGIN    
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,53, @cnt, 3,@ena,'')  -- ALARM_WORKPATH_SIGLOSS(53), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,54, @cnt, 5,@ena,'')  -- ALARM_PRI_CHAN_SIGLOSS(54), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate VALUES(@dvc,@sid,55, @cnt, 5,@ena,'')  -- ALARM_SEC_CHAN_SIGLOSS(55), SEVERITY_WARNING(5)			            	
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    

----- EMS 2.99_01, add new alarm template MSW4424C
----- DEVICE_MSW4424C(82)
SET @dvc = 82
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,8, 1, 4,@ena,'')  -- ALARM_FAN_OFF(8), SEVERITY_MINOR(4)
		    
	WHILE (@cnt <= 29) -- 29 port
	BEGIN
		IF (@cnt <= 28)  -- 28 port
		BEGIN
			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,49, @cnt, 5,@ena,'')  -- ALARM_PORT_LINK_DOWN(49), SEVERITY_WARNING(5)
		
		SET @cnt = @cnt + 1
	END	            
END
GO

----- EMS 2.99_01, add new alarm template for NMC-R3 line card FMC1000MS
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_FMC1000MS(1054)
SET @dvc = 1054
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

-- EMS 2.101, table 'alarmTemplate', add id 1055 FRM220-OAB15 template.
INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(1055, 0,  9, 1, 4, 1,'')  -- ALARM_ALARM_ON(9), SEVERITY_MINOR(4)
INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(1055, 0, 66, 1, 4, 1,'')  -- ALARM_PUMP_INACTIVE(66), SEVERITY_MINOR(4)
GO

-- EMS 2.102, table 'alarmTemplate', add IGS-1608SM-8PH
DECLARE @i INT

SET @i=1
WHILE (@i <= 2)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(96, 0, 1, @i, 4, 1,'')  -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
    SET @i=@i+1
END

INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(96, 0, 4, 1, 4, 1,'')  -- ALARM_FAULT_ON(4), SEVERITY_MINOR(4)  

SET @i=1
WHILE (@i <= 16)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(96, 0, 2, @i, 5, 1,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
    SET @i=@i+1
END

SET @i=1
WHILE (@i <= 8)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(96, 0, 3, @i, 5, 1,'')     -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(96, 0, 12, @i, 4, 1,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(96, 0, 13, @i, 3, 1,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(96, 0, 14, @i, 4, 1,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)
    SET @i=@i+1
END

SET @i=1
WHILE (@i <= 5)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(96, 0, 7, @i, 4, 1,'')  -- ALARM_RING_FAULT(7), SEVERITY_MINOR(4)
    SET @i=@i+1
END

SET @i=1
WHILE (@i <= 8)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(96, 0, 5, @i, 3, 1,'') -- ALARM_POEBUDGET_EXCEED(5), SEVERITY_MAJOR(3)  
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(96, 0, 6, @i, 3, 1,'') -- ALARM_POEPD_OVERLOAD(6), SEVERITY_MAJOR(3) 
    SET @i=@i+1
END
GO

-- EMS 2.102, table 'alarmTemplate', add IFS-1608GSM-8PH
DECLARE @i INT

SET @i=1
WHILE (@i <= 2)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(97, 0, 1, @i, 4, 1,'')  -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
    SET @i=@i+1
END

INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(97, 0, 4, 1, 4, 1,'')  -- ALARM_FAULT_ON(4), SEVERITY_MINOR(4)  

SET @i=1
WHILE (@i <= 16)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(97, 0, 2, @i, 5, 1,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
    SET @i=@i+1
END

SET @i=1
WHILE (@i <= 8)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(97, 0, 3, @i, 5, 1,'')     -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(97, 0, 12, @i, 4, 1,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(97, 0, 13, @i, 3, 1,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(97, 0, 14, @i, 4, 1,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)
    SET @i=@i+1
END

SET @i=1
WHILE (@i <= 5)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(97, 0, 7, @i, 4, 1,'')  -- ALARM_RING_FAULT(7), SEVERITY_MINOR(4)
    SET @i=@i+1
END

SET @i=1
WHILE (@i <= 8)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(97, 0, 5, @i, 3, 1,'') -- ALARM_POEBUDGET_EXCEED(5), SEVERITY_MAJOR(3)  
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(97, 0, 6, @i, 3, 1,'') -- ALARM_POEPD_OVERLOAD(6), SEVERITY_MAJOR(3) 
    SET @i=@i+1
END
GO

-- EMS 2.102, table 'alarmTemplate', add IGS-1608SM-SE
DECLARE @i INT

SET @i=1
WHILE (@i <= 2)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(98, 0, 1, @i, 4, 1,'')  -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
    SET @i=@i+1
END

INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(98, 0, 4, 1, 4, 1,'')  -- ALARM_FAULT_ON(4), SEVERITY_MINOR(4)  

SET @i=1
WHILE (@i <= 16)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(98, 0, 2, @i, 5, 1,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
    SET @i=@i+1
END

SET @i=1
WHILE (@i <= 8)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(98, 0, 3, @i, 5, 1,'')     -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(98, 0, 12, @i, 4, 1,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(98, 0, 13, @i, 3, 1,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(98, 0, 14, @i, 4, 1,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)
    SET @i=@i+1
END

SET @i=1
WHILE (@i <= 5)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(98, 0, 7, @i, 4, 1,'')  -- ALARM_RING_FAULT(7), SEVERITY_MINOR(4)
    SET @i=@i+1
END
GO

-- EMS 3.004, table 'alarmTemplate', add GSW-3424FM
DECLARE @i INT

SET @i=1
WHILE (@i <= 2)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(99, 0, 1, @i, 4, 1,'')  -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
    SET @i=@i+1
END

SET @i=1
WHILE (@i <= 5)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(99, 0, 2, @i, 5, 1,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
    SET @i=@i+1
END

SET @i=1
WHILE (@i <= 28)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(99, 0, 3, @i, 5, 1,'')     -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
    -- INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(99, 0, 12, @i, 4, 1,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
    -- INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(99, 0, 13, @i, 3, 1,'')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
    -- INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(99, 0, 14, @i, 4, 1,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)
    SET @i=@i+1
END
GO

-- EMS 3.005, table 'alarmTemplate', add id 1056 FRM220-E1/DATA template.
INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(1056, 0, 10, 1, 3, 1,'')  -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(1056, 0, 32, 1, 3, 1,'')  -- ALARM_E1_SIGNAL_LOSS(32), SEVERITY_MAJOR(3)
INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(1056, 0, 33, 1, 3, 1,'')  -- ALARM_E1_SYNC_LOSS(33), SEVERITY_MAJOR(3)
INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(1056, 0, 27, 1, 4, 1,'')  -- ALARM_E1_ALARM_ON(27), SEVERITY_MINOR(4)
INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(1056, 0, 30, 1, 5, 1,'')  -- ALARM_E1_LOMF_ON(30), SEVERITY_WARNING(5)
INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(1056, 0, 28, 1, 5, 1,'')  -- ALARM_E1_AIS_ON(28), SEVERITY_WARNING(5)
INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(1056, 0, 58, 1, 7, 1,'')  -- ALARM_LOOPBACK_TEST(58), SEVERITY_TESTING(7)
GO

-- EMS 3.007, table 'alarmTemplate', add MSW-4428X
-- EMS 3.008, table 'alarmTemplate', add MSW-4428X alarm type 8, 12, 13, 14
DECLARE @i INT

SET @i=1
WHILE (@i <= 2)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(100, 0, 1, @i, 4, 1,'')  -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
    SET @i=@i+1
END

SET @i=1
WHILE (@i <= 3)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(100, 0, 8, @i, 4, 1,'')  -- ALARM_FAN_OFF(8), SEVERITY_MINOR(4)
    SET @i=@i+1
END

SET @i=1
WHILE (@i <= 5)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(100, 0, 2, @i, 5, 1,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
    SET @i=@i+1
END

SET @i=1
WHILE (@i <= 28)   
BEGIN
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(100, 0, 3, @i, 5, 1,'')     -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(100, 0, 12, @i, 4, 1,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(100, 0, 13, @i, 3, 1,'-40') -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
    INSERT INTO alarmTemplate (id, side, type, idx, severity, enable, param) VALUES(100, 0, 14, @i, 4, 1,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)
    SET @i=@i+1
END
GO

-- EMS 3.008, table 'alarmTemplate', add IWA-AR114
DECLARE @i INT

SET @i=1
WHILE (@i <= 4)   
BEGIN
    INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(101, 0, 2, @i, 5, 1,'') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
    SET @i=@i+1
END
    
INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(101, 0, 3, 1, 5, 1,'')     -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(101, 0, 12, 1, 4, 1,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(101, 0, 13, 1, 3, 1,'') -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(101, 0, 14, 1, 4, 1,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)
GO


-- EMS 3.015, table 'alarmTemplate', add IACCESS
DECLARE @i INT

SET @i=1    
WHILE (@i<=2)
BEGIN
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(102, 0, 1, @i, 4, 1, '') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(102, 0, 9, @i, 4, 1, '') -- ALARM_ALARM_ON(9), SEVERITY_MINOR(4)
	
    INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(102, 0, 3, @i, 5, 1, '') -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(102, 0, 2, @i, 5, 1, '') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)

	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(102, 0, 13, @i, 3, 1, '') -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(102, 0, 12, @i, 4, 1, '-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(102, 0, 14, @i, 4, 1, '80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
	SET @i=@i+1
END	

SET @i=1    
WHILE (@i<=4)
BEGIN
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(102, 0, 8, @i, 4, 1, '') -- ALARM_FAN_OFF(8), SEVERITY_MINOR(4)
	SET @i=@i+1
END	

INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(102, 0, 47, 1, 3, 1, '') -- ALARM_ALL_SLOTS_LINK_DOWN(47), SEVERITY_MAJOR(3)

SET @i=1    
WHILE (@i<=8)
BEGIN		
    INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(102, 0, 65, @i, 5, 1,'') -- ALARM_CARD_UNPLUG(65), SEVERITY_WARNING(5)
    SET @i=@i+1
END
GO

-- EMS 3.015, table 'alarmTemplate', add line card 12G TP
DECLARE @i INT
DECLARE @j INT

SET @i=1     
WHILE (@i<=4)
BEGIN
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1057, 0, 15, @i, 5, 1, '')    -- ALARM_FIBER_TX_FAIL(15), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1057, 0, 67, @i, 5, 1, '')    -- ALARM_FIBER_SIGNAL_LOSS(67), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1057, 0, 68, @i, 5, 1, '')    -- ALARM_FIBER_CDR_UNLOCK(68), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1057, 0, 11, @i, 7, 1, '')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
	
	IF(@i%2=0) SET @j=-12 ELSE SET @j=-18
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1057, 0, 12, @i, 4, 1, @j) -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
	
	IF(@i%2=0) SET @j=-14 ELSE SET @j=-20
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1057, 0, 13, @i, 3, 1, @j) -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
	
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1057, 0, 14, @i, 4, 1, '80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
    INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1057, 0, 43, @i, 5, 1, '72')  -- ALARM_FIBER_CV_Abnormal(43), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1057, 0, 44, @i, 5, 1, '72')  -- ALARM_FIBER_ES_Abnormal(44), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1057, 0, 45, @i, 5, 1, '2')   -- ALARM_FIBER_SES_Abnormal(45), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1057, 0, 46, @i, 5, 1, '10')  -- ALARM_FIBER_UAS_Abnormal(46), SEVERITY_WARNING(5)
	SET @i=@i+1
END	
GO	 

-- EMS 3.015, table 'alarmTemplate', add line card DMUX16SP  
INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1058, 0, 53, 1, 3, 1, '')  -- ALARM_WORKPATH_SIGLOSS(53), SEVERITY_MAJOR(3)
INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1058, 0, 54, 1, 5, 1, '')  -- ALARM_PRI_CHAN_SIGLOSS(54), SEVERITY_WARNING(5)
INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1058, 0, 55, 1, 5, 1, '')  -- ALARM_SEC_CHAN_SIGLOSS(55), SEVERITY_WARNING(5)	
GO

-- EMS 3.016, table 'alarmTemplate', add FRM220A-N
-- EMS 3.016.3, table 'alarmTemplate', add FRM220A-N alarm type 12, 13, 14, 56, 57
DECLARE @i INT

SET @i=1     
WHILE (@i<=2)
BEGIN
    INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(103, 0, 1, @i, 4, 1, '') -- ALARM_POWER_OFF(1), SEVERITY_MINOR(4)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(103, 0, 8, @i, 4, 1, '') -- ALARM_FAN_OFF(8), SEVERITY_MINOR(4)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(103, 0, 9, @i, 4, 1, '') -- ALARM_ALARM_ON(9), SEVERITY_MINOR(4)    
    SET @i=@i+1
END

SET @i=1     
WHILE (@i<=4)
BEGIN
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(103, 0, 2, @i, 5, 1, '') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(103, 0, 3, @i, 5, 1, '') -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(103, 0, 12, @i, 4, 1,'-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
    INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(103, 0, 13, @i, 3, 1,'-40') -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
    INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(103, 0, 14, @i, 4, 1,'80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)
    SET @i=@i+1
END

INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(103, 0, 56, 1, 4, 1,'')  -- ALARM_CPU_TEMPERATURE_ABNORMAL(56), SEVERITY_MINOR(4)
INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(103, 0, 57, 1, 4, 1,'')  -- ALARM_BOARD_TEMPERATURE_ABNORMAL(57), SEVERITY_MINOR(4)    
GO    

-- EMS 3.020, table 'alarmTemplate', add FRM220 card GFOM08 
DECLARE @i INT

INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1044, 0, 10, 1, 3, 1, '') -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1044, 0, 20, 1, 4, 1, '') -- ALARM_FIBER_FEF_ON(20), SEVERITY_MINOR(4)	
INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1044, 0, 25, 1, 4, 1, '') -- ALARM_FIBER_BIT_ERROR(25), SEVERITY_MINOR(4)
INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1044, 0, 11, 1, 7, 1, '') -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)			
INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1044, 0, 2,  1, 5, 1, '') -- ALARM_UTPLINK_DOWN(2), SEVERITY_WARNING(5)

SET @i=1     
WHILE (@i<=2)
BEGIN
    INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1044, 0, 15, @i, 3, 1, '')    -- ALARM_FIBER_TX_FAIL(15), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1044, 0, 3,  @i, 5, 1, '')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1044, 0, 13, @i, 3, 1, '')    -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1044, 0, 12, @i, 4, 1, '-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1044, 0, 14, @i, 4, 1, '80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
    SET @i=@i+1
END

SET @i=1     
WHILE (@i<=8)
BEGIN
    INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1044, 0, 21, @i, 5, 1, '') -- ALARM_E1Chan_RX_LOSS(21), SEVERITY_WARNING(5)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1044, 0, 22, @i, 4, 1, '') -- ALARM_E1Chan_AIS_ON(22), SEVERITY_MINOR(4)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1044, 0, 23, @i, 3, 1, '') -- ALARM_E1Chan_TX_FAIL(23), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(1044, 0, 24, @i, 7, 1, '') -- ALARM_E1Chan_LOOPBACK_TEST(24), SEVERITY_TESTING(7)	
    SET @i=@i+1
END
GO

-- EMS 3.026, table 'alarmTemplate', add 2000EAS-4F
DECLARE @i INT
SET @i=1     
WHILE (@i<=4)
BEGIN
    --INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(104, 0, 10, @i, 3, 1, '')    -- ALARM_REMOTE_POWER_OFF(10), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(104, 0,  3, @i, 5, 1, '')    -- ALARM_FIBERLINK_DOWN(3), SEVERITY_WARNING(5)
    --INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(104, 0, 20, @i, 4, 1, '')    -- ALARM_FIBER_FEF_ON(20), SEVERITY_MINOR(4)
    --INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(104, 0, 11, @i, 7, 1, '')    -- ALARM_FIBER_LOOPBACK_TEST(11), SEVERITY_TESTING(7)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(104, 0, 13, @i, 3, 1, '-40') -- ALARM_FIBER_RX_POWER_ERROR(13), SEVERITY_MAJOR(3)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(104, 0, 12, @i, 4, 1, '-30') -- ALARM_FIBER_RX_POWER_LOW(12), SEVERITY_MINOR(4)
	INSERT INTO alarmTemplate(id, side, type, idx, severity, enable, param) VALUES(104, 0, 14, @i, 4, 1, '80')  -- ALARM_FIBER_TEMPERATURE_ABNORMAL(14), SEVERITY_MINOR(4)	
    SET @i=@i+1
END
GO

