Skip to content

Commit e44dbe0

Browse files
committed
Add console link to policy to CSV output
1 parent ac05f03 commit e44dbe0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

cmd/root.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package cmd
33
import (
44
"context"
55
"encoding/csv"
6+
"fmt"
67
"log"
78
"os"
89
"strconv"
10+
"strings"
911
"sync"
1012
"time"
1113

@@ -259,13 +261,13 @@ func Execute() {
259261
}
260262
defer csvFile.Close()
261263
csvWriter := csv.NewWriter(csvFile)
262-
err = csvWriter.Write([]string{"ProjectId", "Policy Name", "DisplayName", "Conditions", "Time Series", "Price", "Error"})
264+
err = csvWriter.Write([]string{"ProjectId", "Policy Name", "Link", "DisplayName", "Conditions", "Time Series", "Price", "Error"})
263265
if err != nil {
264266
log.Fatalln("Failed writing header to file", err)
265267
}
266268
csvWriter.Flush()
267269
for policy := range policiesOut {
268-
err = csvWriter.Write([]string{policy.ProjectId, policy.Name, policy.DisplayName, strconv.Itoa(policy.Conditions), strconv.Itoa(policy.TimeSeries), strconv.FormatFloat(policy.Price, 'f', 2, 64), policy.Error})
270+
err = csvWriter.Write([]string{policy.ProjectId, policy.Name, fmt.Sprintf("https://console.cloud.google.com/monitoring/alerting/policies/%s?project=%s", policy.Name[strings.LastIndex(policy.Name, "/")+1:], policy.ProjectId), policy.DisplayName, strconv.Itoa(policy.Conditions), strconv.Itoa(policy.TimeSeries), strconv.FormatFloat(policy.Price, 'f', 2, 64), policy.Error})
269271
if err != nil {
270272
log.Fatalln("Failed writing record to file", err)
271273
}

0 commit comments

Comments
 (0)