|  | 
|  | 1 | +/* | 
|  | 2 | +Copyright 2023 The Doctl Authors All rights reserved. | 
|  | 3 | +Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 4 | +you may not use this file except in compliance with the License. | 
|  | 5 | +You may obtain a copy of the License at | 
|  | 6 | +    http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 7 | +Unless required by applicable law or agreed to in writing, software | 
|  | 8 | +distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 9 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 10 | +See the License for the specific language governing permissions and | 
|  | 11 | +limitations under the License. | 
|  | 12 | +*/ | 
|  | 13 | + | 
|  | 14 | +package displayers | 
|  | 15 | + | 
|  | 16 | +import ( | 
|  | 17 | +	"io" | 
|  | 18 | +	"strings" | 
|  | 19 | + | 
|  | 20 | +	"github.com/digitalocean/doctl/do" | 
|  | 21 | +) | 
|  | 22 | + | 
|  | 23 | +type UptimeAlert struct { | 
|  | 24 | +	UptimeAlerts []do.UptimeAlert | 
|  | 25 | +} | 
|  | 26 | + | 
|  | 27 | +func (uc *UptimeAlert) JSON(out io.Writer) error { | 
|  | 28 | +	return writeJSON(uc.UptimeAlerts, out) | 
|  | 29 | +} | 
|  | 30 | + | 
|  | 31 | +func (uc *UptimeAlert) Cols() []string { | 
|  | 32 | +	return []string{ | 
|  | 33 | +		"ID", "Name", "Type", "Threshold", "Comparison", "Period", "Emails", "Slack Channels", | 
|  | 34 | +	} | 
|  | 35 | +} | 
|  | 36 | + | 
|  | 37 | +func (ua *UptimeAlert) ColMap() map[string]string { | 
|  | 38 | +	return map[string]string{ | 
|  | 39 | +		"ID":             "ID", | 
|  | 40 | +		"Name":           "Name", | 
|  | 41 | +		"Type":           "Type", | 
|  | 42 | +		"Threshold":      "Threshold", | 
|  | 43 | +		"Comparison":     "Comparison", | 
|  | 44 | +		"Period":         "Period", | 
|  | 45 | +		"Emails":         "Emails", | 
|  | 46 | +		"Slack Channels": "Slack Channels", | 
|  | 47 | +	} | 
|  | 48 | +} | 
|  | 49 | + | 
|  | 50 | +func (ua *UptimeAlert) KV() []map[string]interface{} { | 
|  | 51 | +	out := make([]map[string]interface{}, 0, len(ua.UptimeAlerts)) | 
|  | 52 | +	for _, uptimeAlert := range ua.UptimeAlerts { | 
|  | 53 | +		emails := "" | 
|  | 54 | +		if uptimeAlert.Notifications.Email != nil { | 
|  | 55 | +			emails = strings.Join(uptimeAlert.Notifications.Email, ",") | 
|  | 56 | +		} | 
|  | 57 | +		slackChannels := make([]string, 0) | 
|  | 58 | +		if uptimeAlert.Notifications.Slack != nil { | 
|  | 59 | +			for _, v := range uptimeAlert.Notifications.Slack { | 
|  | 60 | +				slackChannels = append(slackChannels, v.Channel) | 
|  | 61 | +			} | 
|  | 62 | +		} | 
|  | 63 | +		slacks := strings.Join(slackChannels, ",") | 
|  | 64 | + | 
|  | 65 | +		m := map[string]interface{}{ | 
|  | 66 | +			"ID":             uptimeAlert.ID, | 
|  | 67 | +			"Name":           uptimeAlert.Name, | 
|  | 68 | +			"Type":           uptimeAlert.Type, | 
|  | 69 | +			"Threshold":      uptimeAlert.Threshold, | 
|  | 70 | +			"Comparison":     uptimeAlert.Comparison, | 
|  | 71 | +			"Period":         uptimeAlert.Period, | 
|  | 72 | +			"Emails":         emails, | 
|  | 73 | +			"Slack Channels": slacks, | 
|  | 74 | +		} | 
|  | 75 | +		out = append(out, m) | 
|  | 76 | +	} | 
|  | 77 | +	return out | 
|  | 78 | +} | 
0 commit comments