#!/bin/bash

source /OSM/script/os_load_base.sh

function startProcess()
{
	#执行重启IBASE进程
	OS_echo "Begin to restart IBASE process."
	sh /OSM/script/reload_alarmconfig.sh ibase
	
	#执行重启ALARM进程
	OS_echo "Begin to restart alarm process."
	sh /OSM/script/reload_alarmconfig.sh alarm

	#执行重启Snmp进程
	OS_echo "Begin to restart snmp process."
	sh /OSM/script/reload_alarmconfig.sh snmp

    return 0
}

function PATCH_START()
{  
    fstPad="       "
    otrPad="          "
    tmpResult=$(cat /OSM/conf/event_xve_zh.xml |grep 'eventID="17656624447492"')
    if [ -n "$tmpResult" ]; then
    OS_echo "Alarm id 17656624447492 has in file event_xve_zh.xml."
    else
    tmpStr=''$fstPad'<param eventID="17656624447492"\
'$otrPad'name="主机FC启动器和存储之间的FC链路存在IO超时"\
'$otrPad'detail="主机FC启动器（本端端口号 ##00， 远端端口NPortID ##01， 远端端口wwpn ##02）与存储FC驱动之间的FC链路存在IO超时。"\
'$otrPad'description="主机FC启动器（本端端口号 ##00， 远端端口NPortID ##01， 远端端口wwpn ##02）与存储FC驱动之间的FC链路存在IO超时。"\
'$otrPad'suggestion="步骤1 请优先排查本端存储FC端口与远端之间的链路是否存在误码。&#10;     1.1 若链路不存在误码=&gt;[步骤2]。&#10;     1.2 若存在误码，请优先处理误码，再观察是否仍然存在新增事件，若后续仍然存在新增事件=&gt;[步骤2]。&#10;步骤2 请收集相关事件信息，然后联系技术支持工程师进行处理。"\
'$otrPad'paramDesc="N/A"\
'$otrPad'objID="212"\
'$otrPad'objName="FC端口"\
'$otrPad'location="param1=##00,param2=##01,param3=##02"\
'$otrPad'alarmOid="" />'
	sed -i "/<\/eventDefinition>/i\\$tmpStr" /OSM/conf/event_xve_zh.xml
    OS_echo "Alarm id 17656624447492 inserted into file event_xve_zh.xml."
    fi

    tmpResult=$(cat /OSM/conf/event_xve_en.xml |grep 'eventID="17656624447492"')
    if [ -n "$tmpResult" ]; then
    OS_echo "Alarm id 17656624447492 has in file event_xve_en.xml."
    else
	tmpStr=''$fstPad'<param eventID="17656624447492"\
'$otrPad'name="I/O Timeout Occurs On The Fibre Channel Link Between The Host FC Initiator And The Storage Device"\
'$otrPad'detail="I/O timeout occurs on the Fibre Channel link between the host FC initiator (local port number ##00, remote port NPortID ##01, remote port WWPN ##02) and the storage FC driver."\
'$otrPad'description="I/O timeout occurs on the Fibre Channel link between the host FC initiator (local port number ##00, remote port NPortID ##01, remote port WWPN ##02) and the storage FC driver."\
'$otrPad'suggestion="Step1 Check whether bit errors occur on the link between the FC port of the local storage and the remote storage.&#10;    1.1 If no=&gt;[Step2].&#10;    1.2 If yes, handle the bit errors first and then check whether new events still exist. If new events still exist=&gt;[Step2].&#10;Step2 Collect related information and contact technical support engineers."\
'$otrPad'paramDesc="N/A"\
'$otrPad'objID="212"\
'$otrPad'objName="FC port"\
'$otrPad'location="param1=##00,param2=##01,param3=##02"\
'$otrPad'alarmOid="" />'
	sed -i "/<\/eventDefinition>/i\\$tmpStr" /OSM/conf/event_xve_en.xml
    OS_echo "Alarm id 17656624447492 inserted into file event_xve_en.xml."
    fi
	
    tmpResult=$(cat /ISM/agent/snmp/conf/snmpagent/alarm_config.xml |grep 'eventID="17656624447492"')
    if [ -n "$tmpResult" ]; then
    OS_echo "Alarm id 17656624447492 has in file event_xve_en.xml."
    else
	tmpStr=''$fstPad'<param eventID="17656624447492"\
'$otrPad'name="I/O Timeout Occurs On The Fibre Channel Link Between The Host FC Initiator And The Storage Device"\
'$otrPad'detail="I/O timeout occurs on the Fibre Channel link between the host FC initiator (local port number ##00, remote port NPortID ##01, remote port WWPN ##02) and the storage FC driver."\
'$otrPad'description="I/O timeout occurs on the Fibre Channel link between the host FC initiator (local port number ##00, remote port NPortID ##01, remote port WWPN ##02) and the storage FC driver."\
'$otrPad'suggestion="Step1 Check whether bit errors occur on the link between the FC port of the local storage and the remote storage.&#10;    1.1 If no=&gt;[Step2].&#10;    1.2 If yes, handle the bit errors first and then check whether new events still exist. If new events still exist=&gt;[Step2].&#10;Step2 Collect related information and contact technical support engineers."\
'$otrPad'paramDesc="N/A"\
'$otrPad'objID="212"\
'$otrPad'objName="FC port"\
'$otrPad'location="param1=##00,param2=##01,param3=##02"\
'$otrPad'alarmOid="" />'
	sed -i "/<\/eventDefinition>/i\\$tmpStr" /ISM/agent/snmp/conf/snmpagent/alarm_config.xml
    OS_echo "Alarm id 17656624447492 inserted into file alarm_config.xml."
    fi
    
    sqlite3 /OSM/conf/alarm_config.dat ".timeout 10000" "DELETE FROM alarmdefine_en where AlmID=17656624447492"
    sqlite3 /OSM/conf/alarm_config.dat ".timeout 10000" "DELETE FROM alarmdefine_cn where AlmID=17656624447492"
    
	sqlite3 /OSM/conf/alarm_config.dat ".timeout 10000" "INSERT INTO alarmdefine_cn VALUES('',17656624447492,'主机FC启动器和存储之间的FC链路存在IO超时',2,'主机FC启动器（本端端口号 ##00， 远端端口NPortID ##01， 远端端口wwpn ##02）与存储FC驱动之间的FC链路存在IO超时。','步骤1 请优先排查本端存储FC端口与远端之间的链路是否存在误码。
     1.1 若链路不存在误码=>[步骤2]。
     1.2 若存在误码，请优先处理误码，再观察是否仍然存在新增事件，若后续仍然存在新增事件=>[步骤2]。
步骤2 请收集相关事件信息，然后联系技术支持工程师进行处理。','主机FC启动器（本端端口号 ##00， 远端端口NPortID ##01， 远端端口wwpn ##02）与存储FC驱动之间的FC链路存在IO超时。',212,'FC端口',2);"
    sqlite3 /OSM/conf/alarm_config.dat ".timeout 10000" "INSERT INTO alarmdefine_en VALUES('',17656624447492,'I/O Timeout Occurs On The Fibre Channel Link Between The Host FC Initiator And The Storage Device',2,'I/O timeout occurs on the Fibre Channel link between the host FC initiator (local port number ##00, remote port NPortID ##01, remote port WWPN ##02) and the storage FC driver.','Step1 Check whether bit errors occur on the link between the FC port of the local storage and the remote storage.
    1.1 If no=>[Step2].
    1.2 If yes, handle the bit errors first and then check whether new events still exist. If new events still exist=>[Step2].
Step2 Collect related information and contact technical support engineers.','I/O timeout occurs on the Fibre Channel link between the host FC initiator (local port number ##00, remote port NPortID ##01, remote port WWPN ##02) and the storage FC driver.',212,'FC port',2);"
    startProcess
    return
}

function PATCH_END()
{
    return
}

function PATCH_ROLLSTART()
{
    sed -i  '/17656624447492/,+9d' /OSM/conf/event_xve_zh.xml
    sed -i  '/17656624447492/,+9d' /OSM/conf/event_xve_en.xml
    sed -i  '/17656624447492/,+9d' /ISM/agent/snmp/conf/snmpagent/alarm_config.xml

    sqlite3 /OSM/conf/alarm_config.dat ".timeout 10000" "DELETE FROM alarmdefine_en where AlmID=17656624447492"
    sqlite3 /OSM/conf/alarm_config.dat ".timeout 10000" "DELETE FROM alarmdefine_cn where AlmID=17656624447492"

    startProcess
    return
}

function PATCH_ROLLEND()
{
    return
}
#start：打补丁前需要执行的操作，脚本的执行时间点在替换文件前
#end：打补丁后需要执行的操作，脚本的执行时间点在替换文件后
#rollstart：回滚补丁时需要执行的操作，脚本的执行时间点在文件被恢复之前。
#rollend：回滚补丁时需要执行的操作，脚本的执行时间点在文件被恢复之后。
#PATCH_CLOSE_SWITCH:先读取性能统计开关的状态，将其值保存到switch中,并关闭性能统计开关
#PATCH_OPEN_SWITCH:如果用户之前是打开状态，将其开关打开
#log "command is "$1

L_CMD=$1    
case $L_CMD in
        "start") 
                PATCH_START
                ;;
        "end") 
                PATCH_END
                ;;
        "rollstart") 
                PATCH_ROLLSTART
                ;;
        "rollend") 
                PATCH_ROLLEND
                ;;
        *)
               #log "unsupported option."
esac
exit 0

