Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot define immediate notification in notification rule step #84

Open
vthiery opened this issue Apr 14, 2021 · 2 comments
Open

Cannot define immediate notification in notification rule step #84

vthiery opened this issue Apr 14, 2021 · 2 comments

Comments

@vthiery
Copy link

vthiery commented Apr 14, 2021

I want to define a notification rule step for a "New Alert" with no delay (so that I immediately receive the notification). The Opsgenie API documentation indicates that the sendAfter field must be specified for New Alert and Assigned Alert notification rules:

Time period (in minute) when notification will be sent after. Valid and Mandatory only for New Alert and Assigned Alert notification rules. sendAfter parameter should be given as an object which has a timeAmount field that takes amount as minutes.

Nevertheless, specifying 0 as TimeAmount won't work because the field would be omitted:

type SendAfter struct {
	TimeAmount uint32 `json:"timeAmount,omitempty"`
	TimeUnit   string `json:"timeUnit,omitempty"`
}

On the other hand, the API is perfectly happy to receive 0.

Would simply removing omitempty be a viable solution?

@trabab
Copy link
Contributor

trabab commented Jun 9, 2021

You can use implementation similar to createRuleStep func to execute the above use case.

func NewNotifiactionClient() (*notification.Client, error) {
	config := client.Config{
		ApiKey:         "******",
		OpsGenieAPIURL: client.ApiUrl("*******"),
	}
	var alertCli, cliErr = notification.NewClient(&config)
	if cliErr != nil {
		message := "Can not create the alert client. " + cliErr.Error()
		return nil, errors.New(message)
	}
	return alertCli, nil
}

func createRuleStep() {
	var cli, _ = NewNotifiactionClient()
	var createRequest = notification.CreateRuleStepRequest{}

	createRequest.UserIdentifier = "123"

	createRequest.RuleId = "123"

	createRequest.Contact.To = "[email protected]"

	createRequest.Contact.MethodOfContact = og.Email
	b := true
	createRequest.Enabled = &b
	timeAmount := uint32(0)
	sendAfter := og.SendAfter{TimeAmount: &timeAmount, TimeUnit: "minutes"}

	createRequest.SendAfter = &sendAfter
	response, _ := cli.CreateRuleStep(nil, &createRequest)
	fmt.Printf("%+v\n", response)
}

@jwebb
Copy link

jwebb commented Aug 11, 2021

Any news on this? It's a one-line fix. (trabab's proposed workaround is not valid - cannot possibly compile - since TimeAmount is not a pointer.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants