"""Preview the CLI output without a real Graylog instance. Runs a handful of commands against the bundled fake Graylog 4.0 server so you can see the exact shape of the tables/JSON before pointing the tool at edu-master. python3 tests/demo.py """ import io import os import sys from contextlib import redirect_stdout HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.dirname(HERE)) sys.path.insert(0, HERE) from fake_graylog import JUDGE_MESSAGES, FakeGraylog # noqa: E402 from graylog_ops import cli # noqa: E402 COMMANDS = ( ["probe"], ["streams"], ["discover", "--range", "3600"], ["top-ips", "--field", "client_ip", "--query", "status:401", "--size", "5"], ["judge", "--range", "300", "--explain", "3"], ) def main(): server = FakeGraylog(messages=JUDGE_MESSAGES).start() base = ["--url", server.url, "--token", "testtoken"] try: for command in COMMANDS: print("=" * 78) print("$ graylog-ops " + " ".join(command)) print("-" * 78) captured = io.StringIO() with redirect_stdout(captured): cli.main(base + command) print(captured.getvalue().rstrip()) print() finally: server.stop() return 0 if __name__ == "__main__": sys.exit(main())