{
    "name"  : "检测NAT配置是否正常",
    "problems" : {
        "error" : {
            "desc"      : "【问题】NAT配置错误",
            "advice"    : "【建议】请在接口${0}下开启NAT功能"
        }
    }
}

---------------------------code-------------------------------
flag = 0
inside_reg = /ip\snat\sinside/i
outside_reg = /ip\snat\soutside/i
response = cli('show run | in nat')
inside = inside_reg.test(response)
if inside == true :
    flag = flag + 1
end
outside = outside_reg.test(response)
if outside == true :
    flag = flag + 1
end

if flag == 1 :
    response = cli('show sys-mode')
    
    reg = /WAN:\s([^\r\n]+)/i
    result = response.match(reg)
    result = result[1]
    reg = /([a-zA-Z]+\s[\d\/\.]+)/g
    wanArr = result.match(reg)
    
    reg = /LAN:\s([^\r\n]+)/i
    result = response.match(reg)
    result = result[1]
    reg = /([a-zA-Z]+\s[\d\/\.]+)/g
    lanArr = result.match(reg)
    
    print "----------------------------------------------------"
    print wanArr
    print lanArr
    
    upWanArr = []
    upLanArr = []
    response = cli('show ip in brief')
    
    #foreach wan in wanArr :
        #reg = format('%s\\s{2,}.+?\\s{2,}.+?\\s{2,}(?:up|UP)',wan)
        #result = response.match(reg)
        #if result != null :
            #upWanArr.push(wan)
        #end
    #end

    #foreach lan in lanArr :
        #reg = format('%s\\s{2,}.+?\\s{2,}.+?\\s{2,}(?:up|UP)',lan)
        #result = response.match(reg)
        #if result != null :
            #upLanArr.push(lan)
        #end
    #end
    
    resArr = response.split(/\r?\n/)
    foreach wan in wanArr :        
        foreach res in resArr :
        	resColumnArr = res.split(/\s{2,}/)
        	if resColumnArr[0] == wan && resColumnArr[3] == 'up' :
        		resColumn = resColumnArr[0]
        		upWanArr.push(resColumn)
        		break
        	end
        end
    end
    foreach lan in lanArr :        
        foreach res in resArr :
        	resColumnArr = res.split(/\s{2,}/)
        	if resColumnArr[0] == lan && resColumnArr[3] == 'up' :
        		resColumn = resColumnArr[0]
        		upLanArr.push(resColumn)
        		break
        	end
        end
    end
    
    print "*****************************************************"
    print upWanArr
    print upLanArr 
    
    errorIntf = ''
    hasError = false
    foreach wan in upWanArr :
        cmd = 'show run int ' + wan
        response = cli(cmd)
        reg = /ip\snat\sinside/i
        if reg.test(response) == false :
            if errorIntf == '' :
                errorIntf = errorIntf + wan
            else :
                errorIntf = errorIntf + ', ' + wan
            end
            hasError = true
        end
    end

    foreach lan in upLanArr :
        cmd = 'show run int ' + lan
        response = cli(cmd)
        reg = /ip\snat\sinside/i
        if reg.test(response) == false :
            if errorIntf == '' :
                errorIntf = errorIntf + lan
            else :
                errorIntf = errorIntf + ', ' + lan
            end
            hasError = true
        end
    end 
    
    if hasError == true :
        add_problem('error', [errorIntf])
        return 'warn'
    end
end

return 'success'


