Skip to content

Commit

Permalink
Merge pull request #19 from WadeBarnes/feature/filter-alerts
Browse files Browse the repository at this point in the history
Add `--alerts` filter
  • Loading branch information
swcurran authored Sep 9, 2020
2 parents fab3ad9 + 494fda4 commit d043731
Showing 1 changed file with 11 additions and 2 deletions.
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))

0 comments on commit d043731

Please sign in to comment.