// NewEvent creates a new event from collectd's write_http endpoint JSON format // defaultDimensions are added to the event created, but will be overridden by any dimension // values in the JSON func NewEvent(e *JSONWriteFormat, defaultDimensions map[string]string) *event.Event { // if you add another dimension that we read from the json update this number const MaxCollectDDims = 6 dimensions := make(map[string]string, len(defaultDimensions)+MaxCollectDDims) for k, v := range defaultDimensions { dimensions[k] = v } eventType, usedParts := getReasonableMetricName(e, 0) addIfNotNullOrEmpty(dimensions, "plugin", true, e.Plugin) parseDimensionsOut(dimensions, true, e.TypeInstance, e.PluginInstance, e.Host) _, usedInMetricName := usedParts["type"] addIfNotNullOrEmpty(dimensions, "type", !usedInMetricName, e.TypeS) meta := make(map[string]interface{}, len(e.Meta)+2) for k, v := range e.Meta { meta[k] = v } _, exists := e.Meta["severity"] if !exists && e.Severity != nil { meta["severity"] = *e.Severity } _, exists = e.Meta["message"] if !exists && e.Message != nil { meta["message"] = *e.Message } timestamp := time.Unix(0, int64(float64(time.Second)**e.Time)) return event.NewWithMeta(eventType, "COLLECTD", dimensions, meta, timestamp) }
// Next returns a unique event func (d *EventSource) Next() *event.Event { d.mu.Lock() defer d.mu.Unlock() return event.NewWithMeta("imanotify.notify_instance", "COLLECTD", d.Dims, d.Meta, d.TimeSource()) }