-
Notifications
You must be signed in to change notification settings - Fork 1
/
resource_event.go
73 lines (66 loc) · 1.63 KB
/
resource_event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"os"
"strconv"
"time"
"github.com/google/uuid"
"github.com/hashicorp/terraform/helper/schema"
scalyr "github.com/scalyr/terraform-provider-dataset/scalyr-go"
)
var u, _ = uuid.NewUUID()
var session = u.String()
func resourceEvent() *schema.Resource {
return &schema.Resource{
Read: resourceEventRead,
Create: resourceEventCreate,
Delete: resourceEventDelete,
Schema: map[string]*schema.Schema{
"parser": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
},
"message": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
},
"attributes": {
Type: schema.TypeMap,
ForceNew: true,
Optional: true,
},
},
}
}
func resourceEventRead(d *schema.ResourceData, meta interface{}) error {
d.SetId("")
return nil
}
func resourceEventDelete(d *schema.ResourceData, meta interface{}) error {
d.SetId("")
return nil
}
func resourceEventCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*scalyr.ScalyrConfig)
event := &scalyr.Event{}
event.Ts = strconv.FormatInt(time.Now().UnixNano(), 10)
event.Attrs = make(map[string]interface{})
if message, ok := d.GetOk("message"); ok {
event.Attrs["message"] = message
}
if parser, ok := d.GetOk("parser"); ok {
event.Attrs["parser"] = parser
} else {
event.Attrs["parser"] = "terraform"
}
if attrs, ok := d.GetOk("attributes"); ok {
for k, v := range attrs.(map[string]interface{}) {
event.Attrs[k] = v
}
}
hostname, _ := os.Hostname()
client.SendEvent(event, nil, session, &scalyr.SessionInfo{ServerID: hostname})
d.SetId(time.Now().UTC().String())
return nil
}