Skip to content

Instantly share code, notes, and snippets.

@wshearn
Created April 30, 2019 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wshearn/c602d13f468bf43cd718604c01955412 to your computer and use it in GitHub Desktop.
Save wshearn/c602d13f468bf43cd718604c01955412 to your computer and use it in GitHub Desktop.
// CreateService creates a service in pagerduty for the specified clusterid and returns the service key
func (data *Data) CreateService() (string, error) {
client := pdApi.NewClient(data.APIKey)
escalationPolicy, err := client.GetEscalationPolicy(string(data.escalationPolicyID), nil)
if err != nil {
return "", errors.New("Escalation policy not found in PagerDuty")
}
clusterService := pdApi.Service{
Name: data.servicePrefix + "-" + data.ClusterID + "." + data.BaseDomain + "-hive-cluster",
Description: data.ClusterID + " - A managed hive created cluster",
EscalationPolicy: *escalationPolicy,
AutoResolveTimeout: &data.autoResolveTimeout,
AcknowledgementTimeout: &data.acknowledgeTimeOut,
}
newSvc, err := client.CreateService(clusterService)
if err != nil {
return "", err
}
venderSearch, err := client.ListVendors(pdApi.ListVendorOptions{Query: "Prometheus"})
if err != nil {
return "", err
}
promVendor, err := client.GetVendor(venderSearch.Vendors[0].ID)
if err != nil {
return "", err
}
promIntergration := pdApi.Integration{}
promIntergration.Vendor = &promVendor.APIObject
promIntergration.Type = "derpv2"
newIntergration, err := client.CreateIntegration(newSvc.ID, promIntergration)
if err != nil {
return "", err
}
return newIntergration.ID, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment