ctx_checker 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +17 -0
  3. data/COUNTER_CONTRACT.md +33 -0
  4. data/LICENSE +22 -0
  5. data/README-zh.md +93 -0
  6. data/README.md +93 -0
  7. data/docs/architecture-zh.md +487 -0
  8. data/docs/release.md +13 -0
  9. data/examples/offline.rb +17 -0
  10. data/lib/ctx_checker/applicability.rb +187 -0
  11. data/lib/ctx_checker/checks/aggregation.rb +73 -0
  12. data/lib/ctx_checker/checks/alarms.rb +25 -0
  13. data/lib/ctx_checker/checks/base.rb +66 -0
  14. data/lib/ctx_checker/checks/clock.rb +30 -0
  15. data/lib/ctx_checker/checks/counters.rb +77 -0
  16. data/lib/ctx_checker/checks/device_counters.rb +32 -0
  17. data/lib/ctx_checker/checks/hardware.rb +45 -0
  18. data/lib/ctx_checker/checks/interfaces.rb +35 -0
  19. data/lib/ctx_checker/checks/ntp.rb +47 -0
  20. data/lib/ctx_checker/checks/optics.rb +107 -0
  21. data/lib/ctx_checker/checks/resources.rb +63 -0
  22. data/lib/ctx_checker/checks/routing.rb +86 -0
  23. data/lib/ctx_checker/checks/temperature.rb +53 -0
  24. data/lib/ctx_checker/cisco_ios/parsers/show_clock_detail.rb +56 -0
  25. data/lib/ctx_checker/cisco_ios/parsers/show_environment_all.rb +153 -0
  26. data/lib/ctx_checker/cisco_ios/parsers/show_etherchannel_summary.rb +110 -0
  27. data/lib/ctx_checker/cisco_ios/parsers/show_facility_alarm_status.rb +41 -0
  28. data/lib/ctx_checker/cisco_ios/parsers/show_interfaces.rb +140 -0
  29. data/lib/ctx_checker/cisco_ios/parsers/show_interfaces_transceiver_detail.rb +107 -0
  30. data/lib/ctx_checker/cisco_ios/parsers/show_ip_bgp_summary.rb +164 -0
  31. data/lib/ctx_checker/cisco_ios/parsers/show_ip_ospf_neighbor.rb +96 -0
  32. data/lib/ctx_checker/cisco_ios/parsers/show_ip_traffic.rb +65 -0
  33. data/lib/ctx_checker/cisco_ios/parsers/show_memory_statistics.rb +36 -0
  34. data/lib/ctx_checker/cisco_ios/parsers/show_ntp_status.rb +44 -0
  35. data/lib/ctx_checker/cisco_ios/parsers/show_processes_cpu.rb +45 -0
  36. data/lib/ctx_checker/cisco_ios/parsers/system_values.rb +62 -0
  37. data/lib/ctx_checker/cisco_ios/profile.rb +39 -0
  38. data/lib/ctx_checker/cisco_nxos/parsers/show_bgp_ipv4_unicast_summary.rb +69 -0
  39. data/lib/ctx_checker/cisco_nxos/parsers/show_clock.rb +13 -0
  40. data/lib/ctx_checker/cisco_nxos/parsers/show_environment.rb +157 -0
  41. data/lib/ctx_checker/cisco_nxos/parsers/show_interface.rb +78 -0
  42. data/lib/ctx_checker/cisco_nxos/parsers/show_interface_transceiver_details.rb +141 -0
  43. data/lib/ctx_checker/cisco_nxos/parsers/show_ip_ospf_neighbors.rb +14 -0
  44. data/lib/ctx_checker/cisco_nxos/parsers/show_ip_traffic.rb +151 -0
  45. data/lib/ctx_checker/cisco_nxos/parsers/show_ntp_peer_status.rb +116 -0
  46. data/lib/ctx_checker/cisco_nxos/parsers/show_port_channel_summary.rb +21 -0
  47. data/lib/ctx_checker/cisco_nxos/parsers/show_system_resources.rb +89 -0
  48. data/lib/ctx_checker/cisco_nxos/profile.rb +35 -0
  49. data/lib/ctx_checker/collector.rb +175 -0
  50. data/lib/ctx_checker/evaluator.rb +49 -0
  51. data/lib/ctx_checker/failure.rb +24 -0
  52. data/lib/ctx_checker/finding.rb +19 -0
  53. data/lib/ctx_checker/h3c/parsers/counters_table.rb +56 -0
  54. data/lib/ctx_checker/h3c/parsers/display_alarm_active.rb +43 -0
  55. data/lib/ctx_checker/h3c/parsers/display_bgp_peer.rb +44 -0
  56. data/lib/ctx_checker/h3c/parsers/display_clock.rb +72 -0
  57. data/lib/ctx_checker/h3c/parsers/display_counters_inbound_interface.rb +21 -0
  58. data/lib/ctx_checker/h3c/parsers/display_counters_outbound_interface.rb +21 -0
  59. data/lib/ctx_checker/h3c/parsers/display_cpu_usage.rb +64 -0
  60. data/lib/ctx_checker/h3c/parsers/display_environment.rb +74 -0
  61. data/lib/ctx_checker/h3c/parsers/display_fan.rb +72 -0
  62. data/lib/ctx_checker/h3c/parsers/display_interface.rb +127 -0
  63. data/lib/ctx_checker/h3c/parsers/display_link_aggregation_verbose.rb +72 -0
  64. data/lib/ctx_checker/h3c/parsers/display_memory.rb +132 -0
  65. data/lib/ctx_checker/h3c/parsers/display_ntp_service_status.rb +84 -0
  66. data/lib/ctx_checker/h3c/parsers/display_ospf_peer.rb +47 -0
  67. data/lib/ctx_checker/h3c/parsers/display_power.rb +63 -0
  68. data/lib/ctx_checker/h3c/parsers/display_transceiver_diagnosis.rb +109 -0
  69. data/lib/ctx_checker/h3c/parsers/system_values.rb +46 -0
  70. data/lib/ctx_checker/h3c/profile.rb +49 -0
  71. data/lib/ctx_checker/hillstone/parsers/show_clock.rb +68 -0
  72. data/lib/ctx_checker/hillstone/parsers/show_cpu.rb +44 -0
  73. data/lib/ctx_checker/hillstone/parsers/show_cpu_cntr.rb +114 -0
  74. data/lib/ctx_checker/hillstone/parsers/show_environment.rb +90 -0
  75. data/lib/ctx_checker/hillstone/parsers/show_interface.rb +82 -0
  76. data/lib/ctx_checker/hillstone/parsers/show_interface_counter.rb +53 -0
  77. data/lib/ctx_checker/hillstone/parsers/show_ip_bgp_summary.rb +22 -0
  78. data/lib/ctx_checker/hillstone/parsers/show_ip_ospf_neighbor.rb +21 -0
  79. data/lib/ctx_checker/hillstone/parsers/show_memory.rb +85 -0
  80. data/lib/ctx_checker/hillstone/parsers/show_ntp_status.rb +110 -0
  81. data/lib/ctx_checker/hillstone/parsers/show_transceiver.rb +101 -0
  82. data/lib/ctx_checker/hillstone/profile.rb +40 -0
  83. data/lib/ctx_checker/observation.rb +165 -0
  84. data/lib/ctx_checker/observation_merger.rb +80 -0
  85. data/lib/ctx_checker/palo_alto/parsers/show_clock.rb +50 -0
  86. data/lib/ctx_checker/palo_alto/parsers/show_counter_global.rb +47 -0
  87. data/lib/ctx_checker/palo_alto/parsers/show_counter_interface_all.rb +68 -0
  88. data/lib/ctx_checker/palo_alto/parsers/show_interface_all.rb +70 -0
  89. data/lib/ctx_checker/palo_alto/parsers/show_lacp_aggregate_ethernet.rb +52 -0
  90. data/lib/ctx_checker/palo_alto/parsers/show_ntp.rb +78 -0
  91. data/lib/ctx_checker/palo_alto/parsers/show_routing_protocol_bgp_peer.rb +66 -0
  92. data/lib/ctx_checker/palo_alto/parsers/show_routing_protocol_ospf_neighbor.rb +54 -0
  93. data/lib/ctx_checker/palo_alto/parsers/show_system_environmentals.rb +142 -0
  94. data/lib/ctx_checker/palo_alto/parsers/show_system_resources.rb +102 -0
  95. data/lib/ctx_checker/palo_alto/parsers/show_system_state_alarms.rb +54 -0
  96. data/lib/ctx_checker/palo_alto/parsers/show_transceiver_all.rb +44 -0
  97. data/lib/ctx_checker/palo_alto/profile.rb +39 -0
  98. data/lib/ctx_checker/parser_registry.rb +43 -0
  99. data/lib/ctx_checker/parsers/base.rb +68 -0
  100. data/lib/ctx_checker/parsers/interface_names.rb +65 -0
  101. data/lib/ctx_checker/parsers/scoped_result.rb +35 -0
  102. data/lib/ctx_checker/policy.rb +104 -0
  103. data/lib/ctx_checker/radware_alteon/parsers/info_l2_lacp_dump.rb +48 -0
  104. data/lib/ctx_checker/radware_alteon/parsers/info_l2_trunk.rb +46 -0
  105. data/lib/ctx_checker/radware_alteon/parsers/info_l3_bgp_summary.rb +22 -0
  106. data/lib/ctx_checker/radware_alteon/parsers/info_l3_ip.rb +71 -0
  107. data/lib/ctx_checker/radware_alteon/parsers/info_l3_ospf_nbr.rb +22 -0
  108. data/lib/ctx_checker/radware_alteon/parsers/info_link.rb +44 -0
  109. data/lib/ctx_checker/radware_alteon/parsers/info_sys_fan.rb +47 -0
  110. data/lib/ctx_checker/radware_alteon/parsers/info_sys_general.rb +48 -0
  111. data/lib/ctx_checker/radware_alteon/parsers/info_sys_ps.rb +34 -0
  112. data/lib/ctx_checker/radware_alteon/parsers/info_sys_temp.rb +53 -0
  113. data/lib/ctx_checker/radware_alteon/parsers/info_transceiver.rb +68 -0
  114. data/lib/ctx_checker/radware_alteon/parsers/stats_mp_cpu.rb +39 -0
  115. data/lib/ctx_checker/radware_alteon/parsers/stats_mp_mem.rb +58 -0
  116. data/lib/ctx_checker/radware_alteon/parsers/stats_port_ether.rb +67 -0
  117. data/lib/ctx_checker/radware_alteon/parsers/stats_port_if.rb +74 -0
  118. data/lib/ctx_checker/radware_alteon/parsers/stats_sp_allutils.rb +99 -0
  119. data/lib/ctx_checker/radware_alteon/parsers/stats_sys_ntp.rb +86 -0
  120. data/lib/ctx_checker/radware_alteon/port_counter_parser.rb +34 -0
  121. data/lib/ctx_checker/radware_alteon/profile.rb +145 -0
  122. data/lib/ctx_checker/radware_alteon.rb +8 -0
  123. data/lib/ctx_checker/report.rb +112 -0
  124. data/lib/ctx_checker/runtime_parser.rb +234 -0
  125. data/lib/ctx_checker/snapshot.rb +44 -0
  126. data/lib/ctx_checker/system_policy.rb +70 -0
  127. data/lib/ctx_checker/system_record.rb +81 -0
  128. data/lib/ctx_checker/version.rb +6 -0
  129. data/lib/ctx_checker.rb +17 -0
  130. metadata +271 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6bd23ca0a7767d79f02f7b0103f0c2f524534ab677d368f995484981d93fbbfb
