Skip to content

About

Evidence-based network health checks and configuration diagnostics for Ruby

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

ctx_checker

简体中文 | Source | Changelog

Runtime health analysis for heterogeneous network devices. Vendor parsers normalize observed metrics; policies evaluate those facts without treating missing evidence as healthy.

Features

  • Interfaces, normalized error/discard counters, aggregation members, optics, BGP, and OSPF.
  • CPU, memory, temperature, environment, power, clock, NTP, active alarms, and device counters.
  • Profiles for H3C, Cisco IOS/IOS-XE, Cisco NX-OS, Palo Alto, Hillstone, and Radware Alteon; coverage differs by platform.
  • Independent command execution and parsing, explicit applicability, and optional comparison with a prior sample.

Installation

Requires Ruby 4.0.6 or newer. Add this line to your application's Gemfile:

gem "ctx_checker"

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.

Internal runtime dependencies: ctx_parser, ctx_driver, ctx_runner. The gemspec leaves their versions unconstrained; applications should commit a verified Gemfile.lock for reproducible deployments. No Rails boot or sibling checkout paths are required.

Release artifacts and checksums are available from GitHub Releases. Check RubyGems for published versions.

Offline example

From a development checkout after installing dependencies:

bundle exec ruby examples/offline.rb

The example uses synthetic data and performs no network access:

require "ctx_checker"

# 使用合成的 IOS 命令回显,本例不连接设备。
output = "GigabitEthernet1/0/1 is up, line protocol is up\n"
parser = CtxChecker::RuntimeParser.new(platform: :cisco_ios)
observation = parser.parse(:interfaces, output, complete: true)
snapshot = CtxChecker::Snapshot.new(
  target: { host: "192.0.2.10", platform: parser.platform.to_s },
  observed_at: Time.utc(2026, 1, 1),
  observations: { interfaces: observation }
)
policy = CtxChecker::Policy.new(required_interfaces: [ "GigabitEthernet1/0/1" ])
report = CtxChecker::Evaluator.new(policy: policy).call(snapshot)
puts report.to_text
# 未请求的维度保持 not_requested,本例不代表整机检查。

Public contract and limits

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.

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.

Sampling timestamps in snapshot strings, command evidence, and records require a valid ISO8601 date with an explicit Z or UTC offset. Snapshots also accept Time objects. Aggregation capacity counts only members supported by complete source evidence; incomplete members cannot establish either sufficient capacity or a shortage.

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.

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 for metric semantics.

Collection snapshots the validated target and selected dimensions before calling the clock or connector. A lifecycle connector must yield exactly one session from open; yielding none or twice records session_not_opened / session_reentered, and a second yield never repeats queries. Unrequested observations are not accepted as command fragments during combination.

Detailed vendor behavior, historical validation notes, and Motor-only integration are preserved in the architecture reference. 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.

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.

Domain vocabulary

An Observation describes collected evidence for a dimension; a Finding describes its health assessment. Policy#required_dimension? and SystemPolicy#required_dimension? query required observation dimensions. Interface and optical requirements retain their scoped identity checks. Counter limits compare increments over a validated sampling interval in seconds; they are not cumulative totals or rates.

Integer OSPF process IDs are normalized to strings in policies, observations, and covered scopes before checking identities. An explicit temperature threshold requires a numeric reading; an ok sensor state alone cannot satisfy it. Parsers retain at most 128 diagnostic samples per result, plus a diagnostics_truncated entry counting omitted diagnostics; truncation never proves complete evidence.

Development and tests

Native net-connector 0.13 integration tests require ctx_driver 0.2.2 or newer. Generic borrowed-session fixtures implement the response protocol directly and remain independent of connector result classes. bundle exec ruby examples/connector.rb exercises all five gems through a local PTY: shared command collection, raw evidence, parsed observations, health findings, and rejection without implicit reconnection. It uses synthetic device responses and requires no network endpoint or credentials.

Name shared classes by their responsibility and use the namespace for platform context. Preserve filenames and class names that directly match device commands.

CLI parsers specify field and line separators explicitly (split(" "), each_line("\n"), and join("\n") as appropriate). Host applications may change Ruby's global separators; that must not change device facts or source evidence.

bundle install
bundle exec rake
bundle exec ruby examples/offline.rb
bundle exec rake build

bundle exec rake runs RSpec, RuboCop, and the offline and local PTY 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.

Run ruby script/verify_package.rb /path/to/ctx_checker.gem to verify an isolated installation with published dependencies. During coordinated development, append explicitly built dependency artifacts, such as /path/to/ctx_parser.gem, to install and activate those exact candidate versions first; incompatible candidates fail verification. Candidate verification does not establish that the published dependencies are compatible. bundle exec ruby -Ilib benchmark/runtime.rb measures synthetic command lookup and diagnostic overhead locally. bundle exec ruby benchmark/report.rb measures report construction for 64, 256, and 512 failed queries, excluding network and parsing time.

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.

Release

This directory can be maintained as the independent ctx_checker repository. Update VERSION and CHANGELOG.md, run the validation and build commands above, and inspect the packaged file list before tagging vVERSION.

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.

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 for release notes.

License

MIT. See LICENSE.

Snapshot access uses observations and observation(name): known missing dimensions are not_requested; unknown names raise ArgumentError. Collection provider failures remain structured issues, including session_not_opened and session_reentered, without replaying queries.

本次契约升级要求重新生成旧报告和计划;Ruby 快照使用 observations、collection_status 和 Time,JSON 通过 CtxRunner::Document 输出 UTC ISO8601(解析基础库仅提供 Result)。跨模块约定见 ctx_runner 契约迁移。

Domain contract migration (2026-10-30)

Inherit shared Observation value semantics with domain validation on construction and replacement. Use peer_address for BGP/NTP endpoints and public Target values in snapshots; expose records(name). Require Runner/Driver 0.5. See the schema 4 migration and module contracts. Regenerate old collection reports and change plans; changing only their version number is not supported.

Platform profiles use ctx_parser 0.5 Commands declarations. Replace Profile::COMMANDS / Profile::PARSERS with Profile::DECLARATIONS.by_dimension / .parsers; instance query methods remain available. See the parser 0.5 migration.

About

Evidence-based network health checks and configuration diagnostics for Ruby

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages