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

Add support for attaching a Preset Alert to a View #26

Open
wosteven opened this issue Jul 30, 2021 · 7 comments
Open

Add support for attaching a Preset Alert to a View #26

wosteven opened this issue Jul 30, 2021 · 7 comments
Labels
enhancement New feature or request planned

Comments

@wosteven
Copy link

Hey !

How can i associate a view with an alert preset ?

I see that you can define a view and an alert separatly:

resource "logdna_view" "my_view" {
  name  = "Basic View"
  query = "level:debug my query"
}

resource "logdna_alert" "my_alert" {
  name = "My Preset Alert via Terraform"
  email_channel {
    emails          = ["test@logdna.com"]
    immediate       = "false"
    operator        = "presence"
    triggerlimit    = 15
    triggerinterval = "15m"
    terminal        = "true"
    timezone        = "Pacific/Samoa"
  }
}

But how can i make "my_view" use "my_alert" ?

I would expect to see something like:

resource "logdna_view" "my_view" {
  name  = "Basic View"
  query = "level:debug my query"
  **alerts = [ logdna_alert.my_alert ]**
}

I did not find an attribute in logdna_view or logdna_alert that would support that ? Or do i miss something ?

@mdeltito
Copy link
Member

Hi @wosteven

Views can have one or more alerting "channels" attached to them, which I think is what you're after. Here's an example of a View that has an email alert channel configured:

https://github.com/logdna/terraform-provider-logdna/blob/main/examples/view_with_email_alert.tf

@wosteven
Copy link
Author

Hi @mdeltito ,
we have seen that i can do that (kind of "inline" channels - specific to the view). But what's the point of being able to create a "logdna_alert" resource if i cannot attach this to a view in TF ? We wanna define a common alert channel and attach this to multiple views. And we only see this to be done atm by re-creating the exact channel in each view.

@mdeltito
Copy link
Member

@wosteven ah yes, we do have plans for allowing Preset Alerts to be attached to a View within the provider. Thanks for the clarification!

cc: @alfeng6

@mdeltito mdeltito added enhancement New feature or request planned labels Jul 30, 2021
@mdeltito mdeltito changed the title How to associate a view with an alert ? Add support for attaching a Preset Alert to a View Jul 30, 2021
@david-ly
Copy link
Contributor

david-ly commented Nov 1, 2021

@wosteven we recently added the ability to consume logdna_alert resources managed/created via Terraform as data sources which should support the functionality to define a "common" preset alert and reference it in any # of views. Refer to the docs here.

For your provided example, the HCL implementation would look something like:

resource "logdna_alert" "my_alert" {
  name = "My Preset Alert via Terraform"
  email_channel {
    emails          = ["test@logdna.com"]
    immediate       = "false"
    operator        = "presence"
    triggerlimit    = 15
    triggerinterval = "15m"
    terminal        = "true"
    timezone        = "Pacific/Samoa"
  }
}

data "logdna_alert" "my_alert_data" {
  # the `logdna_alert` resource named my_alert will have its `id` attribute set upon successful creation 
  # so the data is being pulled directly from the remote backend rather than the local config args
  presetid = logdna_alert.my_alert.id 
}

resource "logdna_view" "my_view" {
  name  = "Basic View"
  query = "level:debug my query"

  # populate the relevant channel args by accessing the attribute from the preset alert data
  email_channel = data.logdna_alert.my_alert_data.email_channel
  ...
}

@philippfrank
Copy link

@david-ly It seems this does not work for slack channels?

An argument named "slack_channel" is not expected here. Did you mean to define a block of type "slack_channel"?

@felipefzdz
Copy link

I've also tried with email_channel and that didn't work either:

An argument named "email_channel" is not expected here. Did you mean to define a block of type "email_channel"?

Might be that the whole preset attaching thing is broken at the moment?

@philippfrank
Copy link

philippfrank commented May 4, 2022

@mdeltito @david-ly What's the status on this. It's been this way for months and your documentation is certainly wrong. Is this a bug?

I checked the code: the functionality was added and documented back in '21: c87a6cc

The view's slack_channel attribute is of type schema.ListType: c87a6cc#diff-0b4c49f154f7dc1f04a503de890c274c777876182f3bd5e499113009e172e19fR259

Might that be the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request planned
Projects
None yet
Development

No branches or pull requests

5 participants