Skip to content

Commit

Permalink
Store check output in dedicated field. Fixes #59.
Browse files Browse the repository at this point in the history
  • Loading branch information
armon committed Apr 21, 2014
1 parent 554a847 commit 018482d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (a *Agent) AddService(service *structs.NodeService, chkType *CheckType) err
CheckID: fmt.Sprintf("service:%s", service.ID),
Name: fmt.Sprintf("Service '%s' check", service.Service),
Status: structs.HealthUnknown,
Notes: "Initializing",
Notes: "",
ServiceID: service.ID,
ServiceName: service.Service,
}
Expand Down
2 changes: 1 addition & 1 deletion command/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func TestAgent_UpdateCheck(t *testing.T) {
if status.Status != structs.HealthPassing {
t.Fatalf("bad: %v", status)
}
if status.Notes != "foo" {
if status.Output != "foo" {
t.Fatalf("bad: %v", status)
}
}
16 changes: 8 additions & 8 deletions command/agent/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (c *CheckType) IsMonitor() bool {
// to notify when a check has a status update. The update
// should take care to be idempotent.
type CheckNotifier interface {
UpdateCheck(checkID, status, note string)
UpdateCheck(checkID, status, output string)
}

// CheckMonitor is used to periodically invoke a script to
Expand Down Expand Up @@ -137,14 +137,14 @@ func (c *CheckMonitor) check() {
}()
err := <-errCh

notes := string(output.Bytes())
outputStr := string(output.Bytes())
c.Logger.Printf("[DEBUG] agent: check '%s' script '%s' output: %s",
c.CheckID, c.Script, notes)
c.CheckID, c.Script, outputStr)

// Check if the check passed
if err == nil {
c.Logger.Printf("[DEBUG] Check '%v' is passing", c.CheckID)
c.Notify.UpdateCheck(c.CheckID, structs.HealthPassing, notes)
c.Notify.UpdateCheck(c.CheckID, structs.HealthPassing, outputStr)
return
}

Expand All @@ -155,15 +155,15 @@ func (c *CheckMonitor) check() {
code := status.ExitStatus()
if code == 1 {
c.Logger.Printf("[WARN] Check '%v' is now warning", c.CheckID)
c.Notify.UpdateCheck(c.CheckID, structs.HealthWarning, notes)
c.Notify.UpdateCheck(c.CheckID, structs.HealthWarning, outputStr)
return
}
}
}

// Set the health as critical
c.Logger.Printf("[WARN] Check '%v' is now critical", c.CheckID)
c.Notify.UpdateCheck(c.CheckID, structs.HealthCritical, notes)
c.Notify.UpdateCheck(c.CheckID, structs.HealthCritical, outputStr)
}

// CheckTTL is used to apply a TTL to check status,
Expand Down Expand Up @@ -221,9 +221,9 @@ func (c *CheckTTL) run() {

// SetStatus is used to update the status of the check,
// and to renew the TTL. If expired, TTL is restarted.
func (c *CheckTTL) SetStatus(status, note string) {
func (c *CheckTTL) SetStatus(status, output string) {
c.Logger.Printf("[DEBUG] Check '%v' status is now %v",
c.CheckID, status)
c.Notify.UpdateCheck(c.CheckID, status, note)
c.Notify.UpdateCheck(c.CheckID, status, output)
c.timer.Reset(c.TTL)
}
4 changes: 2 additions & 2 deletions command/agent/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ func (l *localState) UpdateCheck(checkID, status, output string) {
}

// Do nothing if update is idempotent
if check.Status == status && check.Notes == output {
if check.Status == status && check.Output == output {
return
}

// Update status and mark out of sync
check.Status = status
check.Notes = output
check.Output = output
l.checkStatus[checkID] = syncStatus{inSync: false}
l.changeMade()
}
Expand Down
1 change: 1 addition & 0 deletions consul/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ type HealthCheck struct {
Name string // Check name
Status string // The current check status
Notes string // Additional notes with the status
Output string // Holds output of script runs
ServiceID string // optional associated service
ServiceName string // optional service name
}
Expand Down

0 comments on commit 018482d

Please sign in to comment.