{
    "name"  : "检测用户的并发会话数是否超过限制",
    "problems" : {
        "userSessionExceed" : {
            "desc"      : "【问题】用户的并发会话数超过了限制",
            "advice"    : "【建议】请调整连接数限制策略"
        },
        "sessionExceed" : {
            "desc"      : "【问题】该部分IP地址（${0}）连接数达到上限",
            "advice"    : "【建议】请排查此部分IP地址是否是nat设备，若内网存在nat设备请调整该IP地址连接数限制策略"
        }
    }
}

---------------------------code-------------------------------
ipCheck = precondition('ipCheck')
#ipCheck = '192.168.25.250'

cmd = 'show flow-pre-mgr ip-info | in ' + ipCheck
reg = /[\r\n]+\s*(?:[\d\.]+)\s+(\d+)\s+(\d+)\s*[\r\n]/
response = cli(cmd)
result = response.match(reg)
if result != null :
    flow_current = result[1]
    flow_limit = result[2]
    gap = flow_limit - flow_current
    if gap < 10 :
        add_problem('userSessionExceed')
        return 'warn'
    end
end

isNormal = true
exceedIp = ''
cmd = 'show flow-pre-mgr ip-info'
reg = /[\r\n]+\s*(?:[\d\.]+)\s+(\d+)\s+(\d+)/g
response = cli(cmd)
result = response.match(reg)
if result != null :
    foreach flowItem in result :
        reg = /[\r\n]+\s*([\d\.]+)\s+(\d+)\s+(\d+)/
        flowInfo = flowItem.match(reg)
        if flowInfo != null :
            ip = flowInfo[1]
            flow_current = flowInfo[2]
            flow_limit = flowInfo[3]
            gap = flow_limit - flow_current
            if gap < 10 :
                isNormal = false
                if exceedIp == '' :
                    exceedIp = exceedIp + ip
                else :
                    exceedIp = exceedIp + ', ' + ip
                end
            end
        end
    end
end

if isNormal == false :
    add_problem('sessionExceed',[exceedIp])
    return 'warn'
end

return 'success'