Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
require a valid duration suffix for interval and ttl values
Browse files Browse the repository at this point in the history
  • Loading branch information
sgargan committed Mar 3, 2015
1 parent a8584ad commit 0c6d426
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions clustering/consul
Original file line number Diff line number Diff line change
Expand Up @@ -375,21 +375,21 @@ class ConsulCheck():
if check_id:
self.check_id = check_id
self.script = script
self.interval = str(interval)

if not self.interval.endswith('m') or self.interval.endswith('s'):
self.interval += 'm'

self.ttl = ttl
self.interval = self.validate_duration('interval', interval)
self.ttl = self.validate_duration('ttl', ttl)
self.notes = notes
self.node = node
self.host = host

if interval and interval <= 0:
raise Error('check interval must be positive')


if ttl and ttl <= 0:
raise Error('check ttl value must be positive')
def validate_duration(self, name, duration):
if duration:
duration_units = ['ns', 'us', 'ms', 's', 'm', 'h']
if not any((duration.endswith(suffix) for suffix in duration_units)):
raise Exception('Invalid %s %s you must specify units (%s)' %
(name, duration, ', '.join(duration_units)))
return duration

def register(self, consul_api):
consul_api.agent.check.register(self.name, check_id=self.check_id,
Expand Down Expand Up @@ -434,7 +434,8 @@ def main():
check_id=dict(required=False),
check_name=dict(required=False),
host=dict(default='localhost'),
interval=dict(required=False, default='1m'),
interval=dict(required=False, type='str'),
ttl=dict(required=False, type='str'),
check_node=dict(required=False),
check_host=dict(required=False),
notes=dict(required=False),
Expand Down

0 comments on commit 0c6d426

Please sign in to comment.