|
16 | 16 | from scripts.correlator import build_correlation_timeline, fetch_correlated_logs |
17 | 17 | from scripts.job_parser import parse_job_log |
18 | 18 | from scripts.log_fetcher import fetch_job_log |
| 19 | + from scripts.setup import print_checks, run_checks |
19 | 20 | from scripts.step4_fetch_github import GitHubClient, Step4Analyzer |
20 | 21 | from scripts.tracing import HAS_MLFLOW, SpanType, mlflow, trace |
21 | 22 | else: |
|
24 | 25 | from .correlator import build_correlation_timeline, fetch_correlated_logs |
25 | 26 | from .job_parser import parse_job_log |
26 | 27 | from .log_fetcher import fetch_job_log |
| 28 | + from .setup import print_checks, run_checks |
27 | 29 | from .step4_fetch_github import GitHubClient, Step4Analyzer |
28 | 30 | from .tracing import HAS_MLFLOW, SpanType, mlflow, trace |
29 | 31 |
|
@@ -116,6 +118,7 @@ def upload_analysis_to_jumpbox(analysis_dir: Path, config: Config) -> bool: |
116 | 118 | print(f" Error uploading to Jumpbox: {e}") |
117 | 119 | return False |
118 | 120 |
|
| 121 | + |
119 | 122 | def get_step_name(step: int) -> str: |
120 | 123 | """Get descriptive name for step.""" |
121 | 124 | names = { |
@@ -219,13 +222,13 @@ def cmd_analyze(args: argparse.Namespace, config: Config, span=None) -> int: |
219 | 222 | return 1 |
220 | 223 |
|
221 | 224 | # Validate Splunk config |
222 | | - errors = config.validate_splunk() |
223 | | - if errors: |
224 | | - error_message = f"Splunk configuration invalid: {', '.join(errors)}" |
225 | | - print(f"Error: {error_message}") |
226 | | - if span: |
227 | | - span.set_outputs({"error": error_message}) |
228 | | - return 1 |
| 225 | + splunk_errors = config.validate_splunk() |
| 226 | + if splunk_errors: |
| 227 | + print(f"Warning: Splunk configuration invalid: {', '.join(splunk_errors)}") |
| 228 | + print( |
| 229 | + " Step 2 (Splunk log fetch) will be skipped. Set SPLUNK_HOST/SPLUNK_USERNAME/SPLUNK_PASSWORD in .claude/settings.json to enable." |
| 230 | + ) |
| 231 | + skip_splunk = bool(splunk_errors) |
229 | 232 |
|
230 | 233 | # GitHub token validation will be done at Step 4 (where it's actually needed) |
231 | 234 | github_errors = config.validate_github() |
@@ -256,17 +259,31 @@ def cmd_analyze(args: argparse.Namespace, config: Config, span=None) -> int: |
256 | 259 |
|
257 | 260 | # Step 2: Fetch Splunk logs |
258 | 261 | print("\n[Step 2] Fetching Splunk logs...") |
259 | | - try: |
260 | | - splunk_logs = fetch_correlated_logs(config, job_context) |
261 | | - step2_path = save_step(analysis_dir, 2, splunk_logs) |
262 | | - print(f" OCP logs: {len(splunk_logs.get('ocp_logs', []))}") |
263 | | - print(f" Error logs: {len(splunk_logs.get('error_logs', []))}") |
264 | | - print(f" Pods found: {len(splunk_logs.get('pods_found', []))}") |
265 | | - print(f" Output: {step2_path}") |
266 | | - except Exception as e: |
267 | | - print(f" Error fetching Splunk logs: {e}") |
268 | | - splunk_logs = {"ocp_logs": [], "error_logs": [], "pods_found": [], "errors": [str(e)]} |
| 262 | + if skip_splunk: |
| 263 | + print(" Skipped: Splunk not configured") |
| 264 | + splunk_logs = { |
| 265 | + "ocp_logs": [], |
| 266 | + "error_logs": [], |
| 267 | + "pods_found": [], |
| 268 | + "skipped": True, |
| 269 | + "reason": "Splunk not configured", |
| 270 | + } |
269 | 271 | save_step(analysis_dir, 2, splunk_logs) |
| 272 | + else: |
| 273 | + try: |
| 274 | + splunk_logs = fetch_correlated_logs(config, job_context) |
| 275 | + step2_path = save_step(analysis_dir, 2, splunk_logs) |
| 276 | + ocp_logs = splunk_logs.get("ocp_logs", []) |
| 277 | + error_logs = splunk_logs.get("error_logs", []) |
| 278 | + pods_found = splunk_logs.get("pods_found", []) |
| 279 | + print(f" OCP logs: {len(ocp_logs) if isinstance(ocp_logs, list) else 0}") |
| 280 | + print(f" Error logs: {len(error_logs) if isinstance(error_logs, list) else 0}") |
| 281 | + print(f" Pods found: {len(pods_found) if isinstance(pods_found, list) else 0}") |
| 282 | + print(f" Output: {step2_path}") |
| 283 | + except Exception as e: |
| 284 | + print(f" Error fetching Splunk logs: {e}") |
| 285 | + splunk_logs = {"ocp_logs": [], "error_logs": [], "pods_found": [], "errors": [str(e)]} |
| 286 | + save_step(analysis_dir, 2, splunk_logs) |
270 | 287 |
|
271 | 288 | # Step 3: Build correlation |
272 | 289 | print("\n[Step 3] Building correlation timeline...") |
@@ -447,6 +464,20 @@ def cmd_query(args: argparse.Namespace, config: Config, span=None) -> int: |
447 | 464 | return 0 |
448 | 465 |
|
449 | 466 |
|
| 467 | +def cmd_setup(args: argparse.Namespace, config: Config, span=None) -> int: |
| 468 | + """Run preflight checks for all prerequisites.""" |
| 469 | + base_dir = Path(__file__).parent.parent |
| 470 | + repo_root = base_dir.parent.parent # skills/ -> repo root |
| 471 | + results = run_checks(base_dir, repo_root) |
| 472 | + |
| 473 | + if getattr(args, "json", False): |
| 474 | + print(json.dumps(results, indent=2)) |
| 475 | + return 0 if all(r["status"] == "ok" for r in results) else 1 |
| 476 | + |
| 477 | + issues = print_checks(results) |
| 478 | + return 0 if issues == 0 else 1 |
| 479 | + |
| 480 | + |
450 | 481 | def cmd_status(args: argparse.Namespace, config: Config, span=None) -> int: |
451 | 482 | """Show analysis status for a job.""" |
452 | 483 | analysis_dir = config.analysis_dir / args.job_id |
@@ -526,6 +557,10 @@ def main() -> int: |
526 | 557 | ) |
527 | 558 | query_parser.add_argument("--output", "-o", help="Output file (default: print summary)") |
528 | 559 |
|
| 560 | + # setup command |
| 561 | + setup_parser = subparsers.add_parser("setup", help="Check prerequisites and configuration") |
| 562 | + setup_parser.add_argument("--json", action="store_true", help="Output results as JSON") |
| 563 | + |
529 | 564 | # status command |
530 | 565 | status_parser = subparsers.add_parser("status", help="Show analysis status") |
531 | 566 | status_parser.add_argument("job_id", help="Job ID to check") |
@@ -559,6 +594,7 @@ def main() -> int: |
559 | 594 | "analyze": cmd_analyze, |
560 | 595 | "parse": cmd_parse, |
561 | 596 | "query": cmd_query, |
| 597 | + "setup": cmd_setup, |
562 | 598 | "status": cmd_status, |
563 | 599 | } |
564 | 600 |
|
|
0 commit comments