-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for get_event_series_list and sample app for it (#129)
* fix for get_event_series_list and sample app for it * fix for get_event_series_list and sample app for it * fix docstring * docstring tweak
- Loading branch information
Showing
3 changed files
with
84 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#! /usr/bin/env python3 | ||
import datetime | ||
import os | ||
import pprint | ||
import sys | ||
|
||
# Add the directory containing `polaris_client.py` to sys.path | ||
sys.path.append(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
from polaris_client import build_arg_parser, create_polaris_client | ||
|
||
pp = pprint.PrettyPrinter(indent=4) | ||
|
||
|
||
def get_todays_failed_events(client, cluster_ids=None): | ||
"""Fetch and return today's failed events for the passed clusters.""" | ||
end_time = datetime.datetime.now().isoformat() | ||
start_time = (datetime.datetime.now() - datetime.timedelta( | ||
days=1)).isoformat() | ||
return rubrik.get_event_series_list(cluster_ids=cluster_ids, | ||
status=["FAILURE"], | ||
start_time=start_time, | ||
end_time=end_time) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = build_arg_parser() | ||
parser.add_argument('-f', '--first', dest='first', | ||
help="Number of clusters to get events for", | ||
default=1, type=int) | ||
args = parser.parse_args() | ||
rubrik = create_polaris_client(args) | ||
|
||
clusters = rubrik.list_clusters(first=args.first) | ||
ids = [cluster['id'] for cluster in clusters] | ||
if len(ids) == 0: | ||
print("No clusters found.") | ||
sys.exit(0) | ||
# workaround for bug in list_clusters not honoring first=1 | ||
ids = ids[:args.first] | ||
print("Found {} cluster(s): {}".format(len(ids), ids)) | ||
events = get_todays_failed_events(rubrik, ids) | ||
print("Returned events : {}".format(len(events))) | ||
if len(events) > 0: | ||
print("Event 0 : {}".format(events[0])) |