Skip to content

Implemented alert_notification management #3

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

Merged
merged 1 commit into from
Aug 16, 2017

Conversation

mvisonneau
Copy link
Contributor

This MR allows the configuration of the alert notifications.
Before merging I need to rebase after doing a govendor fetch github.com/apparentlymart/go-grafana-api once this MR onto the Grafana go library will have been merged : nytm/go-grafana-api#1

In the meantime feel free to let me know if I forgot something else, mandatory, in order to get this merged.

ie: tests works locally using the updated library

@mvisonneau
Copy link
Contributor Author

Manual acceptance testing :

~$ cat grafana.tf
resource "grafana_alert_notification" "test" {
  type          = "email"
  name          = "test"

  settings {
    "addresses" = "[email protected]"
  }
}

~$ terraform -v
Terraform v0.10.0

~$ terraform init

Initializing provider plugins...

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

~$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed. Cyan entries are data sources to be read.

Note: You didn't specify an "-out" parameter to save this plan, so when
"apply" is called, Terraform can't guarantee this is what will execute.

  + grafana_alert_notification.test
      is_default:         "false"
      name:               "test"
      settings.%:         "1"
      settings.addresses: "[email protected]"
      type:               "email"


Plan: 1 to add, 0 to change, 0 to destroy.


~$ terraform apply
grafana_alert_notification.test: Creating...
  is_default:         "" => "false"
  name:               "" => "test_notification"
  settings.%:         "0" => "1"
  settings.addresses: "" => "[email protected]"
  type:               "" => "email"
grafana_alert_notification.test: Creation complete (ID: 5)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

~$ curl -s -X GET https://grafana.example.net/api/alert-notifications/5 | jq
{
  "id": 5,
  "name": "test_notification",
  "type": "email",
  "isDefault": false,
  "settings": {
    "addresses": "[email protected]"
  },
  "created": "2017-08-15T17:08:22Z",
  "updated": "2017-08-15T17:08:22Z"
}


~$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

grafana_alert_notification.test: Refreshing state... (ID: 5)
No changes. Infrastructure is up-to-date.

This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, Terraform
doesn't need to do anything.

~$ terraform destroy
grafana_alert_notification.test: Refreshing state... (ID: 5)

The Terraform destroy plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning.
Resources shown in red will be destroyed.

  - grafana_alert_notification.test


Do you really want to destroy?
  Terraform will delete all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

grafana_alert_notification.test: Destroying... (ID: 5)
grafana_alert_notification.test: Destruction complete

Destroy complete! Resources: 1 destroyed.

~$ curl -s -X GET https://grafana.example.net/api/alert-notifications/5 | jq
null

@mvisonneau
Copy link
Contributor Author

API MR has been merged, thanks @apparentlymart ! I rebased, tests are now ok 👌

Copy link
Contributor

@grubernaut grubernaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good! Thanks for the contribution, just a few minor nits and changes.

}
}

func CreateAlertNotification(a *schema.ResourceData, meta interface{}) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor Nit: Conventionally we use d for *schema.ResourceData inside of the CRUD functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

"strconv"

"github.com/hashicorp/terraform/helper/schema"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

return ReadAlertNotification(a, meta)
}

func UpdateAlertNotification(a *schema.ResourceData, meta interface{}) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

return client.UpdateAlertNotification(alertNotification)
}

func ReadAlertNotification(a *schema.ResourceData, meta interface{}) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

@mvisonneau mvisonneau force-pushed the added_alert_notification branch 2 times, most recently from f701a46 to 041a556 Compare August 16, 2017 17:05
@mvisonneau
Copy link
Contributor Author

thanks @grubernaut, fixed the few comments!

@mvisonneau mvisonneau force-pushed the added_alert_notification branch from 041a556 to d1f008e Compare August 16, 2017 17:07
@grubernaut grubernaut merged commit 99dfec4 into grafana:master Aug 16, 2017
@mvisonneau mvisonneau deleted the added_alert_notification branch August 16, 2017 17:48
julienduchesne added a commit that referenced this pull request Dec 17, 2022
It's no longer possible to get users from the API in Grafana Cloud with 9.3.2
This test was kinda weird in any case, we were using the fixed ID of the `admin` user, which was probably ID #3 simply as an artifact of our Grafana Cloud process when launching instances
So I just removed the `user_id` permission from our test. It's not easy to run this test in a docker Grafana instance because it requires a Grafana Enterprise license
julienduchesne added a commit that referenced this pull request Dec 17, 2022
It's no longer possible to get users from the API in Grafana Cloud with 9.3.2
This test was kinda weird in any case, we were using the fixed ID of the `admin` user, which was probably ID #3 simply as an artifact of our Grafana Cloud process when launching instances
So I just removed the `user_id` permission from our test. It's not easy to run this test in a docker Grafana instance because it requires a Grafana Enterprise license
julienduchesne added a commit that referenced this pull request Dec 17, 2022
It's no longer possible to get users from the API in Grafana Cloud with 9.3.2
This test was kinda weird in any case, we were using the fixed ID of the `admin` user, which was probably ID #3 simply as an artifact of our Grafana Cloud process when launching instances
So I just removed the `user_id` permission from our test. It's not easy to run this test in a docker Grafana instance because it requires a Grafana Enterprise license
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

Successfully merging this pull request may close these issues.

2 participants