{
    "name"  : "是否存在攻击",
    "problems" : {
        "localDefend" : {
            "desc"      : "【问题】设备未配置本地防攻击",
            "advice"    : "【建议】在WEB系统上开启本地防攻击-防流量攻击功能" 
        },
        "existDefend" : {
            "desc"      : "【问题】当前存在攻击记录，显示命令返回内容",
            "advice"    : "【建议】配置ip session filter过滤攻击源"
        },
        "existHistoryDefend" : {
            "desc"      : "【问题】存在历史攻击记录，显示命令返回内容",
            "advice"    : "【建议】配置ip session filter过滤攻击源"
        },
        "lackPerformance" : {
            "desc"      : "【问题】存在新建攻击或设备性能不足",
            "advice"    : "【建议】配置防攻击并关闭应用识别功能"
        },
        "icmpAttack" : {
            "desc"      : "【问题】icmp报文可能被防攻击限速",
            "advice"    : "【建议】可以在WEB本地防攻击页面关闭防流量攻击后进行测试"
        }
    }
}
---------------------------code-------------------------------
#是否存在攻击
Message = null
STR = null
STARTNUM = 1

times = 0
ports = []
ports_no_buffer = []
ports_no_buffer_new = []
is_first = true

def fifth() :
    response = cli('show ef-rnfp all')
    reg = /RULE:\sacl:/
    if reg.test(response) :
        add_problem('icmpAttack')
        return 'warn'
    end

    return 'success'
end

def fourth() :
    print 'enter fourth()'
    noBufferBeforeArr = []
    noBufferNowArr = []
    response = cli("show ip i b | in up") 
    results = response.split(/\r?\n/)
    interfaceArr = []
    i = 1
    while i < (results.length - 1):
        resultTmp = results[i]
        resultTmp = resultTmp.trim()
    arr = resultTmp.split(/\s+/)
    interfaceHead = arr[0]
    interfaceNum = arr[1]
    interface = interfaceHead + " " + interfaceNum
    interfaceArr.push(interface)
    i = i + 1
    end

j = 0
while j < interfaceArr.length:
    interface = interfaceArr[j]
    cmd = "show interface " + interface + " | in no buffer"
    response = cli(cmd)
    matchArr = response.match(/bytes, (.+) no buffer,/)
    matchTmp = matchArr[1]
    noBufferBeforeArr.push(matchTmp)
    j = j + 1
end

sleep(5000)

response = cli("show ip i b | in up")
results = response.split(/\r?\n/)

interfaceArr = []
i = 1
while i < (results.length - 1):
    resultTmp = results[i]
    resultTmp = resultTmp.trim()
    arr = resultTmp.split(/\s+/)
    interfaceHead = arr[0]
    interfaceNum = arr[1]
    interface = interfaceHead + interfaceNum
    interfaceArr.push(interface)
    i = i + 1
end

j = 0
while j < interfaceArr.length:
    interface = interfaceArr[j]
    cmd = "show interface " + interface + " | in no buffer"
    response = cli(cmd)
    matchArr = response.match(/bytes, (.+) no buffer,/)
    matchTmp = matchArr[1]
    noBufferNowArr.push(matchTmp)
    j = j + 1
end

k = 0 
while k < noBufferBeforeArr.length :
    noBufferNow = noBufferNowArr[k]
    noBufferBefore = noBufferBeforeArr[k]
	print 'noBufferNow='+noBufferNow
	print 'noBufferBefore='+noBufferBefore
    if noBufferNow - noBufferBefore > 1000:
        add_problem("lackPerformance")
        return "warn"
    end
    k = k + 1
end

fifth()
end

def third() :
    response = cli('show ip i b | in up')
    results = response.split(/\r?\n/ig)
    exist  = false
    i = STARTNUM

	print 'enter third()'
	print 'results='+results

    while i < results.length :
        resultTemp = results[i]
        if resultTemp.search(/(up|UP)/) == -1 :
		    i = i + 1
            continue
        end
        arr = results[i]
        arr = arr.split(/\s\s+/ig)
        if arr.length < 3 :
		    i = i + 1
            continue
        end
        arrTemp = arr[0]
        ports.push(arrTemp)
        exist = true
        i = i + 1
    end
	print 'exist='+exist
	print 'ports='+ports
    if exist == true :
        res = fourth()
        return res
    end
    return 'success'
end

def second() :
    response = cli('show attack-info current')
    results = response.split(/\r?\n/ig)
    exist = false
    i = STARTNUM
    while i < results.length:
        resultTemp = results[i]
        if resultTemp.search("System currently not in attack!") != -1 :
            exist = true
            break
        end        
        i = i + 1       
    end
    if exist == false :
        add_problem('existDefend')
        return 'warn'
    end
    response = cli('show attack-info history')
    results = response.split(/\r?\n/ig)
    _exist = false
    i = STARTNUM
    while i < results.length :
        resultTemp = results[i]
        if resultTemp.search("There is no attack record!") != -1 :
            _exist = true
            break
        end
        i = i + 1
    end
    if _exist == false:
        add_problem('existHistoryDefend')
        return 'warn'
    end
    res = third()
    return res
end

response = cli('show ef-rnfp all | in enable')
results = response.split(/\r?\n/ig)
exist = false
if results.length < (STARTNUM + 2) :
    add_problem('localDefend')
    return 'warn'
end
res = second()
return res

