Skip to content

Commit 02cf782

Browse files
Merge pull request #395 from mjlshen/OSD-16953
Make osdctl cluster context HCP-aware for Splunk
2 parents 7ecbe77 + 27d6fdc commit 02cf782

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

cmd/cluster/context.go

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
87
"math"
98
"os"
109
"os/exec"
@@ -14,9 +13,10 @@ import (
1413
"time"
1514

1615
pd "github.com/PagerDuty/go-pagerduty"
17-
jira "github.com/andygrunwald/go-jira"
16+
"github.com/andygrunwald/go-jira"
1817
"github.com/aws/aws-sdk-go/service/cloudtrail"
1918
"github.com/openshift-online/ocm-cli/pkg/dump"
19+
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
2020
"github.com/openshift/osdctl/cmd/servicelog"
2121
sl "github.com/openshift/osdctl/internal/servicelog"
2222
"github.com/openshift/osdctl/pkg/osdCloud"
@@ -36,12 +36,16 @@ const (
3636
PagerDutyUserTokenConfigKey = "pd_user_token"
3737
PagerDutyTokenRegistrationUrl = "https://martindstone.github.io/PDOAuth/"
3838
PagerDutyTeamIDs = "team_ids"
39+
ClassicSplunkURL = "https://osdsecuritylogs.splunkcloud.com/en-US/app/search/search?q=search%%20index%%3D%%22%s%%22%%20clusterid%%3D%%22%s%%22\n\n"
40+
HCPSplunkURL = "https://osdsecuritylogs.splunkcloud.com/en-US/app/search/search?q=search%%20index%%3D%%22%s%%22%%20annotations.managed.openshift.io%%2Fhosted-cluster-id%%3Docm-%s-%s-%s\n\n"
3941
shortOutputConfigValue = "short"
4042
longOutputConfigValue = "long"
4143
jsonOutputConfigValue = "json"
4244
)
4345

4446
type contextOptions struct {
47+
cluster *cmv1.Cluster
48+
4549
output string
4650
verbose bool
4751
full bool
@@ -314,11 +318,11 @@ func (o *contextOptions) generateContextData() (*contextData, []error) {
314318
ocmClient := utils.CreateConnection()
315319
defer ocmClient.Close()
316320
cluster, err := utils.GetCluster(ocmClient, o.clusterID)
317-
318321
if err != nil {
319322
errors = append(errors, err)
320323
return nil, errors
321324
}
325+
o.cluster = cluster
322326

323327
data.ClusterName = cluster.Name()
324328
data.ClusterID = cluster.ID()
@@ -882,14 +886,30 @@ func (o *contextOptions) printOtherLinks(OCMEnv string) error {
882886
fmt.Println("============================================================")
883887
fmt.Println("External resources containing related cluster data")
884888
fmt.Println("============================================================")
885-
// Determine whether to use the prod or stage Splunk index
886-
splunkIndex := "openshift_managed_audit"
887-
if OCMEnv == "stage" {
888-
splunkIndex = "openshift_managed_audit_stage"
889-
}
890-
// Clusters in integration don't forward to splunk
891-
if OCMEnv != "integration" {
892-
fmt.Printf("Link to Splunk audit logs (set time in Splunk): https://osdsecuritylogs.splunkcloud.com/en-US/app/search/search?q=search%%20index%%3D%%22%s%%22%%20clusterid%%3D%%22%s%%22\n\n", splunkIndex, o.infraID)
889+
890+
// Determine the relevant Splunk URL
891+
if o.cluster.Hypershift().Enabled() {
892+
switch OCMEnv {
893+
case "production":
894+
url := fmt.Sprintf(HCPSplunkURL, "openshift_managed_hypershift_audit", "production", o.cluster.ID(), o.cluster.Name())
895+
fmt.Printf("Link to Splunk audit logs (set time in Splunk): %s", url)
896+
case "stage":
897+
url := fmt.Sprintf(HCPSplunkURL, "openshift_managed_hypershift_audit_stage", "staging", o.cluster.ID(), o.cluster.Name())
898+
fmt.Printf("Link to Splunk audit logs (set time in Splunk): %s", url)
899+
default:
900+
// Only stage and production clusters forward logs to Splunk
901+
}
902+
} else {
903+
switch OCMEnv {
904+
case "production":
905+
url := fmt.Sprintf(ClassicSplunkURL, "openshift_managed_audit", o.cluster.ID())
906+
fmt.Printf("Link to Splunk audit logs (set time in Splunk): %s", url)
907+
case "stage":
908+
url := fmt.Sprintf(ClassicSplunkURL, "openshift_managed_audit_stage", o.cluster.ID())
909+
fmt.Printf("Link to Splunk audit logs (set time in Splunk): %s", url)
910+
default:
911+
// Only stage and production clusters forward logs to Splunk
912+
}
893913
}
894914
fmt.Printf("Link to OHSS tickets: %s/issues/?jql=project%%20%%3D%%20OHSS%%20and%%20(%%22Cluster%%20ID%%22%%20~%%20%%20%%22%s%%22%%20OR%%20%%22Cluster%%20ID%%22%%20~%%20%%22%s%%22)\n\n", JiraBaseURL, o.clusterID, o.externalClusterID)
895915
fmt.Printf("Link to CCX dashboard: https://kraken.psi.redhat.com/clusters/%s\n\n", o.externalClusterID)

0 commit comments

Comments
 (0)