Something went wrong. Try again.
Go port of clojure riemann
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145package riemann
import ( "time"
pb "go.iscode.ca/riemann/proto")
// ProtoToEvent converts a protobuf Event to an internal Event.func ProtoToEvent(pe *pb.Event) *Event { if pe == nil { return nil } e := &Event{} if pe.Time != nil && *pe.Time != 0 { e.Time = *pe.Time } else { e.Time = time.Now().Unix() } if pe.TimeMicros != nil && *pe.TimeMicros != 0 { e.TimeMicros = *pe.TimeMicros } else { e.TimeMicros = time.Now().UnixNano() / 1000 } if pe.State != nil { e.State = *pe.State } if pe.Service != nil { e.Service = *pe.Service } if pe.Host != nil { e.Host = *pe.Host } if pe.Description != nil { e.Description = *pe.Description } e.Tags = pe.Tags if pe.Ttl != nil { e.TTL = *pe.Ttl } if len(pe.Attributes) > 0 { e.Attributes = make(map[string]string) for _, attr := range pe.Attributes { if attr.Key != nil { val := "" if attr.Value != nil { val = *attr.Value } e.Attributes[*attr.Key] = val } } } if pe.MetricD != nil { e.Metric = *pe.MetricD } else if pe.MetricF != nil { e.Metric = *pe.MetricF } else if pe.MetricSint64 != nil { e.Metric = *pe.MetricSint64 } return e}
// EventToProto converts an internal Event to a protobuf Event.func EventToProto(e *Event) *pb.Event { if e == nil { return nil } pe := &pb.Event{ Tags: e.Tags, } if e.Time != 0 { pe.Time = &e.Time } if e.TimeMicros != 0 { pe.TimeMicros = &e.TimeMicros } if e.State != "" { pe.State = &e.State } if e.Service != "" { pe.Service = &e.Service } if e.Host != "" { pe.Host = &e.Host } if e.Description != "" { pe.Description = &e.Description } if e.TTL != 0 { pe.Ttl = &e.TTL } if len(e.Attributes) > 0 { for k, v := range e.Attributes { key := k val := v pe.Attributes = append(pe.Attributes, &pb.Attribute{ Key: &key, Value: &val, }) } } if e.Metric != nil { switch m := e.Metric.(type) { case float64: pe.MetricD = &m case float32: pe.MetricF = &m case int64: pe.MetricSint64 = &m case int: val := int64(m) pe.MetricSint64 = &val } } return pe}
// ProtoToState converts a protobuf State to an internal Event.func ProtoToState(ps *pb.State) *Event { if ps == nil { return nil } e := &Event{} if ps.Time != nil { e.Time = *ps.Time } if ps.State != nil { e.State = *ps.State } if ps.Service != nil { e.Service = *ps.Service } if ps.Host != nil { e.Host = *ps.Host } if ps.Description != nil { e.Description = *ps.Description } e.Tags = ps.Tags if ps.Ttl != nil { e.TTL = *ps.Ttl } return e}