Skip to content
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

feat: add uptime alerts commands #1431

Merged
merged 6 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,23 @@ const (
// ArgUptimeCheckEnabled is whether or not an uptime check is enabled.
ArgUptimeCheckEnabled = "enabled"

// ArgUptimeAlertName is the name of an uptime alert.
ArgUptimeAlertName = "name"
// ArgUptimeAlertType is the type of an uptime alert.
ArgUptimeAlertType = "type"
// ArgUptimeAlertThreshold the threshold at which an uptime alert will trigger.
ArgUptimeAlertThreshold = "threshold"
// ArgUptimeAlertComparison is the uptime alert comparator.
ArgUptimeAlertComparison = "comparison"
// ArgUptimeAlertEmails are the emails to send uptime alerts to.
ArgUptimeAlertEmails = "emails"
// ArgUptimeAlertSlackChannels are the Slack channels to send uptime alerts to.
ArgUptimeAlertSlackChannels = "slack-channels"
// ArgUptimeAlertSlackURLs are the Slack URLs to send uptime alerts to.
ArgUptimeAlertSlackURLs = "slack-urls"
// ArgUptimeAlertPeriod is the time threshold at which an uptime alert will trigger.
ArgUptimeAlertPeriod = "period"

// ArgVolumeSize is the size of a volume.
ArgVolumeSize = "size"
// ArgVolumeDesc is the description of a volume.
Expand Down
78 changes: 78 additions & 0 deletions commands/displayers/uptime_alert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Copyright 2023 The Doctl Authors All rights reserved.
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
http://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 displayers

import (
"io"
"strings"

"github.com/digitalocean/doctl/do"
)

type UptimeAlert struct {
UptimeAlerts []do.UptimeAlert
}

func (uc *UptimeAlert) JSON(out io.Writer) error {
return writeJSON(uc.UptimeAlerts, out)
}

func (uc *UptimeAlert) Cols() []string {
return []string{
"ID", "Name", "Type", "Threshold", "Comparison", "Period", "Emails", "Slack Channels",
}
}

func (ua *UptimeAlert) ColMap() map[string]string {
return map[string]string{
"ID": "ID",
"Name": "Name",
"Type": "Type",
"Threshold": "Threshold",
"Comparison": "Comparison",
"Period": "Period",
"Emails": "Emails",
"Slack Channels": "Slack Channels",
}
}

func (ua *UptimeAlert) KV() []map[string]interface{} {
out := make([]map[string]interface{}, 0, len(ua.UptimeAlerts))
for _, uptimeAlert := range ua.UptimeAlerts {
emails := ""
if uptimeAlert.Notifications.Email != nil {
emails = strings.Join(uptimeAlert.Notifications.Email, ",")
}
slackChannels := make([]string, 0)
if uptimeAlert.Notifications.Slack != nil {
for _, v := range uptimeAlert.Notifications.Slack {
slackChannels = append(slackChannels, v.Channel)
}
}
slacks := strings.Join(slackChannels, ",")

m := map[string]interface{}{
"ID": uptimeAlert.ID,
"Name": uptimeAlert.Name,
"Type": uptimeAlert.Type,
"Threshold": uptimeAlert.Threshold,
"Comparison": uptimeAlert.Comparison,
"Period": uptimeAlert.Period,
"Emails": emails,
"Slack Channels": slacks,
}
out = append(out, m)
}
return out
}
Loading
Loading