4
+ data.tar.gz: 9c324f79c104b917338007d105c2a55405a09a036e66a3c9349ef57e3f9664de
5
+ SHA512:
6
+ metadata.gz: 15cf93bf62713e215071bc2d5d0081820cdad50d67b38ddbbc3874e6df30b8f256417997b33e2383ea849bc15b879537b7f9013f393f01dd74f9c943db0a9aff
7
+ data.tar.gz: 0ac66781f4a9795b92bc872704633d72ab12a88a19b26ebe6b3af7e8b8a4239c013bbec61c28c2182e859043fc6b2ee2726eff3f3339e52e648d950769634137
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ Changes to the public contract are recorded here. Versions follow Semantic Versioning.
4
+
5
+ ## 0.1.0 (2026-10-16)
6
+
7
+ ### Added
8
+
9
+ - Multi-vendor observations, normalized counters, applicability, runtime policies, and health reports.
10
+ - Standalone RubyGems packaging under `ctx_checker` with the `ctx_checker` require path and `CtxChecker` namespace.
11
+ - English and Chinese documentation, an offline example, and standalone RSpec/RuboCop development tasks.
12
+ - Linux/macOS CI, isolated package verification, and automatic RubyGems and GitHub Releases with identical artifacts.
13
+
14
+ ### Changed
15
+
16
+ - Cross-module dependencies resolve through RubyGems/Bundler instead of relative sibling paths.
17
+ - Motor persistence and application-specific adapters remain in the host application.
@@ -0,0 +1,33 @@
1
+ # 接口计数归一契约
2
+
3
+ 接口计数以 `interface + metric` 为身份,保留 `value`、`unit`、`scope`、`source_command`、
4
+ `sampled_at` 和 `discontinuity`。归一化表示同类指标采用一致字段,不表示不同计数可以相加。
5
+ `in_errors`、`out_errors`、`in_discards`、`out_discards` 分别表示接收错误、发送错误、接收丢弃和发送丢弃;
6
+ CRC 及其他错误子项保留独立指标,可能已包含在错误总数中。
7
+
8
+ | 字段 | 值 | 含义 |
9
+ | --- | --- | --- |
10
+ | `unit` | `packets` | 包计数,可应用接口包计数策略 |
11
+ | | `bytes` | 字节计数,不转换或当作包数 |
12
+ | | `events` | 事件计数,不转换或当作包数 |
13
+ | | `unknown` | 命令未证实单位,保留原值,健康判断未知 |
14
+ | `scope` | `interface` | 接口整体计数 |
15
+ | | `mac` | MAC 层计数 |
16
+ | | `cpu` | CPU 接口计数 |
17
+ | | `logical` | 逻辑接口计数 |
18
+ | | `queue` | 队列计数 |
19
+ | | `unknown` | 无法证实范围,健康判断未知 |
20
+
21
+ `RuntimeParser` 仅在已声明的接口计数命令投影中补齐 `packets/interface` 默认值;解析器的显式
22
+ `unit/scope` 优先。厂商适配器必须对单位或范围含糊的字段显式标记 `unknown`,不能把模糊字段静默
23
+ 交给默认值。`source_command` 始终由命令目录确定,不接受解析器伪造来源。
24
+ 直接构造的旧版 `Observation` 仍允许 `unit/scope: nil`,维持旧 API 行为;这不是新来源的语义证据。
25
+
26
+ 判断包计数增量,需要同设备、同接口指标、单位和范围均相同、采样时间递增,以及连续性标识一致。
27
+ 新旧样本一方缺少单位或范围时不做跨版本增量。两个样本都缺少这些字段时保留旧 API 行为。
28
+ `bytes/events/unknown` 单位和 `unknown` 范围均不会使用包阈值,零值也不会据此判定正常。
29
+ 计数回退、清零或重启后的连续性未知时,不用负差、绝对值或自动溢出修正伪造增量。
30
+
31
+ 同接口同指标的多个命令记录仍属于冲突,不按 `scope` 扩大身份后混合累加。
32
+ 来源冲突由 `ObservationMerger` 隔离并报告;若需要同时保留两种范围,应先建立明确的独立业务指标契约。
33
+ 设备级 `device_counters` 使用独立的分类和策略,不继承接口包单位限制。
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Song Huang
4
+ Copyright (c) 2026 Gatework contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
data/README-zh.md ADDED
@@ -0,0 +1,93 @@
1
+ # ctx_checker
2
+
3
+ [English](README.md) | [源码](https://github.com/gatework/ctx_checker) | [变更记录](CHANGELOG.md)
4
+
5
+ 面向异构网络设备的运行时健康检查。厂商解析器归一化观测指标,策略基于事实判定,缺失证据不会被当作健康。
6
+
7
+ ## 能力
8
+
9
+ - 接口、归一化 error/drop 计数、聚合成员、光模块、BGP 和 OSPF。
10
+ - CPU、内存、温度、环境、电源、时钟、NTP、活动告警及设备计数。
11
+ - H3C、Cisco IOS/IOS-XE、Cisco NX-OS、Palo Alto、Hillstone 和 Radware Alteon 策略;各平台覆盖范围不同。
12
+ - 命令执行及解析独立隔离、显式适用性判断,以及可选的前次采样比较。
13
+
14
+ ## 安装
15
+
16
+ 要求 **Ruby 4.0.6 或更新版本**。在应用的 `Gemfile` 中添加:
17
+
18
+ ```ruby
19
+ gem "ctx_checker"
20
+ ```
21
+
22
+ 然后执行 `bundle install`;也可直接执行 `gem install ctx_checker`。Ruby 加载入口为 `ctx_checker`,公开命名空间为 `CtxChecker`;gem 包名与 Ruby 命名空间分别维护。
23
+
24
+ 模块运行依赖:[`ctx_parser`](https://github.com/gatework/ctx_parser), [`ctx_driver`](https://github.com/gatework/ctx_driver)。 gemspec 的运行依赖不添加版本约束;应用应提交自己的 `Gemfile.lock`,保持部署可复现。使用本库不需要启动 Rails 或配置兄弟模块的本地路径。
25
+
26
+ 发布产物和校验值见 [GitHub Releases](https://github.com/gatework/ctx_checker/releases),已发布版本以 [RubyGems](https://rubygems.org/gems/ctx_checker) 为准。
27
+
28
+ ## 离线示例
29
+
30
+ 在开发检出目录安装依赖后执行:
31
+
32
+ ```sh
33
+ bundle exec ruby examples/offline.rb
34
+ ```
35
+
36
+ 示例使用合成数据,不访问网络。完整代码见 [examples/offline.rb](examples/offline.rb):
37
+
38
+ ```ruby
39
+ require "ctx_checker"
40
+
41
+ # 使用合成的 IOS 命令回显,本例不连接设备。
42
+ output = "GigabitEthernet1/0/1 is up, line protocol is up\n"
43
+ parser = CtxChecker::RuntimeParser.new(platform: :cisco_ios)
44
+ observation = parser.parse(:interfaces, output, complete: true)
45
+ snapshot = CtxChecker::Snapshot.new(
46
+ target: { host: "192.0.2.10", platform: parser.platform },
47
+ observed_at: Time.utc(2026, 1, 1),
48
+ observations: { interfaces: observation }
49
+ )
50
+ policy = CtxChecker::Policy.new(required_interfaces: [ "GigabitEthernet1/0/1" ])
51
+ report = CtxChecker::Evaluator.new(policy: policy).call(snapshot)
52
+ puts report.to_text
53
+ # 未请求的维度保持 not_requested,本例不代表整机检查。
54
+ ```
55
+
56
+ ## 公开契约与限制
57
+
58
+ `RuntimeParser.new(platform:, model: nil, software_version: nil)` 提供 `parse`、`parse_many`、`parse_outputs`。以观察结果构建 `Snapshot`,再用 `Evaluator.new(policy: Policy.new).call(snapshot, previous: nil)` 判定;报告提供 `to_text`、`to_h`、`summary` 及覆盖率。
59
+
60
+ 观察完整性 `complete/partial/failed/unsupported/not_requested/not_applicable` 与业务结论 `pass/fail/unknown/not_applicable` 分开。空回显不能独自证明健康或功能未配置。可信配置可证明可选 BGP、OSPF 或聚合检查不适用,必检策略仍优先。
61
+
62
+ error、CRC、discard 保持独立,不相加;单次累计值不能当作当前错误速率。增量要求身份一致、时间递增及可靠连续性证据。光功率需要设备或策略阈值;已有格式支持不代表所有型号/版本都已验证。
63
+
64
+ `Collector#collect` 接收负责会话生命周期的 connector;`collect_session` 借用已有会话。本 gem 不包含 Rails、库存数据库、调度或凭据。指标语义见[计数契约](COUNTER_CONTRACT.md)。
65
+
66
+ 详细厂商语义、历史验证记录和 Motor 专用集成说明保留在[架构参考](docs/architecture-zh.md)。其中宿主集成代码需要 Motor,不属于独立 gem API。适配层位于 [Motor 仓库](https://github.com/gatework/motor/tree/main/backend/lib) 的 `backend/lib/baseline`、`backend/lib/vxlan` 和 `backend/lib/wireless`。
67
+
68
+ 生命周期 connector 是宿主适配器,提供 `open { |session| }`,VXLAN 和 Wireless 还要求 `platform`;原生 `Net::Connector::Base` 实例并不提供这一宿主生命周期协议。已连接的原生会话可传入 `CtxDriver::Reader` 或 `CtxChecker::Collector#collect_session`,不会隐式连接或重试。
69
+
70
+ ## 开发与测试
71
+
72
+ ```sh
73
+ bundle install
74
+ bundle exec rake
75
+ bundle exec ruby examples/offline.rb
76
+ bundle exec rake build
77
+ ```
78
+
79
+ `bundle exec rake` 执行 RSpec、RuboCop 及离线示例。测试放在 `spec/`,沿用项目 RSpec 约定;样例采用合成或脱敏证据。新增解析格式时补充成功、不完整、不支持及非法输入回归。离线测试不代表所有设备版本均通过实机验证。
80
+
81
+ 使用声明的最低 Ruby 版本检查兼容性。方法用途统一使用简明中文注释;复杂实现还需说明业务规则、实现思路及关键分支。保持公开返回值与错误契约。真实回显和凭据不可进入示例、fixture、日志或发布包。
82
+
83
+ ## 发布
84
+
85
+ 本目录可独立维护为 [ctx_checker](https://github.com/gatework/ctx_checker) 仓库。更新 `VERSION` 和 `CHANGELOG.md`,运行上述验证与构建命令,检查包内文件,再创建 `vVERSION` 标签。
86
+
87
+ CI 在 Linux、macOS 上执行测试、lint、示例、构建和隔离安装。`main` 的 CI 通过后推送 `vVERSION` 标签,工作流将已验证的 Linux 产物发布到 RubyGems 和 GitHub Release,附带 `SHA256SUMS` 并回读下载字节。GitHub `release` environment 可配置 `RUBYGEMS_API_KEY` secret;未配置时使用 RubyGems Trusted Publishing,绑定本仓库、`release.yml` 和 `release` environment。失败时重跑失败的发布 job,以复用原 CI 产物;同版本已存在时必须校验字节一致。详见[发布说明](docs/release.md)。
88
+
89
+ 先发布依赖模块。标签、构建成功或工作流文件都不等于已经发布,需单独确认 RubyGems 的实际结果。版本变化见 [CHANGELOG.md](CHANGELOG.md)。
90
+
91
+ ## 许可证
92
+
93
+ MIT,见 [LICENSE](LICENSE)。
data/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # ctx_checker
2
+
3
+ [简体中文](README-zh.md) | [Source](https://github.com/gatework/ctx_checker) | [Changelog](CHANGELOG.md)
4
+
5
+ Runtime health analysis for heterogeneous network devices. Vendor parsers normalize observed metrics; policies evaluate those facts without treating missing evidence as healthy.
6
+
7
+ ## Features
8
+
9
+ - Interfaces, normalized error/discard counters, aggregation members, optics, BGP, and OSPF.
10
+ - CPU, memory, temperature, environment, power, clock, NTP, active alarms, and device counters.
11
+ - Profiles for H3C, Cisco IOS/IOS-XE, Cisco NX-OS, Palo Alto, Hillstone, and Radware Alteon; coverage differs by platform.
12
+ - Independent command execution and parsing, explicit applicability, and optional comparison with a prior sample.
13
+
14
+ ## Installation
15
+
16
+ Requires **Ruby 4.0.6 or newer**. Add this line to your application's `Gemfile`:
17
+
18
+ ```ruby
19
+ gem "ctx_checker"
20
+ ```
21
+
22
+ Then run `bundle install`, or install directly with `gem install ctx_checker`. The require path is `ctx_checker` and the public namespace is `CtxChecker`; package names and Ruby namespaces are intentionally separate.
23
+
24
+ Internal runtime dependencies: [`ctx_parser`](https://github.com/gatework/ctx_parser), [`ctx_driver`](https://github.com/gatework/ctx_driver). The gemspec declares runtime dependencies without version constraints. Applications should commit their own `Gemfile.lock` to make deployments reproducible. No Rails boot or sibling checkout paths are required.
25
+
26
+ Release artifacts and checksums are available from [GitHub Releases](https://github.com/gatework/ctx_checker/releases). Check [RubyGems](https://rubygems.org/gems/ctx_checker) for published versions.
27
+
28
+ ## Offline example
29
+
30
+ From a development checkout after installing dependencies:
31
+
32
+ ```sh
33
+ bundle exec ruby examples/offline.rb
34
+ ```
35
+
36
+ The example uses synthetic data and performs no network access:
37
+
38
+ ```ruby
39
+ require "ctx_checker"
40
+
41
+ # 使用合成的 IOS 命令回显,本例不连接设备。
42
+ output = "GigabitEthernet1/0/1 is up, line protocol is up\n"
43
+ parser = CtxChecker::RuntimeParser.new(platform: :cisco_ios)
44
+ observation = parser.parse(:interfaces, output, complete: true)
45
+ snapshot = CtxChecker::Snapshot.new(
46
+ target: { host: "192.0.2.10", platform: parser.platform },
47
+ observed_at: Time.utc(2026, 1, 1),
48
+ observations: { interfaces: observation }
49
+ )
50
+ policy = CtxChecker::Policy.new(required_interfaces: [ "GigabitEthernet1/0/1" ])
51
+ report = CtxChecker::Evaluator.new(policy: policy).call(snapshot)
52
+ puts report.to_text
53
+ # 未请求的维度保持 not_requested,本例不代表整机检查。
54
+ ```
55
+
56
+ ## Public contract and limits
57
+
58
+ `RuntimeParser.new(platform:, model: nil, software_version: nil)` exposes `parse`, `parse_many`, and `parse_outputs`. Build `Snapshot` from observations and evaluate it with `Evaluator.new(policy: Policy.new).call(snapshot, previous: nil)`. Reports expose `to_text`, `to_h`, `summary`, and coverage.
59
+
60
+ Observation completeness (`complete`, `partial`, `failed`, `unsupported`, `not_requested`, `not_applicable`) is separate from findings (`pass`, `fail`, `unknown`, `not_applicable`). Empty output alone cannot prove a healthy or unconfigured feature. Confirmed configuration can establish that optional BGP, OSPF, or aggregation checks do not apply; required policy still takes precedence.
61
+
62
+ Errors, CRC, and discards are distinct counters and must not be summed. A single cumulative value is not a current error rate. Delta analysis needs matching identities, increasing timestamps, and reliable continuity evidence. Optics need device or policy thresholds; supported command formats do not guarantee every model/version is covered.
63
+
64
+ `Collector#collect` accepts an injected connector that owns its session lifecycle; `collect_session` borrows an existing session. No Rails, inventory database, scheduler, or credentials are included. See the [counter contract](COUNTER_CONTRACT.md) for metric semantics.
65
+
66
+ Detailed vendor behavior, historical validation notes, and Motor-only integration are preserved in [the architecture reference](docs/architecture-zh.md). Host integration examples in that reference require Motor; they are not standalone gem APIs. Motor adapters live under `backend/lib/baseline`, `backend/lib/vxlan`, and `backend/lib/wireless` in the [Motor repository](https://github.com/gatework/motor/tree/main/backend/lib).
67
+
68
+ The lifecycle connector is a host adapter exposing `open { |session| }` (and `platform` for VXLAN and Wireless). It is distinct from a native `Net::Connector::Base` device instance. Borrowed native sessions are accepted by `CtxDriver::Reader` and `CtxChecker::Collector#collect_session`; they are never implicitly connected or retried.
69
+
70
+ ## Development and tests
71
+
72
+ ```sh
73
+ bundle install
74
+ bundle exec rake
75
+ bundle exec ruby examples/offline.rb
76
+ bundle exec rake build
77
+ ```
78
+
79
+ `bundle exec rake` runs RSpec, RuboCop, and the offline examples. Tests live in `spec/`, following the existing project's RSpec convention; fixtures use synthetic or sanitized evidence. Add regression cases for successful, incomplete, unsupported, and malformed inputs when extending a parser. Offline tests do not certify all device versions or replace live integration checks.
80
+
81
+ Use the declared minimum Ruby version for compatibility checks. Document source methods and non-obvious business logic in concise Chinese, preserve public return/error contracts, and never add raw device captures or credentials to examples, fixtures, logs, or release archives.
82
+
83
+ ## Release
84
+
85
+ This directory can be maintained as the independent [ctx_checker](https://github.com/gatework/ctx_checker) repository. Update `VERSION` and `CHANGELOG.md`, run the validation and build commands above, and inspect the packaged file list before tagging `vVERSION`.
86
+
87
+ CI runs tests, lint, examples, build, and an isolated installation on Linux and macOS. After CI passes on `main`, push `vVERSION` to run the release workflow. It publishes the tested Linux artifact to RubyGems and GitHub Releases, attaches `SHA256SUMS`, and verifies downloaded bytes. The GitHub `release` environment accepts a `RUBYGEMS_API_KEY` secret; without it, configure RubyGems Trusted Publishing for this repository, `release.yml`, and the `release` environment. Retry a failed publish job to reuse its CI artifact; an already published version must have identical bytes. See [release details](docs/release.md).
88
+
89
+ Publish dependency gems first. A Git tag, a successful build, or a workflow file does not establish that the gem has reached RubyGems; confirm the registry result separately. See [CHANGELOG.md](CHANGELOG.md) for release notes.
90
+
91
+ ## License
92
+
93
+ MIT. See [LICENSE](LICENSE).