Skip to content

Instantly share code, notes, and snippets.

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/ff7cff02f3ffee0d81d34450f8e9e50e to your computer and use it in GitHub Desktop.
Save wshearn/ff7cff02f3ffee0d81d34450f8e9e50e 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
}
clusterIntegration := pdApi.Integration{
Name: "Test",
Type: "events_api_v2_inbound_integration_reference",
}
newInt, err := client.CreateIntegration(newSvc.ID, clusterIntegration)
if err != nil {
return "", err
}
return newInt.ID, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment