Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --alerts filter #19

Merged
merged 1 commit into from
Sep 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions fetch-validator-status/fetch_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down Expand Up @@ -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))


Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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))
asyncio.get_event_loop().run_until_complete(fetch_status(args.genesis_path, args.nodes, ident, args.status, args.alerts))