#!/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="300661276673"')
    if [ -n "$tmpResult" ]; then
    OS_echo "Alarm id 300661276673 has in file event_xve_zh.xml."
    else
    tmpStr=''$fstPad'<param eventID="300661276673"\
'$otrPad'name="CCDB服务异常"\
'$otrPad'detail="CCDB服务异常，节点编号：##00，此异常会导致CCDB集群冗余度降低，如未及时处理可能导致业务中断、数据丢失等。"\
'$otrPad'description="CCDB服务异常。"\
'$otrPad'suggestion="步骤1 请检查是否有系统盘异常的告警&#10;   1.1 如果是，更换异常盘所在的控制器。操作完成后，手动清除告警。&#10;   1.2 如果否=&gt;步骤2。&#10;步骤2 请收集相关信息，然后联系技术支持工程师进行处理。"\
'$otrPad'paramDesc="N/A"\
'$otrPad'objID="207"\
'$otrPad'objName="控制器"\
'$otrPad'location="nodeid=##00"\
'$otrPad'alarmOid="15.207.16" />'
	sed -i "/<\/eventDefinition>/i\\$tmpStr" /OSM/conf/event_xve_zh.xml
    OS_echo "Alarm id 300661276673 inserted into file event_xve_zh.xml."
    fi

    tmpResult=$(cat /OSM/conf/event_xve_en.xml |grep 'eventID="300661276673"')
    if [ -n "$tmpResult" ]; then
    OS_echo "Alarm id 300661276673 has in file event_xve_en.xml."
    else
	tmpStr=''$fstPad'<param eventID="300661276673"\
'$otrPad'name="The CCDB Service Is Abnormal"\
'$otrPad'detail="The CCDB service (node ID: ##00) is abnormal. This exception reduces the redundancy of the CCDB cluster. If the exception is not handled in a timely manner, services may be interrupted and data may be lost."\
'$otrPad'description="The CCDB service is abnormal."\
'$otrPad'suggestion="Step1 Check whether an alarm is generated indicating that the system disk is abnormal.&#10;    1.1 If yes, replace the controller where the abnormal disk resides. After the operation is complete, manually clear the alarm.&#10;    1.2 If no=&gt;[Step2].&#10;Step2 Collect related information and contact technical support engineers."\
'$otrPad'paramDesc="N/A"\
'$otrPad'objID="207"\
'$otrPad'objName="Controller"\
'$otrPad'location="nodeid=##00"\
'$otrPad'alarmOid="15.207.16" />'
	sed -i "/<\/eventDefinition>/i\\$tmpStr" /OSM/conf/event_xve_en.xml
    OS_echo "Alarm id 300661276673 inserted into file event_xve_en.xml."
    fi
	
    tmpResult=$(cat /ISM/agent/snmp/conf/snmpagent/alarm_config.xml |grep 'eventID="300661276673"')
    if [ -n "$tmpResult" ]; then
    OS_echo "Alarm id 300661276673 has in file event_xve_en.xml."
    else
	tmpStr=''$fstPad'<param eventID="300661276673"\
'$otrPad'name="CCDB Service Is Abnormal"\
'$otrPad'detail="The CCDB service (node ID: ##00) is abnormal. This exception reduces the redundancy of the CCDB cluster. If the exception is not handled in a timely manner, services may be interrupted and data may be lost."\
'$otrPad'description="The CCDB service is abnormal."\
'$otrPad'suggestion="Step1 Check whether an alarm is generated indicating that the system disk is abnormal.&#10;    1.1 If yes, replace the controller where the abnormal disk resides. After the operation is complete, manually clear the alarm.&#10;    1.2 If no=&gt;[Step2].&#10;Step2 Collect related information and contact technical support engineers."\
'$otrPad'paramDesc="N/A"\
'$otrPad'objID="207"\
'$otrPad'objName="Controller"\
'$otrPad'location="nodeid=##00"\
'$otrPad'alarmOid="15.207.16" />'
	sed -i "/<\/eventDefinition>/i\\$tmpStr" /ISM/agent/snmp/conf/snmpagent/alarm_config.xml
    OS_echo "Alarm id 300661276673 inserted into file alarm_config.xml."
    fi
    
    sqlite3 /OSM/conf/alarm_config.dat ".timeout 10000" "DELETE FROM alarmdefine_en where AlmID=300661276673"
    sqlite3 /OSM/conf/alarm_config.dat ".timeout 10000" "DELETE FROM alarmdefine_cn where AlmID=300661276673"
    
	sqlite3 /OSM/conf/alarm_config.dat ".timeout 10000" "INSERT INTO alarmdefine_cn VALUES('',300661276673,'CCDB服务异常',5,'CCDB服务异常。','步骤1 请检查是否有系统盘异常的告警
   1.1 如果是，更换异常盘所在的控制器。操作完成后，手动清除告警。
   1.2 如果否=>步骤2。
步骤2 请收集相关信息，然后联系技术支持工程师进行处理。','CCDB服务异常，节点编号：##00，此异常会导致CCDB集群冗余度降低，如未及时处理可能导致业务中断、数据丢失等。',207,'控制器',0)"
    sqlite3 /OSM/conf/alarm_config.dat ".timeout 10000" "INSERT INTO alarmdefine_en VALUES('',300661276673,'The CCDB Service Is Abnormal',5,'The CCDB service is abnormal.','Step1 Check whether an alarm is generated indicating that the system disk is abnormal.
    1.1 If yes, replace the controller where the abnormal disk resides. After the operation is complete, manually clear the alarm.
    1.2 If no=>[Step2].
Step2 Collect related information and contact technical support engineers.','The CCDB service (node ID: ##00) is abnormal. This exception reduces the redundancy of the CCDB cluster. If the exception is not handled in a timely manner, services may be interrupted and data may be lost.',207,'Controller',0)"
    startProcess
    return
}

function PATCH_END()
{
    return
}

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

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

    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

