77 "net"
88 "os"
99 "os/exec"
10- "sort"
11- "strconv"
1210 "strings"
1311 "sync"
1412 "time"
@@ -25,7 +23,6 @@ import (
2523 "github.com/openshift/osdctl/cmd/dynatrace"
2624 "github.com/openshift/osdctl/pkg/osdCloud"
2725 "github.com/openshift/osdctl/pkg/osdctlConfig"
28- "github.com/openshift/osdctl/pkg/printer"
2926 "github.com/openshift/osdctl/pkg/provider/pagerduty"
3027 "github.com/openshift/osdctl/pkg/utils"
3128 "github.com/spf13/cobra"
@@ -66,6 +63,16 @@ func (o ContextOptions) Validate() error {
6663 if o .Days < 1 {
6764 return fmt .Errorf ("cannot have a days value lower than 1" )
6865 }
66+ switch o .Output {
67+ case shortOutputConfigValue :
68+ return nil
69+ case longOutputConfigValue :
70+ return nil
71+ case jsonOutputConfigValue :
72+ return nil
73+ default :
74+ return fmt .Errorf ("unknown Output Format: %s" , o .Output )
75+ }
6976 return nil
7077}
7178
@@ -627,75 +634,6 @@ func GetCloudTrailLogsForCluster(awsProfile string, clusterID string, maxPages i
627634 return filteredEvents , nil
628635}
629636
630- func printHistoricalPDAlertSummary (incidentCounters map [string ][]* pagerduty.IncidentOccurrenceTracker , serviceIDs []string , sinceDays int , w io.Writer ) {
631- var name string = "PagerDuty Historical Alerts"
632- fmt .Fprintln (w , delimiter + name )
633-
634- for _ , serviceID := range serviceIDs {
635-
636- if len (incidentCounters [serviceID ]) == 0 {
637- fmt .Fprintln (w , "Service: https://redhat.pagerduty.com/service-directory/" + serviceID + ": None" )
638- continue
639- }
640-
641- fmt .Fprintln (w , "Service: https://redhat.pagerduty.com/service-directory/" + serviceID + ":" )
642- table := printer .NewTablePrinter (w , 20 , 1 , 3 , ' ' )
643- table .AddRow ([]string {"Type" , "Count" , "Last Occurrence" })
644- totalIncidents := 0
645- for _ , incident := range incidentCounters [serviceID ] {
646- table .AddRow ([]string {incident .IncidentName , strconv .Itoa (incident .Count ), incident .LastOccurrence })
647- totalIncidents += incident .Count
648- }
649-
650- // Add empty row for readability
651- table .AddRow ([]string {})
652- if err := table .Flush (); err != nil {
653- fmt .Fprintf (w , "Error printing %s: %v\n " , name , err )
654- }
655-
656- fmt .Fprintln (w , "\t Total number of incidents [" , totalIncidents , "] in [" , sinceDays , "] days" )
657- }
658- }
659-
660- func printJIRASupportExceptions (issues []jira.Issue , w io.Writer ) {
661- var name string = "Support Exceptions"
662- fmt .Fprintln (w , delimiter + name )
663-
664- for _ , i := range issues {
665- fmt .Fprintf (w , "[%s](%s/%s): %+v [Status: %s]\n " , i .Key , i .Fields .Type .Name , i .Fields .Priority .Name , i .Fields .Summary , i .Fields .Status .Name )
666- fmt .Fprintf (w , "- Link: %s/browse/%s\n \n " , JiraBaseURL , i .Key )
667- }
668-
669- if len (issues ) == 0 {
670- fmt .Fprintln (w , "None" )
671- }
672- }
673-
674- func printCloudTrailLogs (events []* types.Event , w io.Writer ) {
675- var name string = "Potentially interesting CloudTrail events"
676- fmt .Fprintln (w , delimiter + name )
677-
678- if events == nil {
679- fmt .Fprintln (w , "None" )
680- return
681- }
682-
683- table := printer .NewTablePrinter (w , 20 , 1 , 3 , ' ' )
684- table .AddRow ([]string {"EventId" , "EventName" , "Username" , "EventTime" })
685- for _ , event := range events {
686- if event .Username == nil {
687- table .AddRow ([]string {* event .EventId , * event .EventName , "" , event .EventTime .String ()})
688- } else {
689- table .AddRow ([]string {* event .EventId , * event .EventName , * event .Username , event .EventTime .String ()})
690- }
691- }
692- // Add empty row for readability
693- table .AddRow ([]string {})
694- if err := table .Flush (); err != nil {
695- fmt .Fprintf (w , "Error printing %s: %v\n " , name , err )
696- }
697- }
698-
699637// These are a list of skippable aws event types, as they won't indicate any modification on the customer's side.
700638func skippableEvent (eventName string ) bool {
701639 skippableList := []string {
@@ -717,87 +655,9 @@ func skippableEvent(eventName string) bool {
717655 return false
718656}
719657
720- func printNetworkInfo (data * contextData , w io.Writer ) {
721- var name = "Network Info"
722- fmt .Fprintln (w , delimiter + name )
723-
724- table := printer .NewTablePrinter (w , 20 , 1 , 3 , ' ' )
725- table .AddRow ([]string {"Network Type" , data .NetworkType })
726- table .AddRow ([]string {"MachineCIDR" , data .NetworkMachineCIDR })
727- table .AddRow ([]string {"ServiceCIDR" , data .NetworkServiceCIDR })
728- table .AddRow ([]string {"Max Services" , strconv .Itoa (data .NetworkMaxServices )})
729- table .AddRow ([]string {"PodCIDR" , data .NetworkPodCIDR })
730- table .AddRow ([]string {"Host Prefix" , strconv .Itoa (data .NetworkHostPrefix )})
731- table .AddRow ([]string {"Max Nodes (based on PodCIDR)" , strconv .Itoa (data .NetworkMaxNodesFromPodCIDR )})
732- table .AddRow ([]string {"Max pods per node" , strconv .Itoa (data .NetworkMaxPodsPerNode )})
733-
734- if err := table .Flush (); err != nil {
735- fmt .Fprintf (w , "Error printing %s: %v\n " , name , err )
736- }
737- }
738-
739- func printDynatraceResources (data * contextData , w io.Writer ) {
740- var name string = "Dynatrace Details"
741- fmt .Fprintln (w , delimiter + name )
742-
743- links := map [string ]string {
744- "Dynatrace Tenant URL" : data .DyntraceEnvURL ,
745- "Logs App URL" : data .DyntraceLogsURL ,
746- }
747-
748- // Sort, so it's always a predictable order
749- var keys []string
750- for k := range links {
751- keys = append (keys , k )
752- }
753- sort .Strings (keys )
754-
755- table := printer .NewTablePrinter (w , 20 , 1 , 3 , ' ' )
756- for _ , link := range keys {
757- url := strings .TrimSpace (links [link ])
758- if url == dynatrace .ErrUnsupportedCluster .Error () {
759- fmt .Fprintln (w , dynatrace .ErrUnsupportedCluster .Error ())
760- break
761- } else if url != "" {
762- table .AddRow ([]string {link , url })
763- }
764- }
765-
766- if err := table .Flush (); err != nil {
767- fmt .Fprintf (w , "Error printing %s: %v\n " , name , err )
768- }
769- }
770-
771- func printUserBannedStatus (data * contextData , w io.Writer ) {
772- var name string = "User Ban Details"
773- fmt .Fprintln (w , "\n " + delimiter + name )
774- if data .UserBanned {
775- fmt .Fprintln (w , "User is banned" )
776- fmt .Fprintf (w , "Ban code = %v\n " , data .BanCode )
777- fmt .Fprintf (w , "Ban description = %v\n " , data .BanDescription )
778- if data .BanCode == BanCodeExportControlCompliance {
779- fmt .Fprintln (w , "User banned due to export control compliance.\n Please follow the steps detailed here: https://github.com/openshift/ops-sop/blob/master/v4/alerts/UpgradeConfigSyncFailureOver4HrSRE.md#user-banneddisabled-due-to-export-control-compliance ." )
780- }
781- } else {
782- fmt .Fprintln (w , "User is not banned" )
783- }
784- }
785-
786658func (data * contextData ) printClusterHeader (w io.Writer ) {
787659 clusterHeader := fmt .Sprintf ("%s -- %s" , data .ClusterName , data .ClusterID )
788660 fmt .Fprintln (w , strings .Repeat ("=" , len (clusterHeader )))
789661 fmt .Fprintln (w , clusterHeader )
790662 fmt .Fprintln (w , strings .Repeat ("=" , len (clusterHeader )))
791663}
792-
793- func printSDNtoOVNMigrationStatus (data * contextData , w io.Writer ) {
794- name := "SDN to OVN Migration Status"
795- fmt .Fprintln (w , "\n " + delimiter + name )
796-
797- if data .SdnToOvnMigration != nil && data .MigrationStateValue == cmv1 .ClusterMigrationStateValueInProgress {
798- fmt .Fprintln (w , "SDN to OVN migration is in progress" )
799- return
800- }
801-
802- fmt .Fprintln (w , "No active SDN to OVN migrations" )
803- }
0 commit comments