mirror of https://github.com/status-im/consul.git
Store check output in dedicated field. Fixes #59.
This commit is contained in:
parent
554a8478ac
commit
018482dc4c
|
@ -359,7 +359,7 @@ func (a *Agent) AddService(service *structs.NodeService, chkType *CheckType) err
|
||||||
CheckID: fmt.Sprintf("service:%s", service.ID),
|
CheckID: fmt.Sprintf("service:%s", service.ID),
|
||||||
Name: fmt.Sprintf("Service '%s' check", service.Service),
|
Name: fmt.Sprintf("Service '%s' check", service.Service),
|
||||||
Status: structs.HealthUnknown,
|
Status: structs.HealthUnknown,
|
||||||
Notes: "Initializing",
|
Notes: "",
|
||||||
ServiceID: service.ID,
|
ServiceID: service.ID,
|
||||||
ServiceName: service.Service,
|
ServiceName: service.Service,
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,7 +308,7 @@ func TestAgent_UpdateCheck(t *testing.T) {
|
||||||
if status.Status != structs.HealthPassing {
|
if status.Status != structs.HealthPassing {
|
||||||
t.Fatalf("bad: %v", status)
|
t.Fatalf("bad: %v", status)
|
||||||
}
|
}
|
||||||
if status.Notes != "foo" {
|
if status.Output != "foo" {
|
||||||
t.Fatalf("bad: %v", status)
|
t.Fatalf("bad: %v", status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ func (c *CheckType) IsMonitor() bool {
|
||||||
// to notify when a check has a status update. The update
|
// to notify when a check has a status update. The update
|
||||||
// should take care to be idempotent.
|
// should take care to be idempotent.
|
||||||
type CheckNotifier interface {
|
type CheckNotifier interface {
|
||||||
UpdateCheck(checkID, status, note string)
|
UpdateCheck(checkID, status, output string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckMonitor is used to periodically invoke a script to
|
// CheckMonitor is used to periodically invoke a script to
|
||||||
|
@ -137,14 +137,14 @@ func (c *CheckMonitor) check() {
|
||||||
}()
|
}()
|
||||||
err := <-errCh
|
err := <-errCh
|
||||||
|
|
||||||
notes := string(output.Bytes())
|
outputStr := string(output.Bytes())
|
||||||
c.Logger.Printf("[DEBUG] agent: check '%s' script '%s' output: %s",
|
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
|
// Check if the check passed
|
||||||
if err == nil {
|
if err == nil {
|
||||||
c.Logger.Printf("[DEBUG] Check '%v' is passing", c.CheckID)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ func (c *CheckMonitor) check() {
|
||||||
code := status.ExitStatus()
|
code := status.ExitStatus()
|
||||||
if code == 1 {
|
if code == 1 {
|
||||||
c.Logger.Printf("[WARN] Check '%v' is now warning", c.CheckID)
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ func (c *CheckMonitor) check() {
|
||||||
|
|
||||||
// Set the health as critical
|
// Set the health as critical
|
||||||
c.Logger.Printf("[WARN] Check '%v' is now critical", c.CheckID)
|
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,
|
// CheckTTL is used to apply a TTL to check status,
|
||||||
|
@ -221,9 +221,9 @@ func (c *CheckTTL) run() {
|
||||||
|
|
||||||
// SetStatus is used to update the status of the check,
|
// SetStatus is used to update the status of the check,
|
||||||
// and to renew the TTL. If expired, TTL is restarted.
|
// 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.Logger.Printf("[DEBUG] Check '%v' status is now %v",
|
||||||
c.CheckID, status)
|
c.CheckID, status)
|
||||||
c.Notify.UpdateCheck(c.CheckID, status, note)
|
c.Notify.UpdateCheck(c.CheckID, status, output)
|
||||||
c.timer.Reset(c.TTL)
|
c.timer.Reset(c.TTL)
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,13 +186,13 @@ func (l *localState) UpdateCheck(checkID, status, output string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do nothing if update is idempotent
|
// Do nothing if update is idempotent
|
||||||
if check.Status == status && check.Notes == output {
|
if check.Status == status && check.Output == output {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update status and mark out of sync
|
// Update status and mark out of sync
|
||||||
check.Status = status
|
check.Status = status
|
||||||
check.Notes = output
|
check.Output = output
|
||||||
l.checkStatus[checkID] = syncStatus{inSync: false}
|
l.checkStatus[checkID] = syncStatus{inSync: false}
|
||||||
l.changeMade()
|
l.changeMade()
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,6 +205,7 @@ type HealthCheck struct {
|
||||||
Name string // Check name
|
Name string // Check name
|
||||||
Status string // The current check status
|
Status string // The current check status
|
||||||
Notes string // Additional notes with the status
|
Notes string // Additional notes with the status
|
||||||
|
Output string // Holds output of script runs
|
||||||
ServiceID string // optional associated service
|
ServiceID string // optional associated service
|
||||||
ServiceName string // optional service name
|
ServiceName string // optional service name
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue