#!/bin/bash

source /OSM/script/os_load_base.sh

function startProcess()
{
    # 版本间差异需单独确认参数及脚本是否存在
    OS_echo "Begin to restart OMM process."
    sh /OSM/script/reload_alarmconfig.sh alarm
    return 0
}

function PATCH_START()
{
    OS_echo "Begin to delete psu alert manager."
    # 删除告警0xF00170014（子告警）
    sqlite3 /OSM/conf/alarm_config.dat ".timeout 10000" "DELETE FROM alarm_rules where ChildID=0xF00170014 and FathersID=0xF0170005"

    startProcess
    return
}

function PATCH_END()
{
    return
}

function PATCH_ROLLSTART()
{
    OS_echo "Begin to insert psu alert manager."
    # 回滚前先执行删除操作
    # 删除告警0xF00170014(子告警) + 0xF0170005(父告警)的规则
    sqlite3 /OSM/conf/alarm_config.dat ".timeout 10000" "DELETE FROM alarm_rules where ChildID=0xF00170014 and FathersID=0xF0170005"

    # 删除操作执行后再执行插入操作
    # 插入告警0xF00170014(子告警) + 0xF0170005(父告警)的规则
    sqlite3 /OSM/conf/alarm_config.dat ".timeout 10000" "INSERT INTO alarm_rules VALUES(64426016788,60,4028039173,60,'(0=0,1=1,2=2)')"

    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

