azureeabilling

package module
v0.0.0-...-6f89ed0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2018 License: MIT Imports: 9 Imported by: 3

README

azure-ea-billing

A small GoLang package for retreiving billing data from the Azure Enterprise Agreement billing portal.

This is not a package that can retrieve billing information from traditional Azure subscriptions. This is only for enterprise agreements, as it talks to the EA billing portal (not the usual Azure billing portal.)

Usage

import "github.com/mhenderson-so/azure-ea-billing"

func main() {
	eab := azureeabilling.Config{
		EA:     12345678,  //Your EA Number
		APIKey: "abcdefg", //Your EA Billing API Key
	}

	resp, err := eab.GetUsageReports() //Fetches the usage reports from the EA portal
	if err != nil {
		fmt.Println(err)
		return
	}
    
	//Fetches a specific month from the EA billing portal
	reports := eab.GetMonthReportsCSV(resp.AvailableMonths[20], azureeabilling.DownloadForStructs)

	//Convert the CSV reports to GoLang structs so we can access the data easier
	structs, err := reports.ConvertToStructs()
	if err != nil {
		fmt.Println(err)
		return
	}
	for _, l := range structs.DetailReport {
		fmt.Println(*l)
	}
}

Supported reports

Any of the EA portal reports can be downloaded in CSV format (depending on what is avaliable in your EA portal).

The following two reports can be converted to structs:

  • Detail report
  • Price Sheet

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AvailableMonth

type AvailableMonth struct {
	LinkToDownloadDetailReport      string `json:"LinkToDownloadDetailReport"`
	LinkToDownloadPriceSheetReport  string `json:"LinkToDownloadPriceSheetReport"`
	LinkToDownloadStoreChargeReport string `json:"LinkToDownloadStoreChargeReport"`
	LinkToDownloadSummaryReport     string `json:"LinkToDownloadSummaryReport"`
	Month                           string `json:"Month"`
}

AvailableMonth is used in UsageReports for the details for a given month

type Config

type Config struct {
	BaseURI string
	EA      uint32
	APIKey  string
	// contains filtered or unexported fields
}

Config is the basic config struct for Azure EA billing

var AzureConfig Config

AzureConfig is the global for our configuration

func (*Config) GetMonthReportsCSV

func (ea *Config) GetMonthReportsCSV(month AvailableMonth, reports DownloadOption) *MonthDownloadCSV

GetMonthReportsCSV downloads the reports for a given month from the Azure billing portal, in CSV format. The DownloadOption parameter accepts a number generated by bitwise-or on the avaliable options (see DownloadOption) e.g. DownloadDetail|DownloadPricesheet

func (*Config) GetUsageReports

func (ea *Config) GetUsageReports() (*UsageReports, error)

GetUsageReports returns all of the reports that are present in the EA Billing API. This is usually your first call, as it returns an array of reports in .AvailableMonths, which is required for feeding into GetMonthReportCSV.

func (*Config) MakeAPIRequestEndpoint

func (ea *Config) MakeAPIRequestEndpoint(method, endpoint string) (*[]byte, error)

MakeAPIRequestEndpoint queries a specific API endpoint, such as "usage-reports", adding the rest of the URL, such as EA number, etc.

func (*Config) MakeAPIRequestRaw

func (ea *Config) MakeAPIRequestRaw(method, fullURL string) (*[]byte, error)

MakeAPIRequestRaw takes a full URL and adds the header keys (but expects a fully formed URL) including the EA number, etc

type DetailRow

