def Run(self, args): util.ValidateUpdateArgsSpecified( args, ['policy', 'policy_from_file', 'display_name', 'enabled', 'add_notification_channels', 'remove_notification_channels', 'set_notification_channels', 'clear_notification_channels', 'documentation', 'documentation_format', 'documentation_from_file', 'fields', 'update_user_labels', 'remove_user_labels', 'clear_user_labels'], 'policy') flags.ValidateAlertPolicyUpdateArgs(args) client = policies.AlertPolicyClient() messages = client.messages passed_yaml_policy = False policy_ref = args.CONCEPTS.alert_policy.Parse() if args.policy or args.policy_from_file: passed_yaml_policy = True policy = util.GetBasePolicyMessageFromArgs(args, messages.AlertPolicy) else: # If a full policy isn't given, we want to do Read-Modify-Write. policy = client.Get(policy_ref) if not args.fields: channels = policy.notificationChannels new_channels = repeated.ParseResourceNameArgs( args, 'notification_channels', lambda: channels, util.ParseNotificationChannel) enabled = args.enabled if args.IsSpecified('enabled') else None fields = [] util.ModifyAlertPolicy( policy, messages, display_name=args.display_name, documentation_content= args.documentation or args.documentation_from_file, documentation_format=args.documentation_format, enabled=enabled, channels=new_channels, field_masks=fields) new_labels = util.ProcessUpdateLabels( args, 'user_labels', messages.AlertPolicy.UserLabelsValue, policy.userLabels) if new_labels: policy.userLabels = new_labels # TODO(b/73120276): Use field masks per key for label updates. fields.append('user_labels') # For more robust concurrent updates, use update masks if we're not # trying to replace the policy using --policy or --policy-from-file. fields = None if passed_yaml_policy else ','.join(sorted(fields)) else: fields = ','.join(args.fields) return client.Update(policy_ref, policy, fields)
def Run(self, args): client = policies.AlertPolicyClient() condition_ref = args.CONCEPTS.condition.Parse() policy_ref = condition_ref.Parent() policy = client.Get(policy_ref) condition = util.GetConditionFromPolicy(condition_ref.RelativeName(), policy) return condition
def Run(self, args): client = policies.AlertPolicyClient() messages = client.messages policy_ref = args.CONCEPTS.alert_policy.Parse() condition = util.GetConditionFromArgs(args, messages) policy = client.Get(policy_ref) policy.conditions.append(condition) response = client.Update(policy_ref, policy) return response
def Run(self, args): client = policies.AlertPolicyClient() condition_ref = args.CONCEPTS.condition.Parse() policy_ref = condition_ref.Parent() policy = client.Get(policy_ref) policy = util.RemoveConditionFromPolicy(condition_ref.RelativeName(), policy) response = client.Update(policy_ref, policy) log.DeletedResource(condition_ref.RelativeName(), 'Condition') return response
def Run(self, args): client = policies.AlertPolicyClient() messages = client.messages policy = util.CreateAlertPolicyFromArgs(args, client.messages) if args.user_labels: policy.userLabels = util.ParseCreateLabels( args.user_labels, messages.AlertPolicy.UserLabelsValue) project_ref = (projects_util.ParseProject( properties.VALUES.core.project.Get())) result = client.Create(project_ref, policy) log.CreatedResource(result.name, 'alert policy') return result
def Run(self, args): util.ValidateUpdateArgsSpecified( args, ['display_name', 'trigger_count', 'trigger_percent', 'if_value'], 'condition') client = policies.AlertPolicyClient() messages = client.messages condition_ref = args.CONCEPTS.condition.Parse() policy_ref = condition_ref.Parent() policy = client.Get(policy_ref) condition = util.GetConditionFromPolicy(condition_ref.RelativeName(), policy) nested_condition = condition.conditionAbsent or condition.conditionThreshold if args.display_name: condition.displayName = args.display_name if args.trigger_count or args.trigger_percent: nested_condition.trigger = messages.Trigger( count=args.trigger_count, percent=args.trigger_percent) if args.if_value is not None: # Copy existing condition properties into kwargs. kwargs = { 'trigger_count': nested_condition.trigger.count, 'trigger_percent': nested_condition.trigger.percent, 'aggregations': nested_condition.aggregations, 'duration': nested_condition.duration, 'condition_filter': nested_condition.filter, 'if_value': args.if_value } # If any trigger values are specified, overwrite whats in args. if args.trigger_count or args.trigger_percent: kwargs['trigger_count'] = args.trigger_count kwargs['trigger_percent'] = args.trigger_percent # Clear nested condition messages as this can potentially change. condition.conditionAbsent = None condition.conditionThreshold = None # This will change condition in place. util.BuildCondition(messages, condition=condition, **kwargs) return client.Update(policy_ref, policy, fields='conditions')