コード例 #1
0
 public void Dispose()
 {
     NotificationChannelClient.DeleteNotificationChannel(
         NotificationChannelName.Parse(Channel.Name), true);
     AlertPolicyClient.DeleteAlertPolicy(
         AlertPolicyName.Parse(Alert.Name));
 }
コード例 #2
0
    public NotificationChannel CreateChannel()
    {
        var channel = new NotificationChannel()
        {
            Type        = "email",
            DisplayName = "Email joe.",
            Description = "AlertTest.cs",
            Labels      = { { "email_address", "*****@*****.**" } },
            UserLabels  =
            {
                { "role",     "operations"               },
                { "level",    "5"                        },
                { "office",   "california_westcoast_usa" },
                { "division", "fulfillment"              }
            }
        };

        return(NotificationChannelClient.CreateNotificationChannel(
                   new ProjectName(ProjectId), channel));
    }
コード例 #3
0
        public AlertTestFixture()
        {
            var channel = new NotificationChannel()
            {
                Type        = "email",
                DisplayName = "Email joe.",
                Description = "AlertTest.cs",
                Labels      = { { "email_address", "*****@*****.**" } },
                UserLabels  =
                {
                    { "role",     "operations"               },
                    { "level",    "5"                        },
                    { "office",   "california_westcoast_usa" },
                    { "division", "fulfillment"              }
                }
            };

            Channel = NotificationChannelClient.CreateNotificationChannel(
                new ProjectName(ProjectId), channel);

            Alert = AlertPolicyClient.CreateAlertPolicy(
                new ProjectName(ProjectId), new AlertPolicy()
            {
                DisplayName = "AlertTest.cs",
                Enabled     = false,
                Combiner    = ConditionCombinerType.Or,
                Conditions  =
                {
                    new AlertPolicy.Types.Condition()
                    {
                        ConditionThreshold = new MetricThreshold()
                        {
                            Filter       = "metric.label.state=\"blocked\" AND metric.type=\"agent.googleapis.com/processes/count_by_state\"  AND resource.type=\"gce_instance\"",
                            Aggregations =
                            {
                                new Aggregation()
                                {
                                    AlignmentPeriod = Duration.FromTimeSpan(
                                        TimeSpan.FromSeconds(60)),
                                    PerSeriesAligner   = Aligner.AlignMean,
                                    CrossSeriesReducer = Reducer.ReduceMean,
                                    GroupByFields      =
                                    {
                                        "project",
                                        "resource.label.instance_id",
                                        "resource.label.zone"
                                    }
                                }
                            },
                            DenominatorFilter       = "",
                            DenominatorAggregations ={                  },
                            Comparison     = ComparisonType.ComparisonGt,
                            ThresholdValue = 100.0,
                            Duration       = Duration.FromTimeSpan(
                                TimeSpan.FromSeconds(900)),
                            Trigger = new Trigger()
                            {
                                Count   = 1,
                                Percent = 0.0,
                            }
                        },
                        DisplayName = "AlertTest.cs",
                    }
                },
            });
        }