type DetailRow struct {
	AccountOwnerID         string    `csv:"AccountOwnerId"`
	AccountName            string    `csv:"Account Name"`
	ServiceAdministratorID string    `csv:"ServiceAdministratorId"`
	SubscriptionID         string    `csv:"SubscriptionId"`
	SubscriptionGUID       string    `csv:"SubscriptionGuid"`
	SubscriptionName       string    `csv:"Subscription Name"`
	DateRaw                string    `csv:"Date"`
	Date                   time.Time `csv:"-"`
	Month                  int       `csv:"Month"`
	Day                    int       `csv:"Day"`
	Year                   int       `csv:"Year"`
	Product                string    `csv:"Product"`
	MeterID                string    `csv:"Meter ID"`
	MeterCategory          string    `csv:"Meter Category"`
	MeterSubCategory       string    `csv:"Meter Sub-Category"`
	MeterRegion            string    `csv:"Meter Region"`
	MeterName              string    `csv:"Meter Name"`
	ConsumedQuantity       float64   `csv:"Consumed Quantity"`
	ResourceRate           float64   `csv:"ResourceRate"`
	ExtendedCostRaw        string    `csv:"ExtendedCost"`
	ResourceLocation       string    `csv:"Resource Location"`
	ConsumedService        string    `csv:"Consumed Service"`
	InstanceID             string    `csv:"Instance ID"`
	ServiceInfo1           string    `csv:"ServiceInfo1"`
	ServiceInfo2           string    `csv:"ServiceInfo2"`
	AdditionalInfo         string    `csv:"AdditionalInfo"`
	Tags                   string    `csv:"Tags"`
	StoreServiceIdentifier string    `csv:"Store Service Identifier"`
	DepartmentName         string    `csv:"Department Name"`
	CostCenter             string    `csv:"Cost Center"`
	UnitOfMeasure          string    `csv:"Unit Of Measure"`
	ResourceGroup          string    `csv:"Resource Group"`
}

DetailRow contains the data of each row in the monthly account detail usage table

type DownloadOption

type DownloadOption int

DownloadOption is used as our enum to toggle which reports we do and don't want to download

const (
	// DownloadDetail - Download the detail report
	DownloadDetail DownloadOption = 1
	// DownloadPricesheet - Download the price sheet
	DownloadPricesheet DownloadOption = 2
	// DownloadStoreCharge - Download the store charge
	DownloadStoreCharge DownloadOption = 4
	// DownloadSummary - Download the summary
	DownloadSummary DownloadOption = 8
	// DownloadAll - Download all of the reports
	DownloadAll DownloadOption = DownloadDetail | DownloadPricesheet | DownloadStoreCharge | DownloadSummary
	// Download the reports that we have struct support for
	DownloadForStructs DownloadOption = DownloadDetail | DownloadPricesheet
)

type MonthDownloadCSV

type MonthDownloadCSV struct {
	DetailReport      string
	PriceSheetReport  string
	StoreChargeReport string
	SummaryReport     string
}

MonthDownloadCSV is the struct for downloaded reports in CSV format

func (*MonthDownloadCSV) ConvertToStructs

func (reps *MonthDownloadCSV) ConvertToStructs() (*MonthDownloadStructs, error)

ConvertToStructs takes an existing monthly CSV download set and converts it to something more usable

type MonthDownloadStructs

type MonthDownloadStructs struct {
	DetailReport     []*DetailRow
	PriceSheetReport []*PriceSheetRow
}

MonthDownloadStructs is the struct that contains other reports represented as structs

type PriceSheetRow

type PriceSheetRow struct {
	Service                string `csv:"Service"`
	UnitOfMeasure          string `csv:"Unit of Measure"`
	PartNumber             string `csv:"Part Number"`
	UnitPriceRaw           string `csv:"Unit Price"`
	UnitPrice              int    `csv:"-"`
	CommitmentPartNumber   string `csv:"Commitment Part Number"`
	CommitmentUnitPriceRaw string `csv:"Commitment Unit Price"`
	CommitmentUnitPrice    int    `csv:"-"`
	OveragePartNumber      string `csv:"Overage Part Number"`
	OverageUnitPriceRaw    string `csv:"Overage Unit Price"`
	OverageUnitPrice       int    `csv:"-"`

	CurrencyCode string `csv:"Currency Code"`
}

PriceSheetRow contains the data of each row in a price sheet table

type UsageReports

type UsageReports struct {
	AvailableMonths []AvailableMonth `json:"AvailableMonths"`
	ContractVersion string           `json:"ContractVersion"`
	ObjectType      string           `json:"ObjectType"`
}

UsageReports is the struct containing the list of reports avaliable

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL