helper

package
v0.0.0-...-3e85251 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateCostsPerResourceGroup

func CalculateCostsPerResourceGroup(data []DailyBillingDetails) (map[string]float64, float64, error)

func GetCostsPerRGPrefix

func GetCostsPerRGPrefix(wantedPrefixes []string, allData []SubscriptionCosts) (map[string]float64, error)

getCostsPerPrefix takes costs that have already been retrieved and give summaries where particular prefixes are met. ie, will search for RG prefixes of "test-" for the testenv etc. Simply return a map of prefix and total for RGs matching that prefix.

Types

type AppInsightsConfig

type AppInsightsConfig struct {
	Env       string `json:"env"`
	Resources []struct {
		Name   string `json:"Name"`
		AppID  string `json:"AppID"`
		APIKey string `json:"APIKey"`
	} `json:"resources"`
}

type AppInsightsHelper

type AppInsightsHelper struct {
	// contains filtered or unexported fields
}

func NewAppInsightsHelper

func NewAppInsightsHelper(config AzureMonitoringConfigMap) *AppInsightsHelper

func (AppInsightsHelper) GetCPUAverage

func (aih AppInsightsHelper) GetCPUAverage(env string, appInsightsName string, spanInMinutes int, ch chan string)

GetCPUAverage gets the average CPU usage over a given time period. Will try and make this more generic it expands. Return the data via a channel

func (AppInsightsHelper) GetMemoryAverage

func (aih AppInsightsHelper) GetMemoryAverage(env string, appInsightsName string, spanInMinutes int, ch chan string)

GetMemoryAverage gets the average memory available over given span.

type AzureAppServiceHelper

type AzureAppServiceHelper struct {
	// contains filtered or unexported fields
}

func NewAzureAppServiceHelper

func NewAzureAppServiceHelper(subscriptionID string, tenantID string, clientID string, clientSecret string) *AzureAppServiceHelper

func (*AzureAppServiceHelper) GetAppServiceAppSettings

func (ah *AzureAppServiceHelper) GetAppServiceAppSettings(subscriptionID string, resourceGroup string, appServerName string) (*AzureAppSettings, error)

GetAppServiceAppSettings get app settings... get them all dammit!! Just return a map of string/string. No need for anything fancy.

func (*AzureAppServiceHelper) SetAppServiceAppSettings

func (ah *AzureAppServiceHelper) SetAppServiceAppSettings(subscriptionID string, resourceGroup string, appServerName string, appSettings AzureAppSettings) error

SetAppServiceAppSettings making bold assumption that key/value can always be strings.

type AzureAppSettings

type AzureAppSettings struct {
	ID         string            `json:"id"`
	Name       string            `json:"name"`
	Type       string            `json:"type"`
	Location   string            `json:"location"`
	Properties map[string]string `json:"properties"`
}

type AzureAuth

type AzureAuth struct {
	// contains filtered or unexported fields
}

func NewAzureAuth

func NewAzureAuth(tenantID string, clientID string, clientSecret string) *AzureAuth

func (*AzureAuth) CurrentToken

func (aa *AzureAuth) CurrentToken() AzureAuthToken

func (*AzureAuth) RefreshToken

func (aa *AzureAuth) RefreshToken() error

refreshToken checks the token, if it's going to expire in the next 30 seconds then it will refresh it.

type AzureAuthToken

type AzureAuthToken struct {
	TokenType    string `json:"token_type"`
	ExpiresIn    string `json:"expires_in"`
	ExtExpiresIn string `json:"ext_expires_in"`
	ExpiresOn    string `json:"expires_on"`
	NotBefore    string `json:"not_before"`
	Resource     string `json:"resource"`
	AccessToken  string `json:"access_token"`

	ExpiresOnTime time.Time // converted from string above. Don't want to make custom unmarshaller.
}

type AzureCost

type AzureCost struct {
	// contains filtered or unexported fields
}

func NewAzureCost

func NewAzureCost(tenantID string, clientID string, clientSecret string) AzureCost

func (*AzureCost) GenerateSubscriptionCostDetails

func (ac *AzureCost) GenerateSubscriptionCostDetails(subscriptionIDs []string, startDate time.Time, endDate time.Time) ([]SubscriptionCosts, error)

func (*AzureCost) GenerateSubscriptionCostDetailsSequential

