{
    "name"  : "是否存在协议震荡",
    "problems" : {
        "OSPF" : {
            "desc"      : "${0}",
            "advice"    : ["【建议】建议开启RLDP防环功能，或者开启风暴控制功能。"
                          ,"\t开启RLDP防环功能示例："
                          ,"\t\tRuijie#config"
                          ,"\t\tRuijie(config)#rldp enable "
                          ,"\t\tRuijie(config)#interface GigabitEthernet 0/1 "
                          ,"\t\tRuijie(config-if-range)#rldp port loop-detect block "
                          ,"\t\tRuijie(config-if-range)#spanning-tree bpdufilter enable "
                          ,"\t\tRuijie(config-if-range)#en "
                          ,"\t\tRuijie#write "
                          ,"\t开启广播风暴控制示例： "
                          ,"\t\tRuijie#config "
                          ,"\t\tRuijie(config)#interface GigabitEthernet 0/1 "
                          ,"\t\tRuijie(config-if-range)#spanning-tree portfast "
                          ,"\t\tRuijie(config-if-range)#spanning-tree bpduguard enable "
                          ,"\t\tRuijie(config-if-range)#storm-control broadcast "
                          ,"\t\tRuijie(config-if-range)#end"
                          ,"\t\tRuijie#write"] 
        }
    }
}
---------------------------code-------------------------------
#是否存在协议震荡
strResult = ''
response = cli('show ip ospf neighbor detail')
if response.search('Invalid input | Unknown command.') != -1 :
    add_reason('无效指令：show ip ospf neighbor detail')
    return 'skip'    
end
ospfReg = /Neighbor\s.+[\r\n]+.*via\sinterface.*[\r\n]+.*state\schanges/g
ospfConfs = response.match(ospfReg)
if ospfConfs == null :
    return 'success'
else :
    i = 0
    while i < ospfConfs.length :
        conf = ospfConfs[i]
        intfName = ''
        intfNameArr = conf.match(/via\sinterface.*[\r\n]/g)
        if intfNameArr.length > 0 :
           intfName = intfNameArr[0]
           intfName = intfName.replace('via','')
        else :
            add_reason('解析出错')
            return 'skip'
        end
        changeNum = tryCatch(conf, /,\s*(\d*)\sstate changes/, 1)
        if changeNum == "解析出错" :
           add_reason('解析出错')
           return 'skip'
        end
        if changeNum > 30 :
           strResult = strResult + '\r\n\t' + intfName
        end
        i = i + 1
    end
end
if strResult != '' :
    strResult = '以下接口存在OSPF震荡:' + strResult
end
response = cli('show logging')
if response.search('Invalid input | Unknown command.') != -1 :
    add_reason('无效指令：show logging')
    return 'skip'    
end
upReg   = /BFD-6-SESSION_STATE_UP.+interface.+is up/g
downReg = /BFD-6-SESSION_STATE_DOWN.+interface.+has gone down/g
upElems = response.match(upReg)
if upElems == null :
    return 'success'
end
downElems = response.match(downReg)
if downElems == null :
    return 'success'
end
intfName = ''
intfTag = {}
bfdResult = ''
i = 0
while i < upElems.length :
    upElemTemp = upElems[i]
    intfNameArr = upElemTemp.match(/interface\s+\S+\s+\S+/g)
    if intfNameArr.length == 0 :
        add_reason('解析出错')
        return 'skip'        
    else :
        intfName = intfNameArr[0]
        intfTag[intfName] = true
    end
    i = i + 1
end
j = 0
while j < downElems.length :
    downElemTemp = downElems[j]
    intfNameArr = downElemTemp.match(/interface\s+\S+\s+\S+/g)
    if intfNameArr.length == 0 :
        add_reason('解析出错')
        return 'skip'        
    else :
        intfName = intfNameArr[0]
        if intfTag[intfName] == true :
            bfdResult = bfdResult + '\r\n\t' + intfName
        end
    end
    j = j + 1
end
if bfdResult != '' :
    bfdResult = '以下接口存在BFD震荡:' + bfdResult
    strResult = strResult + bfdResult
end
strResult = '[问题] 部分接口存在震荡' + '\r\n' + strResult
add_problem('OSPF',[resultStr])
return 'warn'












