packagemainimport("bytes""crypto/rand""encoding/hex""encoding/json""net/http""os")constapi="https://api.example.com/organizations/<org>"// newKey returns a random idempotency key.funcnewKey()string{b:=make([]byte,16)rand.Read(b)returnhex.EncodeToString(b)}// call sends one request with the access token and a JSON body (or none).// An optional idempotency key is sent as the Idempotency-Key header.funccall(method,pathstring,bodyany,idempotencyKey...string)(*http.Response,error){varbufbytes.Bufferifbody!=nil{iferr:=json.NewEncoder(&buf).Encode(body);err!=nil{returnnil,err}}req,err:=http.NewRequest(method,api+path,&buf)iferr!=nil{returnnil,err}req.Header.Set("Authorization","Bearer "+os.Getenv("STREAMTIME_TOKEN"))req.Header.Set("Content-Type","application/json")iflen(idempotencyKey)>0{req.Header.Set("Idempotency-Key",idempotencyKey[0])}returnhttp.DefaultClient.Do(req)}
Add an alert channel
Go to Settings → Alert Channels and select Create Alert Channel.
Enter an Identifier and choose the Receiver Type.
Slack:Channel and Webhook URL. PagerDuty:Routing Key, and optionally URL, Client and Client URL. Webhook:URL, and optionally Proxy URL, basic auth or Auth Token.
The provider fills receiver_type from type when you leave it out. Webhook channels need url; PagerDuty channels need routing_key. The configuration is sensitive and kept in Terraform state. Changing the destination updates the channel in place; changing its identifier replaces it. terraform destroy removes the channel from Streamtime.