Documentation ¶
Index ¶
- Variables
- func GetAllRegions(clientAuth *model.Auth) ([]string, error)
- func GetCostperService(cmd *cobra.Command, clientAuth *model.Auth) (string, error)
- func GetTotalCostOfTheRegion(cmd *cobra.Command, clientAuth *model.Auth, region string) (*costexplorer.GetCostAndUsageOutput, error)
- func GetformatCostData(result *costexplorer.GetCostAndUsageOutput) (string, string, int)
- type CostDataResponse
- type CostDetails
Constants ¶
This section is empty.
Variables ¶
View Source
var AwsxGetTotalCostOfTheRegion = &cobra.Command{ Use: "getTotalRegionCostData", Short: "Get cost of all cost of a region", Long: `Retrieve the total cost of specified region using AWS Cost Explorer.`, Run: func(cmd *cobra.Command, args []string) { authFlag, clientAuth, err := authenticate.AuthenticateCommand(cmd) if err != nil { log.Println("Error during authentication:", err) cmd.Help() return } if authFlag { regions, err := GetAllRegions(clientAuth) if err != nil { log.Println("Error fetching regions:", err) return } var costDataResponses []CostDataResponse for _, region := range regions { costData, err := GetTotalCostOfTheRegion(cmd, clientAuth, region) if err != nil { log.Println("Error getting cost data for region", region, ":", err) continue } totalCost, services, noofservices := GetformatCostData(costData) response := CostDataResponse{ Region: region, TotalCost: totalCost, Services: services, NoOfServices: noofservices, } costDataResponses = append(costDataResponses, response) } responseJSON, err := json.Marshal(costDataResponses) if err != nil { log.Println("Error marshaling response:", err) return } fmt.Println(string(responseJSON)) } else { log.Println("Authentication failed. Exiting...") } }, }
View Source
var GetCostDataCmd = &cobra.Command{ Use: "get all cost over view", Short: "Get cost of all services", Long: `Retrieve the cost for all services using AWS Cost Explorer.`, Run: func(cmd *cobra.Command, args []string) { authFlag, clientAuth, err := authenticate.AuthenticateCommand(cmd) if err != nil { log.Println("Error during authentication:", err) cmd.Help() return } if authFlag { responseType, _ := cmd.Flags().GetString("responseType") costData, err := GetCostperService(cmd, clientAuth) if err != nil { log.Println("Error getting EC2 cost data: ", err) return } if responseType == "frame" { fmt.Println(costData) } else { fmt.Println(costData) } } else { log.Println("Authentication failed. Exiting...") } }, }
Functions ¶
func GetCostperService ¶ added in v1.15.0
func GetTotalCostOfTheRegion ¶
func GetTotalCostOfTheRegion(cmd *cobra.Command, clientAuth *model.Auth, region string) (*costexplorer.GetCostAndUsageOutput, error)
func GetformatCostData ¶ added in v1.15.3
func GetformatCostData(result *costexplorer.GetCostAndUsageOutput) (string, string, int)
Types ¶
type CostDataResponse ¶ added in v1.15.3
Click to show internal directories.
Click to hide internal directories.