# frozen_string_literal: true

# 简单示例：直接在 run 中定义检查点
class SimpleCheck < NetCat::DeviceScript
  def run(connection)
    record_start!

    checkpoint :cpu, "检查CPU" do |c|
      c.description = "检查CPU利用率"
      c.expected = "CPU < 70%"
      c.actual = connection.cli("display cpu-usage")
      if c.actual.match(/five seconds[:\s]+(\d+)%/)
        cpu = Regexp.last_match(1).to_i
        c.passed = cpu < 70
        c.reason = "CPU过高: #{cpu}%" unless c.passed
      end
    end

    checkpoint :fan, "检查风扇" do |c|
      c.description = "检查风扇状态"
      c.expected = "风扇正常"
      c.actual = connection.cli("display fan")
      c.passed = c.actual.include?("Normal")
    end

    build_script_result
  end
end
