
{
    "name"  : "Flash文件系统检查",
    "problems" : {
        "flash_left" : {
            "desc"      : "【问题】设备flash空间占满，剩余${0}M，使系统存在未知风险，例如出现重启等风险。",
            "advice"    : "【建议】清理管理板FLASH空间或更换大空间管理板。"
        },
        "flash_operate" : {
            "desc"      : "【问题】flash读写异常。",
            "advice"    : "【建议】检查flash读写。"
        }
    }
}

---------------------------code-------------------------------
result = 'pass'
log_flash = cli('dir')
reg = /\d+ bytes flash total \(([^ ]+) bytes free\)/
r = log_flash.match(reg)
if r != null :
	value_str = r[1]
	value = str_to_num(value_str)
	value_left = value/1024/1024
	if value_left<200:
        add_problem('flash_left',[value_left])
		result = 'fail'
	end
end

result = 'pass'
log_write = cli('mkdir flash:/my_test.txt')
cli('rmdir flash:/my_test.txt','[Y/N]')
sleep(2000)
log_delete = cli('y')
log_writeList = log_write.split("\r\n")
log_deleteList = log_delete.split("\r\n")
foreach data in log_writeList:
	if data.indexOf('#') == -1:
		result = 'fail'
	end
end
foreach data in log_deleteList:
	if data.indexOf('#') == -1:
		result = 'fail'
	end
end

if result == 'fail' :
    change_title('flash文件系统异常')
    add_problem('flash_operate')
    return 'warn'
end

change_title('flash文件系统无异常')
return 'success'

def str_to_num(str):
	num = ''
	strList = str.split(",")
	foreach data in strList:
		num = num+data
	end
	return num
end