func (ac *AzureCost) GenerateSubscriptionCostDetailsSequential(subscriptionIDs []string, startDate time.Time, endDate time.Time) ([]SubscriptionCosts, error)

func (*AzureCost) GetAllBillingForSubscriptionID

func (ac *AzureCost) GetAllBillingForSubscriptionID(subscriptionID string, startDate time.Time, endDate time.Time) ([]DailyBillingDetails, error)

just testing out ideas.... naming rocks.

type AzureMonitor

type AzureMonitor struct {
	Name              string                 `json:"Name"`
	SubscriptionID    string                 `json:"SubscriptionID"`
	TenantID          string                 `json:"TenantID"`
	ClientID          string                 `json:"ClientID"`
	ClientSecret      string                 `json:"ClientSecret"`
	ResourceToMonitor []AzureMonitorResource `json:"ResourceToMonitor"`
}

type AzureMonitorHelper

type AzureMonitorHelper struct {
	// contains filtered or unexported fields
}

used to get metrics via AzureMonitor (as opposed to app insights)

func NewAzureMonitorHelper

func NewAzureMonitorHelper(config AzureMonitoringConfigMap) *AzureMonitorHelper

NewAzureMonitorHelper does the Azure specifics....

func (*AzureMonitorHelper) GetMetrics

func (ah *AzureMonitorHelper) GetMetrics(env string, subscriptionID string, resourceGroup string, metricDefinition string, resourceName string, startTime time.Time, endTime time.Time, metricNamesSlice []string) (*MetricResponse, error)

func (*AzureMonitorHelper) GetResourceMetrics

func (ah *AzureMonitorHelper) GetResourceMetrics(env string, resourceFriendlyName string, resourceGroup string, resourceName string, metricDefinition string, metrics []string, spanInMinutes int, ch chan string)

type AzureMonitorResource

type AzureMonitorResource struct {
	Name             string   `json:"Name"`
	ResourceGroup    string   `json:"ResourceGroup"`
	ResourceName     string   `json:"ResourceName"`
	MetricDefinition string   `json:"MetricDefinition"`
	Metrics          []string `json:"Metrics"`
}

type AzureMonitoringConfig

type AzureMonitoringConfig struct {
	AzureMonitor []AzureMonitor `json:"AzureMonitor"`
	AppInsights  struct {
		Configs []AppInsightsConfig `json:"Configs"`
	} `json:"AppInsights"`
}

type AzureMonitoringConfigMap

type AzureMonitoringConfigMap struct {
	AzureMonitoringConfig

	// maps for app insights and azure monitor.... just for quick and easy lookup!
	AppInsightsMap  map[string]AppInsightsConfig
	AzureMonitorMap map[string]AzureMonitor
}

func LoadAzureMonitoringConfig

func LoadAzureMonitoringConfig(configFileName string) (*AzureMonitoringConfigMap, error)

type AzureSQLHelper

type AzureSQLHelper struct {
	// contains filtered or unexported fields
}

func NewAzureSQLHelper

func NewAzureSQLHelper(importSubscriptionID string, exportSubscriptionID string, tenantID string, clientID string, clientSecret string, sqlExportAdminLogin string, sqlExportAdminPassword string, sqlImportAdminLogin string, sqlImportAdminPassword string, storageKey string, storageURL string, exportSqlRgName string, importSqlRgName string, importStorageKey string) *AzureSQLHelper

func (*AzureSQLHelper) CreateDB

func (ah *AzureSQLHelper) CreateDB(importServerName string, databaseName string) error

CreateDB Creates DB https://docs.microsoft.com/en-us/rest/api/sql/databases/createorupdate#code-try-0

func (*AzureSQLHelper) DoesSQLFirewallRuleExist

func (ah *AzureSQLHelper) DoesSQLFirewallRuleExist(subscriptionID string, serverName string, resourceGroup string, firewallRule string) bool

DoesSQLFirewallRuleExist Checks if firewall rule exists. https://docs.microsoft.com/en-us/rest/api/sql/firewallrules/get

func (*AzureSQLHelper) StartDBExport

func (ah *AzureSQLHelper) StartDBExport(serverName string, databaseName string, backupFileName string) error

StartDBExport starts an export of an Azure DB to blob storage. https://docs.microsoft.com/en-us/rest/api/sql/databases%20-%20import%20export/export

