{
    "name"  : "检测对端热备配置",
    "problems" : {
        "problem1" : {
            "desc"      : "【问题】对端热备配置有误",
            "advice"    : "【建议】在对端配置wlan hot-backup [本端IP]"
        },
        "problem2" : {
            "desc"      : "【问题】热备Context配置不符",
            "advice"    : "【建议】主机和备机需要配置相同的context"
        }
    }
}
---------------------------code-------------------------------
#step1
response = cli('show run | incl local-ip')
print response
reg = /local-ip/
response = response.split(/\r?\n/)
response.shift()
response.pop()
foreach item in response :
    if reg.test(item) :
        item = item.split(/:/)
        terminal_IP = item[1]
        print 'teminal IP !!!!!!!!!!!!!!!!!\n'
        print terminal_IP
        step4()
    end
end

#step2
response = cli('show ac-config')
response = response.split(/\r?\n/)
reg = /localIpAddr/
foreach item in response :
    if reg.test(item) :
        item = item.split(/:/)
        terminal_IP = item[1]
        print item[1]
    end
end

#step3
ip = precondition('ip')
cmd = 'show wlan hot-backup ' + ip
response = cli(cmd)
print '========================='
print response
reg = /context\s(\d+)/
context = []
response = response.split(/\r?\n/)
foreach item in response :  
    match = item.match(reg)
    if match != null :
        match_tmp = match[1]
        context.push(match_tmp)
    end
end
step4()

#step4
def step4() :
    user_name = precondition('user_name')
    user_psw = precondition('user_psw')
    user_snpsw = precondition('user_snpsw')
    cmd = 'telnet ' + ip
    cli(cmd)
	if user_name != '' :
		cli(user_name)
	end
    if user_psw != '' :
	    cli(user_psw)
	end
    if user_snpsw != '' :
		cli('en')
        cli(user_snpsw)
    end
    response = cli('show wlan hot-backup')
    reg = '/' + terminal_IP + '/'
    if !reg.test(response) :
        add_problem('problem1')
		cli('exit')
        return 'warn'
    end
    cli('exit')
    step5()
end

#step5
def step5() :
    cmd = 'telnet' + ip
    cli(cmd)
    cli(user_name)
    cli(user_psw)
    if user_snpsw != '' :
        cli(user_snpsw)
    end
    cmd = 'show wlan hot-backup ' + terminal_IP
    response = cli(cmd)
    reg = /context\s(\d+)/
    context_2 = []
    response = response.split(/\r?\n/)
    foreach item in response :  
        match = item.match(reg)
        if match != null :
            match_tmp = match[1]
            context_2.push(match_tmp)
        end
    end
    foreach i in context_2 :
        foreach j in context :
            if i == j :
                return 'success'
            end
        end
    end

    add_problem('problem2')
    return 'warn'
end

return 'success'