mirror of https://github.com/hashicorp/terraform
provider/ns1: Add notify list resource (#12373)
* Allow for local development with ns1 provider. * Adds first implementation of ns1 notification list resource. * NS1 record.use_client_subnet defaults to true, and added test for field. * Adds more test cases for monitoring jobs. * Adds webhook/datafeed notifier types and acctests for notifylists. * Adds docs for notifylists resource. * Updates ns1-go rest client via govendor * Fix typos in record docspull/12457/head
parent
120e3af178
commit
ce633f2321
@ -0,0 +1,140 @@
|
||||
package ns1
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
|
||||
ns1 "gopkg.in/ns1/ns1-go.v2/rest"
|
||||
"gopkg.in/ns1/ns1-go.v2/rest/model/monitor"
|
||||
)
|
||||
|
||||
func notifyListResource() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"notifications": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"type": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"config": &schema.Schema{
|
||||
Type: schema.TypeMap,
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Create: NotifyListCreate,
|
||||
Read: NotifyListRead,
|
||||
Update: NotifyListUpdate,
|
||||
Delete: NotifyListDelete,
|
||||
}
|
||||
}
|
||||
|
||||
func notifyListToResourceData(d *schema.ResourceData, nl *monitor.NotifyList) error {
|
||||
d.SetId(nl.ID)
|
||||
d.Set("name", nl.Name)
|
||||
|
||||
if len(nl.Notifications) > 0 {
|
||||
notifications := make([]map[string]interface{}, len(nl.Notifications))
|
||||
for i, n := range nl.Notifications {
|
||||
ni := make(map[string]interface{})
|
||||
ni["type"] = n.Type
|
||||
if n.Config != nil {
|
||||
ni["config"] = n.Config
|
||||
}
|
||||
notifications[i] = ni
|
||||
}
|
||||
d.Set("notifications", notifications)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceDataToNotifyList(nl *monitor.NotifyList, d *schema.ResourceData) error {
|
||||
nl.ID = d.Id()
|
||||
|
||||
if rawNotifications := d.Get("notifications").([]interface{}); len(rawNotifications) > 0 {
|
||||
ns := make([]*monitor.Notification, len(rawNotifications))
|
||||
for i, notificationRaw := range rawNotifications {
|
||||
ni := notificationRaw.(map[string]interface{})
|
||||
config := ni["config"].(map[string]interface{})
|
||||
|
||||
switch ni["type"].(string) {
|
||||
case "webhook":
|
||||
ns[i] = monitor.NewWebNotification(config["url"].(string))
|
||||
case "email":
|
||||
ns[i] = monitor.NewEmailNotification(config["email"].(string))
|
||||
case "datafeed":
|
||||
ns[i] = monitor.NewFeedNotification(config["sourceid"].(string))
|
||||
}
|
||||
}
|
||||
nl.Notifications = ns
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NotifyListCreate creates an ns1 notifylist
|
||||
func NotifyListCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ns1.Client)
|
||||
nl := monitor.NewNotifyList(d.Get("name").(string))
|
||||
|
||||
if err := resourceDataToNotifyList(nl, d); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := client.Notifications.Create(nl); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return notifyListToResourceData(d, nl)
|
||||
}
|
||||
|
||||
// NotifyListRead fetches info for the given notifylist from ns1
|
||||
func NotifyListRead(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ns1.Client)
|
||||
|
||||
nl, _, err := client.Notifications.Get(d.Id())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return notifyListToResourceData(d, nl)
|
||||
}
|
||||
|
||||
// NotifyListDelete deletes the given notifylist from ns1
|
||||
func NotifyListDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ns1.Client)
|
||||
|
||||
_, err := client.Notifications.Delete(d.Id())
|
||||
d.SetId("")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// NotifyListUpdate updates the notifylist with given parameters
|
||||
func NotifyListUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ns1.Client)
|
||||
|
||||
nl := monitor.NewNotifyList(d.Get("name").(string))
|
||||
|
||||
if err := resourceDataToNotifyList(nl, d); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := client.Notifications.Update(nl); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return notifyListToResourceData(d, nl)
|
||||
}
|
||||
@ -0,0 +1,158 @@
|
||||
package ns1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
|
||||
ns1 "gopkg.in/ns1/ns1-go.v2/rest"
|
||||
"gopkg.in/ns1/ns1-go.v2/rest/model/monitor"
|
||||
)
|
||||
|
||||
func TestAccNotifyList_basic(t *testing.T) {
|
||||
var nl monitor.NotifyList
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckNotifyListDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccNotifyListBasic,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckNotifyListExists("ns1_notifylist.test", &nl),
|
||||
testAccCheckNotifyListName(&nl, "terraform test"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccNotifyList_updated(t *testing.T) {
|
||||
var nl monitor.NotifyList
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckNotifyListDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccNotifyListBasic,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckNotifyListExists("ns1_notifylist.test", &nl),
|
||||
testAccCheckNotifyListName(&nl, "terraform test"),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
Config: testAccNotifyListUpdated,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckNotifyListExists("ns1_notifylist.test", &nl),
|
||||
testAccCheckNotifyListName(&nl, "terraform test"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccCheckNotifyListState(key, value string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
rs, ok := s.RootModule().Resources["ns1_notifylist.test"]
|
||||
if !ok {
|
||||
return fmt.Errorf("Not found: %s", "ns1_notifylist.test")
|
||||
}
|
||||
|
||||
if rs.Primary.ID == "" {
|
||||
return fmt.Errorf("No ID is set")
|
||||
}
|
||||
|
||||
p := rs.Primary
|
||||
if p.Attributes[key] != value {
|
||||
return fmt.Errorf(
|
||||
"%s != %s (actual: %s)", key, value, p.Attributes[key])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testAccCheckNotifyListExists(n string, nl *monitor.NotifyList) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
rs, ok := s.RootModule().Resources[n]
|
||||
|
||||
if !ok {
|
||||
return fmt.Errorf("Resource not found: %v", n)
|
||||
}
|
||||
|
||||
id := rs.Primary.ID
|
||||
if id == "" {
|
||||
return fmt.Errorf("ID is not set")
|
||||
}
|
||||
|
||||
client := testAccProvider.Meta().(*ns1.Client)
|
||||
|
||||
foundNl, _, err := client.Notifications.Get(id)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if foundNl.ID != id {
|
||||
return fmt.Errorf("Notify List not found want: %#v, got %#v", id, foundNl)
|
||||
}
|
||||
|
||||
*nl = *foundNl
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testAccCheckNotifyListDestroy(s *terraform.State) error {
|
||||
client := testAccProvider.Meta().(*ns1.Client)
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "ns1_notifylist" {
|
||||
continue
|
||||
}
|
||||
|
||||
nl, _, err := client.Notifications.Get(rs.Primary.Attributes["id"])
|
||||
|
||||
if err == nil {
|
||||
return fmt.Errorf("Notify List still exists %#v: %#v", err, nl)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func testAccCheckNotifyListName(nl *monitor.NotifyList, expected string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
if nl.Name != expected {
|
||||
return fmt.Errorf("Name: got: %#v want: %#v", nl.Name, expected)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
const testAccNotifyListBasic = `
|
||||
resource "ns1_notifylist" "test" {
|
||||
name = "terraform test"
|
||||
notifications = {
|
||||
type = "webhook"
|
||||
config = {
|
||||
url = "http://localhost:9090"
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const testAccNotifyListUpdated = `
|
||||
resource "ns1_notifylist" "test" {
|
||||
name = "terraform test"
|
||||
notifications = {
|
||||
type = "webhook"
|
||||
config = {
|
||||
url = "http://localhost:9091"
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
@ -1,11 +0,0 @@
|
||||
.PHONY: all clean
|
||||
|
||||
all: .git/hooks/pre-commit
|
||||
go build .
|
||||
|
||||
clean:
|
||||
rm -f terraform-provider-nsone
|
||||
|
||||
.git/hooks/pre-commit:
|
||||
if [ ! -f .git/hooks/pre-commit ]; then ln -s ../../git-hooks/pre-commit .git/hooks/pre-commit; fi
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRateLimit(t *testing.T) {
|
||||
r := RateLimit{
|
||||
Limit: 10,
|
||||
Remaining: 10,
|
||||
Period: 10,
|
||||
}
|
||||
if r.WaitTime() != time.Second {
|
||||
t.Error("WaitTime is wrong duration ", r.WaitTime())
|
||||
}
|
||||
if r.PercentageLeft() != 100 {
|
||||
t.Error("PercentLeft != 100")
|
||||
}
|
||||
r.Remaining = 5
|
||||
if r.PercentageLeft() != 50 {
|
||||
t.Error("PercentLeft != 50")
|
||||
}
|
||||
if r.WaitTime() != time.Second {
|
||||
t.Error("WaitTime is wrong duration ", r.WaitTime())
|
||||
}
|
||||
if r.WaitTimeRemaining() != (time.Duration(2) * time.Second) {
|
||||
t.Error("WaitTimeRemaining is wrong duration ", r.WaitTimeRemaining())
|
||||
}
|
||||
}
|
||||
@ -1,117 +0,0 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUnmarshalUsers(t *testing.T) {
|
||||
d := []byte(`[
|
||||
{
|
||||
"permissions": {},
|
||||
"teams": [],
|
||||
"email": "support@nsone.net",
|
||||
"last_access": 1376325771.0,
|
||||
"notify": {
|
||||
"billing": true
|
||||
},
|
||||
"name": "API Example",
|
||||
"username": "apiexample"
|
||||
},
|
||||
{
|
||||
"permissions": {
|
||||
"dns": {
|
||||
"view_zones": true,
|
||||
"manage_zones": true,
|
||||
"zones_allow_by_default": false,
|
||||
"zones_deny": [],
|
||||
"zones_allow": ["example.com"]
|
||||
},
|
||||
"data": {
|
||||
"push_to_datafeeds": false,
|
||||
"manage_datasources": false,
|
||||
"manage_datafeeds": false
|
||||
},
|
||||
"account": {
|
||||
"manage_payment_methods": false,
|
||||
"manage_plan": false,
|
||||
"manage_teams": false,
|
||||
"manage_apikeys": false,
|
||||
"manage_account_settings": false,
|
||||
"view_activity_log": false,
|
||||
"view_invoices": false,
|
||||
"manage_users": false
|
||||
},
|
||||
"monitoring": {
|
||||
"manage_lists": false,
|
||||
"manage_jobs": false,
|
||||
"view_jobs": false
|
||||
}
|
||||
},
|
||||
"teams": ["520422919f782d37dffb588a"],
|
||||
"email": "newuser@example.com",
|
||||
"last_access": null,
|
||||
"notify": {
|
||||
"billing": true
|
||||
},
|
||||
"name": "New User",
|
||||
"username": "newuser"
|
||||
}
|
||||
]
|
||||
`)
|
||||
ul := []*User{}
|
||||
if err := json.Unmarshal(d, &ul); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.Equal(t, len(ul), 2, "Userlist should have 2 users")
|
||||
|
||||
u := ul[0]
|
||||
assert.Equal(t, u.TeamIDs, []string{}, "User should have empty teams")
|
||||
assert.Equal(t, u.Email, "support@nsone.net", "User wrong email")
|
||||
assert.Equal(t, u.LastAccess, 1376325771.0, "User wrong last access")
|
||||
assert.Equal(t, u.Name, "API Example", "User wrong name")
|
||||
assert.Equal(t, u.Username, "apiexample", "User wrong username")
|
||||
assert.Equal(t, u.Notify, NotificationSettings{true}, "User wrong notify")
|
||||
assert.Equal(t, u.Permissions, PermissionsMap{}, "User should have empty permissions")
|
||||
|
||||
u2 := ul[1]
|
||||
assert.Equal(t, u2.TeamIDs, []string{"520422919f782d37dffb588a"}, "User should have empty teams")
|
||||
assert.Equal(t, u2.Email, "newuser@example.com", "User wrong email")
|
||||
assert.Equal(t, u2.LastAccess, 0.0, "User wrong last access")
|
||||
assert.Equal(t, u2.Name, "New User", "User wrong name")
|
||||
assert.Equal(t, u2.Username, "newuser", "User wrong username")
|
||||
assert.Equal(t, u.Notify, NotificationSettings{true}, "User wrong notify")
|
||||
|
||||
permMap := PermissionsMap{
|
||||
DNS: PermissionsDNS{
|
||||
ViewZones: true,
|
||||
ManageZones: true,
|
||||
ZonesAllowByDefault: false,
|
||||
ZonesDeny: []string{},
|
||||
ZonesAllow: []string{"example.com"},
|
||||
},
|
||||
Data: PermissionsData{
|
||||
PushToDatafeeds: false,
|
||||
ManageDatasources: false,
|
||||
ManageDatafeeds: false,
|
||||
},
|
||||
Account: PermissionsAccount{
|
||||
ManagePaymentMethods: false,
|
||||
ManagePlan: false,
|
||||
ManageTeams: false,
|
||||
ManageApikeys: false,
|
||||
ManageAccountSettings: false,
|
||||
ViewActivityLog: false,
|
||||
ViewInvoices: false,
|
||||
ManageUsers: false,
|
||||
},
|
||||
Monitoring: PermissionsMonitoring{
|
||||
ManageLists: false,
|
||||
ManageJobs: false,
|
||||
ViewJobs: false,
|
||||
},
|
||||
}
|
||||
assert.Equal(t, u2.Permissions, permMap, "User wrong permissions")
|
||||
}
|
||||
@ -1,70 +0,0 @@
|
||||
package data_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/ns1/ns1-go.v2/rest/model/data"
|
||||
)
|
||||
|
||||
func ExampleSource() {
|
||||
// Construct an NSONE API data source.
|
||||
source := data.NewSource("my api source", "nsone_v1")
|
||||
fmt.Println(source.ID) // will be empty string
|
||||
fmt.Println(source.Name)
|
||||
fmt.Println(source.Type)
|
||||
// Output:
|
||||
// my api source
|
||||
// nsone_v1
|
||||
}
|
||||
|
||||
func ExampleFeed() {
|
||||
|
||||
// Construct the london data feed.
|
||||
feed := data.NewFeed(
|
||||
"London Feed",
|
||||
data.Config{"label": "London-UK"})
|
||||
fmt.Println(feed.ID) // will be empty string
|
||||
fmt.Println(feed.Name)
|
||||
fmt.Println(feed.Config)
|
||||
// Output:
|
||||
// London Feed
|
||||
// map[label:London-UK]
|
||||
}
|
||||
|
||||
func ExampleMeta() {
|
||||
feedID := "feed_id"
|
||||
|
||||
meta := data.Meta{}
|
||||
meta.Priority = 1
|
||||
meta.Up = data.FeedPtr{FeedID: feedID}
|
||||
fmt.Println(meta.Connections) // will be nil
|
||||
fmt.Println(meta.Priority)
|
||||
fmt.Println(meta.Up)
|
||||
// Output:
|
||||
// <nil>
|
||||
// 1
|
||||
// {feed_id}
|
||||
}
|
||||
|
||||
func ExampleRegions() {
|
||||
feedPtr := data.FeedPtr{FeedID: "feed_id"}
|
||||
|
||||
regions := data.Regions{}
|
||||
// Set a regions' 'up' metavalue to false('down').
|
||||
regions["some_region"] = data.Region{
|
||||
Meta: data.Meta{Up: false},
|
||||
}
|
||||
// Set a regions' 'connections' metavalue to receive from a feed.
|
||||
regions["other_region"] = data.Region{
|
||||
Meta: data.Meta{Connections: feedPtr},
|
||||
}
|
||||
fmt.Println(regions["some_region"].Meta.Up)
|
||||
fmt.Println(regions["some_region"].Meta.Priority)
|
||||
fmt.Println(regions["other_region"].Meta.Connections)
|
||||
fmt.Println(regions["other_region"].Meta.Priority)
|
||||
// Output:
|
||||
// false
|
||||
// <nil>
|
||||
// {feed_id}
|
||||
// <nil>
|
||||
}
|
||||
@ -1,141 +0,0 @@
|
||||
package dns_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/ns1/ns1-go.v2/rest/model/data"
|
||||
"gopkg.in/ns1/ns1-go.v2/rest/model/dns"
|
||||
"gopkg.in/ns1/ns1-go.v2/rest/model/filter"
|
||||
)
|
||||
|
||||
func ExampleZone() {
|
||||
z := dns.NewZone("example.com")
|
||||
|
||||
fmt.Println(z)
|
||||
// Output:
|
||||
// example.com
|
||||
}
|
||||
|
||||
// Example references https://ns1.com/articles/primary-dns-with-ns1
|
||||
func ExamplePrimaryZone() {
|
||||
// Secondary/slave dns server info.
|
||||
secondary := dns.ZoneSecondaryServer{
|
||||
IP: "1.2.3.4",
|
||||
Port: 53,
|
||||
Notify: true,
|
||||
}
|
||||
|
||||
// Construct the primary/master zone.
|
||||
domain := "masterzone.example"
|
||||
|
||||
masterZone := dns.NewZone(domain)
|
||||
masterZone.MakePrimary(secondary)
|
||||
|
||||
b, _ := json.MarshalIndent(masterZone, "", " ")
|
||||
|
||||
fmt.Println(string(b))
|
||||
// Output:
|
||||
// {
|
||||
// "zone": "masterzone.example",
|
||||
// "primary": {
|
||||
// "enabled": true,
|
||||
// "secondaries": [
|
||||
// {
|
||||
// "ip": "1.2.3.4",
|
||||
// "port": 53,
|
||||
// "notify": true
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
func ExampleRecord() {
|
||||
// Construct the A record
|
||||
record := dns.NewRecord("test.com", "a", "A")
|
||||
record.TTL = 300
|
||||
|
||||
// Construct primary answer(higher priority)
|
||||
pAns := dns.NewAv4Answer("1.1.1.1")
|
||||
pAns.Meta.Priority = 1
|
||||
pAns.Meta.Up = data.FeedPtr{FeedID: "feed1_id"}
|
||||
|
||||
// Construct secondary answer(lower priority)
|
||||
sAns := dns.NewAv4Answer("2.2.2.2")
|
||||
sAns.Meta.Priority = 2
|
||||
sAns.Meta.Up = data.FeedPtr{FeedID: "feed2_id"}
|
||||
|
||||
// Add both answers to record
|
||||
record.AddAnswer(pAns)
|
||||
record.AddAnswer(sAns)
|
||||
|
||||
// Construct and add both filters to the record(ORDER MATTERS)
|
||||
record.AddFilter(filter.NewUp())
|
||||
record.AddFilter(filter.NewSelFirstN(1))
|
||||
|
||||
// Add region 'test' to record(set as down)
|
||||
record.Regions["test"] = data.Region{Meta: data.Meta{Up: false}}
|
||||
|
||||
fmt.Println(record)
|
||||
fmt.Println(record.TTL)
|
||||
|
||||
fmt.Println("Primary answer:")
|
||||
fmt.Println(record.Answers[0])
|
||||
fmt.Println(record.Answers[0].Meta.Priority)
|
||||
fmt.Println(record.Answers[0].Meta.Up)
|
||||
|
||||
fmt.Println("Secondary answer:")
|
||||
fmt.Println(record.Answers[1])
|
||||
fmt.Println(record.Answers[1].Meta.Priority)
|
||||
fmt.Println(record.Answers[1].Meta.Up)
|
||||
|
||||
fmt.Println("First Filter in Chain:")
|
||||
fmt.Println(record.Filters[0].Type)
|
||||
fmt.Println(record.Filters[0].Config)
|
||||
|
||||
fmt.Println("Second Filter in Chain:")
|
||||
fmt.Println(record.Filters[1].Type)
|
||||
fmt.Println(record.Filters[1].Config)
|
||||
|
||||
fmt.Println("Regions:")
|
||||
fmt.Println(record.Regions["test"].Meta.Up)
|
||||
|
||||
// Output:
|
||||
// a.test.com A
|
||||
// 300
|
||||
// Primary answer:
|
||||
// 1.1.1.1
|
||||
// 1
|
||||
// {feed1_id}
|
||||
// Secondary answer:
|
||||
// 2.2.2.2
|
||||
// 2
|
||||
// {feed2_id}
|
||||
// First Filter in Chain:
|
||||
// up
|
||||
// map[]
|
||||
// Second Filter in Chain:
|
||||
// select_first_n
|
||||
// map[N:1]
|
||||
// Regions:
|
||||
// false
|
||||
}
|
||||
|
||||
func ExampleRecordLink() {
|
||||
// Construct the src record
|
||||
srcRecord := dns.NewRecord("test.com", "a", "A")
|
||||
srcRecord.TTL = 300
|
||||
srcRecord.Meta.Priority = 2
|
||||
|
||||
linkedRecord := dns.NewRecord("test.com", "l", "A")
|
||||
linkedRecord.LinkTo(srcRecord.Domain)
|
||||
fmt.Println(linkedRecord)
|
||||
fmt.Println(linkedRecord.Meta)
|
||||
fmt.Println(linkedRecord.Answers)
|
||||
// Output:
|
||||
// l.test.com A
|
||||
// <nil>
|
||||
// []
|
||||
}
|
||||
@ -1,97 +0,0 @@
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUnmarshalJobs(t *testing.T) {
|
||||
data := []byte(`[
|
||||
{
|
||||
"id": "52a27d4397d5f07003fdbe7b",
|
||||
"config": {
|
||||
"host": "1.2.3.4"
|
||||
},
|
||||
"status": {
|
||||
"lga": {
|
||||
"since": 1389407609,
|
||||
"status": "up"
|
||||
},
|
||||
"global": {
|
||||
"since": 1389407609,
|
||||
"status": "up"
|
||||
},
|
||||
"sjc": {
|
||||
"since": 1389404014,
|
||||
"status": "up"
|
||||
}
|
||||
},
|
||||
"rules": [
|
||||
{
|
||||
"key": "rtt",
|
||||
"value": 100,
|
||||
"comparison": "<"
|
||||
}
|
||||
],
|
||||
"job_type": "ping",
|
||||
"regions": [
|
||||
"lga",
|
||||
"sjc"
|
||||
],
|
||||
"active": true,
|
||||
"frequency": 60,
|
||||
"policy": "quorum",
|
||||
"region_scope": "fixed"
|
||||
}
|
||||
]`)
|
||||
mjl := []*Job{}
|
||||
if err := json.Unmarshal(data, &mjl); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if len(mjl) != 1 {
|
||||
fmt.Println(mjl)
|
||||
t.Error("Do not have any jobs")
|
||||
}
|
||||
j := mjl[0]
|
||||
if j.ID != "52a27d4397d5f07003fdbe7b" {
|
||||
t.Error("Wrong ID")
|
||||
}
|
||||
conf := j.Config
|
||||
if conf["host"] != "1.2.3.4" {
|
||||
t.Error("Wrong host")
|
||||
}
|
||||
status := j.Status["global"]
|
||||
if status.Since != 1389407609 {
|
||||
t.Error("since has unexpected value")
|
||||
}
|
||||
if status.Status != "up" {
|
||||
t.Error("Status is not up")
|
||||
}
|
||||
r := j.Rules[0]
|
||||
assert.Equal(t, r.Key, "rtt", "RTT rule key is wrong")
|
||||
assert.Equal(t, r.Value.(float64), float64(100), "RTT rule value is wrong")
|
||||
if r.Comparison != "<" {
|
||||
t.Error("RTT rule comparison is wrong")
|
||||
}
|
||||
if j.Type != "ping" {
|
||||
t.Error("Jobtype is wrong")
|
||||
}
|
||||
if j.Regions[0] != "lga" {
|
||||
t.Error("First region is not lga")
|
||||
}
|
||||
if !j.Active {
|
||||
t.Error("Job is not active")
|
||||
}
|
||||
if j.Frequency != 60 {
|
||||
t.Error("Job frequency != 60")
|
||||
}
|
||||
if j.Policy != "quorum" {
|
||||
t.Error("Job policy is not quorum")
|
||||
}
|
||||
if j.RegionScope != "fixed" {
|
||||
t.Error("Job region scope is not fixed")
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
---
|
||||
layout: "ns1"
|
||||
page_title: "NS1: ns1_notifylist"
|
||||
sidebar_current: "docs-ns1-resource-notifylist"
|
||||
description: |-
|
||||
Provides a NS1 Notify List resource.
|
||||
---
|
||||
|
||||
# ns1\_notifylist
|
||||
|
||||
Provides a NS1 Notify List resource. This can be used to create, modify, and delete notify lists.
|
||||
|
||||
## Example Usage
|
||||
|
||||
```
|
||||
resource "ns1_notifylist" "nl" {
|
||||
name = "my notify list"
|
||||
notifications = {
|
||||
type = "webhook"
|
||||
config = {
|
||||
url = "http://www.mywebhook.com"
|
||||
}
|
||||
}
|
||||
|
||||
notifications = {
|
||||
type = "email"
|
||||
config = {
|
||||
email = "test@test.com"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Argument Reference
|
||||
|
||||
The following arguments are supported:
|
||||
|
||||
* `name` - (Required) The free-form display name for the notify list.
|
||||
* `notifications` - (Optional) A list of notifiers. All notifiers in a notification list will receive notifications whenever an event is send to the list (e.g., when a monitoring job fails). Notifiers are documented below.
|
||||
|
||||
Notify List Notifiers (`notifications`) support the following:
|
||||
|
||||
* `type` - (Required) The type of notifier. Available notifiers are indicated in /notifytypes endpoint.
|
||||
* `config` - (Required) Configuration details for the given notifier type.
|
||||
|
||||
Loading…
Reference in new issue