diff --git a/fetch-validator-status/fetch_status.py b/fetch-validator-status/fetch_status.py index 63af263..f8d7ce8 100644 --- a/fetch-validator-status/fetch_status.py +++ b/fetch-validator-status/fetch_status.py @@ -48,7 +48,7 @@ def seed_as_bytes(seed): return seed.encode("ascii") -async def fetch_status(genesis_path: str, nodes: str = None, ident: DidKey = None, status_only: bool = False): +async def fetch_status(genesis_path: str, nodes: str = None, ident: DidKey = None, status_only: bool = False, alerts_only: bool = False): pool = await open_pool(transactions_path=genesis_path) result = [] @@ -108,6 +108,14 @@ async def fetch_status(genesis_path: str, nodes: str = None, ident: DidKey = Non # Connection Issues await detect_connection_issues(result) + # Filter on alerts + if alerts_only: + filtered_result = [] + for item in result: + if ("info" in item["status"]) or ("warnings" in item["status"]) or ("errors" in item["status"]): + filtered_result.append(item) + result = filtered_result + print(json.dumps(result, indent=2)) @@ -307,6 +315,7 @@ def list_networks(): parser.add_argument("-s", "--seed", default=os.environ.get('SEED') , help="The privileged DID seed to use for the ledger requests. Can be specified using the 'SEED' environment variable.") parser.add_argument("-a", "--anonymous", action="store_true", help="Perform requests anonymously, without requiring privileged DID seed.") parser.add_argument("--status", action="store_true", help="Get status only. Suppresses detailed results.") + parser.add_argument("--alerts", action="store_true", help="Filter results based on alerts. Only return data for nodes containing detected 'info', 'warnings', or 'errors'.") parser.add_argument("--nodes", help="The comma delimited list of the nodes from which to collect the status. The default is all of the nodes in the pool.") parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose logging.") args = parser.parse_args() @@ -344,4 +353,4 @@ def list_networks(): else: ident = None - asyncio.get_event_loop().run_until_complete(fetch_status(args.genesis_path, args.nodes, ident, args.status)) \ No newline at end of file + asyncio.get_event_loop().run_until_complete(fetch_status(args.genesis_path, args.nodes, ident, args.status, args.alerts)) \ No newline at end of file