Skip to content

Commit

Permalink
updating timestamp handling for improper subsecond precision
Browse files Browse the repository at this point in the history
  • Loading branch information
sebito91 committed Feb 10, 2018
1 parent 85f4ad6 commit 1b21875
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 1 addition & 2 deletions services/pagerduty2/pagerduty2test/pagerduty2test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net/http"
"net/http/httptest"
"sync"
"time"
)

type Server struct {
Expand Down Expand Up @@ -57,7 +56,7 @@ type PDCEF struct {
Summary string `json:"summary"`
Source string `json:"source"`
Severity string `json:"severity"`
Timestamp time.Time `json:"timestamp"`
Timestamp string `json:"timestamp"`
Class string `json:"class"`
Component string `json:"component"`
Group string `json:"group"`
Expand Down
14 changes: 9 additions & 5 deletions services/pagerduty2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type PDCEF struct {
Summary string `json:"summary"`
Source string `json:"source"`
Severity string `json:"severity"`
Timestamp time.Time `json:"timestamp"`
Timestamp string `json:"timestamp"`
Class string `json:"class"`
Component string `json:"component"`
Group string `json:"group"`
Expand Down Expand Up @@ -229,6 +229,7 @@ func (s *Service) Alert(serviceKey, incidentKey, desc string, level alert.Level,
if resp.StatusCode != http.StatusAccepted {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Printf("error parsing error body\n")
return err
}
type response struct {
Expand Down Expand Up @@ -290,10 +291,8 @@ func (s *Service) preparePost(serviceKey, incidentKey, desc string, level alert.
case alert.Info:
severity = "info"
default:
eventType = "resolve"

// default is a 'resolve' function
return s.sendResolve(c, serviceKey, incidentKey)

}

// create a new AlertPayload for us to fire off
Expand Down Expand Up @@ -322,11 +321,16 @@ func (s *Service) preparePost(serviceKey, incidentKey, desc string, level alert.
}
}

m := timestamp.Format(time.RFC3339Nano)
if timestamp.Nanosecond() == 0 {
m = time.Unix(timestamp.Unix(), 1).Format(time.RFC3339Nano)
}

ap.Payload.Class = data.TaskName
ap.Payload.Severity = severity
ap.Payload.Source = "unknown"
ap.Payload.Summary = desc
ap.Payload.Timestamp = timestamp
ap.Payload.Timestamp = m

if _, ok := data.Tags["host"]; ok {
ap.Payload.Source = data.Tags["host"]
Expand Down

0 comments on commit 1b21875

Please sign in to comment.