func (*AzureSQLHelper) StartDBImport

func (ah *AzureSQLHelper) StartDBImport(importServerName string, databaseName string, backupBlobName string) error

StartDBImport starts to import from a blob backup file to a specific DB server and dbname keep to a default size for now. https://docs.microsoft.com/en-us/rest/api/sql/databases%20-%20import%20export/import

func (*AzureSQLHelper) UpdateSQLFirewall

func (ah *AzureSQLHelper) UpdateSQLFirewall(subscriptionID string, serverName string, resourceGroup string, firewallRule string, ip string) error

UpdateSQLFirewall will update a named firewall rule with a new IP address. https://docs.microsoft.com/en-us/rest/api/sql/firewallrules/createorupdate

type AzureVMHelper

type AzureVMHelper struct {
	// contains filtered or unexported fields
}

func NewAzureVMHelper

func NewAzureVMHelper(subscriptionID string, tenantID string, clientID string, clientSecret string, resourceGroup string) *AzureVMHelper

func (*AzureVMHelper) StartVM

func (ah *AzureVMHelper) StartVM(vmName string, rgName string) error

StartVM See https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/start for details

type BillingResponse

type BillingResponse struct {
	NextLink string                `json:"nextLink"`
	Value    []DailyBillingDetails `json:"value"`
}

type DailyBillingDetails

type DailyBillingDetails struct {
	ID         string      `json:"id"`
	Name       string      `json:"name"`
	Type       string      `json:"type"`
	Tags       interface{} `json:"tags"`
	Properties struct {
		BillingPeriodID         string      `json:"billingPeriodId"`
		UsageStart              time.Time   `json:"usageStart"`
		UsageEnd                time.Time   `json:"usageEnd"`
		InstanceID              string      `json:"instanceId"`
		InstanceName            string      `json:"instanceName"`
		InstanceLocation        string      `json:"instanceLocation"`
		MeterID                 string      `json:"meterId"`
		UsageQuantity           float64     `json:"usageQuantity"`
		PretaxCost              float64     `json:"pretaxCost"`
		Currency                string      `json:"currency"`
		IsEstimated             bool        `json:"isEstimated"`
		SubscriptionGUID        string      `json:"subscriptionGuid"`
		SubscriptionName        string      `json:"subscriptionName"`
		Product                 string      `json:"product"`
		ConsumedService         string      `json:"consumedService"`
		PartNumber              string      `json:"partNumber"`
		ResourceGUID            string      `json:"resourceGuid"`
		OfferID                 string      `json:"offerId"`
		ChargesBilledSeparately bool        `json:"chargesBilledSeparately"`
		MeterDetails            interface{} `json:"meterDetails"`
	} `json:"properties"`
}

type GithubHelper

type GithubHelper struct {
	// contains filtered or unexported fields
}

func NewGithubHelper

func NewGithubHelper(owner string, apikey string) *GithubHelper

func (*GithubHelper) AddLabelToIssue

func (gh *GithubHelper) AddLabelToIssue(repo string, issueID int, label string) error

func (*GithubHelper) AddLabelToPR

func (gh *GithubHelper) AddLabelToPR(repo string, prID int, label string) error

func (*GithubHelper) AddUserToIssue

func (gh *GithubHelper) AddUserToIssue(repo string, issueID int, user string) error

func (*GithubHelper) GetBranchesForRepo

func (gh *GithubHelper) GetBranchesForRepo(repo string) ([]*github.Branch, error)

GetBranchesForRepo get all pages until all branches returned. Should never be THAT many that this would cause an issue. (watch me eat these words)

func (*GithubHelper) GetIssue

func (gh *GithubHelper) GetIssue(repo string, issueID int) (*github.Issue, error)

func (*GithubHelper) GetIssueState

func (gh *GithubHelper) GetIssueState(repo string, issueID int) (string, error)

func (*GithubHelper) GetMergeCommentsBetweenCommits

func (gh *GithubHelper) GetMergeCommentsBetweenCommits(repo string, commit1 string, commit2 string) ([]string, error)

func (*GithubHelper) GetPR

func (gh *GithubHelper) GetPR(repo string, prID int) (*github.PullRequest, error)

type MetricResponse

