Add --json output to the check command
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
5e560f4307
commit
826daa3ab7
2 changed files with 50 additions and 4 deletions
|
|
@ -146,7 +146,7 @@ def _reconcile_list(cfg: Config, store, args) -> int:
|
|||
return 1 if any_stale else 0
|
||||
|
||||
|
||||
def _cmd_check(cfg: Config) -> int:
|
||||
def _cmd_check(cfg: Config, as_json: bool = False) -> int:
|
||||
# One-shot: arm everything immediately, force the SUID scan.
|
||||
sentinel = Sentinel(cfg)
|
||||
sentinel.start_time = 0.0 # past the grace window
|
||||
|
|
@ -154,10 +154,15 @@ def _cmd_check(cfg: Config) -> int:
|
|||
if not sentinel.listener_baseline:
|
||||
sentinel.build_baselines()
|
||||
alerts = sentinel.sweep(force_suid=True)
|
||||
ordered = sorted(alerts, key=lambda x: -x.severity)
|
||||
if as_json:
|
||||
import json
|
||||
print(json.dumps([a.to_dict() for a in ordered], indent=2))
|
||||
return 0
|
||||
if not alerts:
|
||||
print("No alerts.")
|
||||
return 0
|
||||
for a in sorted(alerts, key=lambda x: -x.severity):
|
||||
for a in ordered:
|
||||
print(f"[{a.severity}] {a.signature:<14} {a.detail}")
|
||||
return 0
|
||||
|
||||
|
|
@ -172,7 +177,8 @@ def main(argv: list[str] | None = None) -> int:
|
|||
parser.add_argument("-c", "--config", help="path to TOML config")
|
||||
sub = parser.add_subparsers(dest="cmd")
|
||||
sub.add_parser("run", help="run the daemon loop (default)")
|
||||
sub.add_parser("check", help="run detectors once and print alerts")
|
||||
chk = sub.add_parser("check", help="run detectors once and print alerts")
|
||||
chk.add_argument("--json", action="store_true", help="emit alerts as JSON")
|
||||
bl = sub.add_parser(
|
||||
"baseline",
|
||||
help="rebuild baselines (default), or accept/revoke/list drift")
|
||||
|
|
@ -259,7 +265,7 @@ def main(argv: list[str] | None = None) -> int:
|
|||
return _cmd_baseline(cfg)
|
||||
return _cmd_reconcile(cfg, args)
|
||||
if args.cmd == "check":
|
||||
return _cmd_check(cfg)
|
||||
return _cmd_check(cfg, args.json)
|
||||
if args.cmd == "web":
|
||||
from .web import serve
|
||||
serve(cfg)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue