From 438c9537d39ca4597935285e41793363923a39f7 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Thu, 30 Jan 2014 13:18:05 -0800 Subject: [PATCH] agent: Adding CheckType which is used to wrap either a CheckMonitor or CheckTTL --- command/agent/check.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/command/agent/check.go b/command/agent/check.go index ce71092f81..b86aa454a7 100644 --- a/command/agent/check.go +++ b/command/agent/check.go @@ -11,6 +11,31 @@ import ( "time" ) +// CheckType is used to create either the CheckMonitor +// or the CheckTTL. Only one of TTL or Script/Interval +// needs to be provided +type CheckType struct { + Script string + Interval time.Duration + + TTL time.Duration +} + +// Valid checks if the CheckType is valid +func (c *CheckType) Valid() bool { + return c.IsTTL() || c.IsMonitor() +} + +// IsTTL checks if this is a TTL type +func (c *CheckType) IsTTL() bool { + return c.TTL != 0 +} + +// IsMonitor checks if this is a Monitor type +func (c *CheckType) IsMonitor() bool { + return c.Script != "" && c.Interval != 0 +} + // CheckNotifier interface is used by the CheckMonitor // to notify when a check has a status update. The update // should take care to be idempotent.