{
    "name"  : "版本不一致",
    "problems" : {
        "version" : {
            "desc"      : "【问题】获取到线卡/引擎${0}(获取到不一致的线卡或引擎名称)版本与系统大版本版本不一致，该问题会导致不一致版本线卡/设备的端口不能UP或者流量转发不通。",
            "advice"    : "【建议】重新upgrade升级到最新版本"
        },
        "version_detail": {
            "desc"      : "【问题】获取到线卡/设备${0}(获取到不一致的线卡或引擎名称)版本与系统小版本版本不一致，该问题会导致不一致版本线卡/设备的端口不能UP或者流量转发不通。",
            "advice"    : "【建议】重新upgrade升级到最新版本"
        }
    },
    "slot_map" : {
        "S8606" : {"1":"10","2":"40","3":"50","4":"80"},
        "S8610" : {"1":"10","2":"20","3":"30","4":"40","5":"50","6":"60","7":"70","8":"80"},
        "S8614" : {"1":"10","2":"20","3":"30","4":"40","5":"50","6":"60","7":"70","8":"80","9":"110","10":"120","11":"130","12":"140"}
    }
}
---------------------------code-------------------------------
str_version = cli('show version')
str_versionList=str_version.split("\n")
resule_total='pass'
s_version = get_sysVersion(str_versionList)
result = "pass"
card=''
if s_version != "":
    reg_card = /(Slot\s[^ ]+)\s:\s[^ ]+/
    foreach data in str_versionList:
        r1 = data.match(reg_card)
        if r1 != null:
            slot = r1[1]
            c_version = get_soft_version(str_versionList,slot)
            if c_version != s_version && c_version != "":
                result = "fail"
                card = card + slot + "、"
            end
        end
    end
end
if result == "fail":
    change_title('检测到设备版本不一致')
    add_problem('version',[card])
    result_total="fail"
end
    
result_1 = "pass"
port_1 = ""
str_version_detail = cli('show version detail')
str_version_detailList = str_version_detail.split("\n")
reg = /System software number\s+:\s+\w\d{6}(\d{8})\r\n/
date_sys = get_sysSoft_num(str_version_detailList)
if date_sys != "":
    foreach i in str_version_detailList:
        r1 = i.match(/(Slot\s[^ ]+)\s:\s[^ ]+/)
        if r1 != null:
            slot = r1[1]
            date_detail = get_soft_num(str_version_detailList,slot)
            if GetDateDiff(date_sys,date_detail) > 1:
                result_1 = "fail"
                port_1 = port_1 + slot +"、"
            end
        end  
    end
end

if result_1 == "fail":
    change_title('检测到设备版本不一致')
    add_problem('version_detail',[port_1])
    result_total = "fail"
end
if result_total=="fail":
    return 'warn'
end

change_title('未检测到设备版本不一致')
return 'success'

def get_sysVersion(strList):
    version = ""
    reg =/System software version\s+:\s+[^ ]+\s+([^,^\r^\n]+)/
    foreach data in strList:
        r = data.match(reg)
        if r!= null:
            version = r[1]
            break
        end
    end
    return version
end

def get_soft_version(strList,slot):
    version = ""
    tag = 0
    reg = /Software version\s+:\s+[^ ]+\s+([^,^\r^\n]+)/
    foreach i in strList:
        if i.match(slot):
            tag = 1
        end
        if tag == 1:
            r = i.match(reg)
            if r != null:
                version = r[1]
                return version
                break
            end
        end
    end
    return version
end

def get_sysSoft_num(strList):
    date = ""
    reg = /System software number\s+:\s+\w\d{6}(\d{8})/
    foreach data in strList:
        r = data.match(reg)
        if r != null:
            str_date = r[1]
            date = str_to_date(str_date)
            return date
            break
        end
    end
    return date
end

def get_soft_num(strList,slot):
    date = ""
    tag = 0
    foreach i in strList:
        if i.search(slot) != -1:
            tag = 1
        end
        if tag == 1:
            reg = /Software number\s+:\s+\w\d{6}(\d{8})/
            r = i.match(reg)
            if r != null:
                str_date = r[1]
                date = str_to_date(str_date)
                return date
                break
            end
        end
    end
    return date
end

def str_to_date(str):
    date = ""
    reg = /(\d{2})(\d{2})(\d{4})/
    r = str.match(reg)
    if r != null:
        date=r[3]+"-"+r[1]+"-"+r[2]
        return date
    end
    return date
end
