mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-09-07 07:12:52 +02:00
Implements structured JSON diagnostic output for node state export with full schema documentation. This feature provides machine-readable diagnostics for automated analysis, monitoring, and AI/MCP integration. Key changes: - Add `zerotier-cli diagnostic` command for JSON node state export - Add `zerotier-cli dump -j` as alias for JSON output - Add `zerotier-cli diagnostic --schema` to print JSON schema - Implement platform-specific interface collection (Linux, BSD, macOS, Windows) - Create modular diagnostic/ directory with isolated try/catch error handling - Add comprehensive JSON schema (diagnostic_schema.json) for validation - Include build-time schema embedding for offline access - Add Python and Rust scripts for schema embedding during build - Update build systems to compile new diagnostic modules The diagnostic output includes: - Node configuration and identity - Network memberships and settings - Interface states and IP addresses - Peer connections and statistics - Moon orbits - Controller networks (if applicable) All diagnostic collection is wrapped in try/catch blocks to ensure partial failures don't prevent overall output generation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
39 lines
No EOL
1.3 KiB
Rust
39 lines
No EOL
1.3 KiB
Rust
use std::env;
|
|
use std::fs;
|
|
use std::io::Write;
|
|
use std::path::Path;
|
|
|
|
fn main() {
|
|
let args: Vec<String> = env::args().collect();
|
|
if args.len() != 3 {
|
|
eprintln!("Usage: {} <input.json> <output.c>", args[0]);
|
|
std::process::exit(1);
|
|
}
|
|
let input_path = &args[1];
|
|
let output_path = &args[2];
|
|
|
|
let data = fs::read_to_string(input_path).expect("Failed to read input file");
|
|
// Minify JSON
|
|
let minified = match serde_json::from_str::<serde_json::Value>(&data) {
|
|
Ok(json) => serde_json::to_string(&json).unwrap_or(data.clone()),
|
|
Err(_) => data.clone(),
|
|
};
|
|
|
|
let escaped = minified
|
|
.replace('\\', "\\\\")
|
|
.replace('"', "\\\"")
|
|
.replace('\n', "\\n")
|
|
.replace('\r', "");
|
|
|
|
let header = "#include \"diagnostic_schema_embed.h\"\n\n";
|
|
let array_decl = format!(
|
|
"const char ZT_DIAGNOSTIC_SCHEMA_JSON[] = \"{}\";\n",
|
|
escaped
|
|
);
|
|
let len_decl = "const unsigned int ZT_DIAGNOSTIC_SCHEMA_JSON_LEN = sizeof(ZT_DIAGNOSTIC_SCHEMA_JSON) - 1;\n";
|
|
|
|
let mut out = fs::File::create(output_path).expect("Failed to create output file");
|
|
out.write_all(header.as_bytes()).unwrap();
|
|
out.write_all(array_decl.as_bytes()).unwrap();
|
|
out.write_all(len_decl.as_bytes()).unwrap();
|
|
}
|