type MetricResponse struct {
	Cost           int              `json:"cost"`
	Timespan       string           `json:"timespan"`
	Interval       string           `json:"interval"`
	Value          []ResourceMetric `json:"value"`
	Namespace      string           `json:"namespace"`
	Resourceregion string           `json:"resourceregion"`
}

type ResourceMetric

type ResourceMetric struct {
	ID   string `json:"id"`
	Type string `json:"type"`
	Name struct {
		Value          string `json:"value"`
		LocalizedValue string `json:"localizedValue"`
	} `json:"name"`
	Unit       string       `json:"unit"`
	Timeseries []TimeSeries `json:"timeseries"`
}

type SendgridHandler

type SendgridHandler struct {
	ApiKey string
}

SendgridHandler handles all things sendgrid...

func NewSendgridHandler

func NewSendgridHandler() *SendgridHandler

NewSendgridHandler creates a new instance of SendgridHandler

func (*SendgridHandler) CheckBlock

func (sg *SendgridHandler) CheckBlock(email string) ([]*SendgridResult, error)

CheckBlock checks if a block has been registered against the email address

func (*SendgridHandler) CheckBounce

func (sg *SendgridHandler) CheckBounce(email string) ([]*SendgridResult, error)

CheckBounce checks if a bounce has been registered against the email address

func (*SendgridHandler) CheckInvalid

func (sg *SendgridHandler) CheckInvalid(email string) ([]*SendgridResult, error)

CheckInvalid checks if an invalid email flag has been registered against the email address

func (*SendgridHandler) CheckSpam

func (sg *SendgridHandler) CheckSpam(email string) ([]*SpamReportResult, error)

CheckSpam checks if address has been marked as spammy

func (*SendgridHandler) DeleteBlock

func (sg *SendgridHandler) DeleteBlock(email string) error

DeleteBlock removes a block against an email addr.

func (*SendgridHandler) DeleteBounce

func (sg *SendgridHandler) DeleteBounce(email string) error

DeleteBounce removes a bounce against an email addr.

func (*SendgridHandler) DeleteInvalid

func (sg *SendgridHandler) DeleteInvalid(email string) error

DeleteInvalid removes an invalid mark against an email addr.

func (*SendgridHandler) DeleteSpam

func (sg *SendgridHandler) DeleteSpam(email string) error

DeleteSpam removes a spam against an email addr.

type SendgridResult

type SendgridResult struct {
	Created int    `json:"created"`
	Email   string `json:"email"`
	Reason  string `json:"reason"`
	Status  string `json:"status"`
}

SendgridResult is the result of queries to the Sengrid API.

type ServiceBusHelper

type ServiceBusHelper struct {
	ConnectionString string // connection string to servicebus
	// contains filtered or unexported fields
}

ServiceBusHelper handles all things sendgrid...

func NewServiceBusHelper

func NewServiceBusHelper() *ServiceBusHelper

NewServiceBusHelper creates a new instance of ServiceBusHelper

func (*ServiceBusHelper) CheckQueue

func (sb *ServiceBusHelper) CheckQueue(name string) (ServiceBusResponse, error)

CheckQueue checks queue for messages

func (*ServiceBusHelper) CheckTopic

func (sb *ServiceBusHelper) CheckTopic(name string) (ServiceBusResponse, error)

CheckTopic checks queue for messages

type ServiceBusResponse

type ServiceBusResponse struct {
	AllCountDetails map[string]*servicebus.CountDetails
}

type SpamReportResult

type SpamReportResult struct {
	Created int    `json:"created"`
	Email   string `json:"email"`
	IP      string `json:"ip"`
}

SpamReportResult returned info on SPAM reports for given email address.

type SubscriptionCosts

type SubscriptionCosts struct {
	SubscriptionID     string
	Total              float64 // total for subscription, not really concerted about using floats here.
	ResourceGroupCosts map[string]float64
}

func FilterDataBasedOnSubscription

func FilterDataBasedOnSubscription(allData []SubscriptionCosts, subIDs []string) []SubscriptionCosts

func NewSubscriptionCosts

func NewSubscriptionCosts(subscriptionID string) SubscriptionCosts

type TimeSeries

type TimeSeries struct {
	Metadatavalues []interface{} `json:"metadatavalues"`
	Data           []struct {
		TimeStamp time.Time `json:"timeStamp"` // we will get one of these per minute.
		Average   float64   `json:"average"`
	} `json:"data"`
}

Jump to

Keyboard shortcuts

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