-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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 sample to update a cloud monitoring uptime check. #1508
Merged
SurferJeffAtGoogle
merged 2 commits into
GoogleCloudPlatform:master
from
SurferJeffAtGoogle:updateUptimeCheck
May 30, 2018
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,22 @@ def create_uptime_check_config(project_name, host_name=None, | |
# [END monitoring_uptime_check_create] | ||
|
||
|
||
# [START monitoring_uptime_check_update] | ||
def update_uptime_check_config(config_name, new_display_name=None, | ||
new_http_check_path=None): | ||
client = monitoring_v3.UptimeCheckServiceClient() | ||
config = client.get_uptime_check_config(config_name) | ||
field_mask = monitoring_v3.types.FieldMask() | ||
if new_display_name: | ||
field_mask.paths.append('display_name') | ||
config.display_name = new_display_name | ||
if new_http_check_path: | ||
field_mask.paths.append('http_check.path') | ||
config.http_check.path = new_http_check_path | ||
client.update_uptime_check_config(config, field_mask) | ||
# [END monitoring_uptime_check_update] | ||
|
||
|
||
# [START monitoring_uptime_check_list_configs] | ||
def list_uptime_check_configs(project_name): | ||
client = monitoring_v3.UptimeCheckServiceClient() | ||
|
@@ -153,6 +169,23 @@ def project_name(): | |
required=True, | ||
) | ||
|
||
update_uptime_check_config_parser = subparsers.add_parser( | ||
'update-uptime-check-config', | ||
help=update_uptime_check_config.__doc__ | ||
) | ||
update_uptime_check_config_parser.add_argument( | ||
'-m', '--name', | ||
required=True, | ||
) | ||
update_uptime_check_config_parser.add_argument( | ||
'-d', '--display_name', | ||
required=False, | ||
) | ||
update_uptime_check_config_parser.add_argument( | ||
'-p', '--uptime_check_path', | ||
required=False, | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
if args.command == 'list-uptime-check-configs': | ||
|
@@ -170,3 +203,11 @@ def project_name(): | |
|
||
elif args.command == 'delete-uptime-check-config': | ||
delete_uptime_check_config(args.name) | ||
|
||
elif args.command == 'update-uptime-check-config': | ||
if not args.display_name and not args.uptime_check_path: | ||
print("Nothing to update. Pass --display_name or " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: single-quotes for strings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
"--uptime_check_path.") | ||
else: | ||
update_uptime_check_config(args.name, args.display_name, | ||
args.uptime_check_path) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside: I find it slightly annoying that the autogen client doesn't take a list of strings for
field_mask
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.