Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (47 sloc) 1.75 KB
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package snippets contains examples of using the monitoring API.
package snippets
// [START monitoring_alert_enable_channel]
import (
"context"
"fmt"
"io"
monitoring "cloud.google.com/go/monitoring/apiv3"
"github.com/golang/protobuf/ptypes/wrappers"
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
"google.golang.org/genproto/protobuf/field_mask"
)
// enableChannel enables the given channel. channelName should be of the form
// "projects/[PROJECT_ID]/notificationChannels/[CHANNEL_ID]".
func enableChannel(w io.Writer, channelName string) error {
ctx := context.Background()
client, err := monitoring.NewNotificationChannelClient(ctx)
if err != nil {
return err
}
req := &monitoringpb.UpdateNotificationChannelRequest{
UpdateMask: &field_mask.FieldMask{Paths: []string{"enabled"}},
NotificationChannel: &monitoringpb.NotificationChannel{
Name: channelName,
Enabled: &wrappers.BoolValue{Value: true},
},
}
if _, err := client.UpdateNotificationChannel(ctx, req); err != nil {
return fmt.Errorf("EnableNotificationChannel: %v", err)
}
fmt.Fprintf(w, "Enabled channel %q", channelName)
return nil
}
// [END monitoring_alert_enable_channel]
You can’t perform that action at this time.