-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from instana/events-api
first simple event API
- Loading branch information
Showing
4 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package instana | ||
|
||
type EventData struct { | ||
Title string `json:"title"` | ||
Text string `json:"text"` | ||
Duration int `json:"duration"` | ||
Severity int `json:"severity"` | ||
Plugin string `json:"plugin,omitempty"` | ||
ID string `json:"id,omitempty"` | ||
Host string `json:"host,omitempty"` | ||
} | ||
|
||
const ( | ||
ServicePlugin = "com.instana.forge.connection.http.logical.LogicalWebApp" | ||
ServiceHost = "" | ||
) | ||
|
||
func SendDefaultServiceEvent(title string, text string, severity int) { | ||
SendServiceEvent(sensor.serviceName, title, text, severity) | ||
} | ||
|
||
func SendServiceEvent(service string, title string, text string, severity int) { | ||
sendEvent(&EventData{ | ||
Title: title, | ||
Text: text, | ||
Duration: 0, | ||
Severity: severity, | ||
Plugin: ServicePlugin, | ||
ID: service, | ||
Host: ServiceHost}) | ||
} | ||
|
||
func SendHostEvent(title string, text string, severity int) { | ||
sendEvent(&EventData{ | ||
Title: title, | ||
Text: text, | ||
Duration: 0, | ||
Severity: severity}) | ||
} | ||
|
||
func sendEvent(event *EventData) { | ||
|
||
log.debug(event) | ||
|
||
//we do fire & forget here, because the whole pid dance isn't necessary to send events | ||
go sensor.agent.request(sensor.agent.makeURL(AgentEventURL), "POST", event) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/instana/golang-sensor" | ||
) | ||
|
||
const ( | ||
service = "golang-event" | ||
) | ||
|
||
func main() { | ||
instana.InitSensor(&instana.Options{ | ||
Service: service, | ||
LogLevel: instana.Debug}) | ||
|
||
go forever() | ||
select {} | ||
} | ||
|
||
func forever() { | ||
for { | ||
instana.SendDefaultServiceEvent("Event from the Golang sample", "{field: data}", -1) | ||
time.Sleep(5000 * time.Millisecond) | ||
} | ||
} |