From ee1795b2c7b39c652f4b36c1f3179aeaae2e9e8a Mon Sep 17 00:00:00 2001 From: Oscar Eriksson Date: Thu, 3 May 2018 17:20:45 +0800 Subject: [PATCH] enable ServiceAddress to be set --- src/ianitor/args_parser.py | 6 ++++++ src/ianitor/script.py | 1 + src/ianitor/service.py | 4 +++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ianitor/args_parser.py b/src/ianitor/args_parser.py index e0107f4..d189b65 100644 --- a/src/ianitor/args_parser.py +++ b/src/ianitor/args_parser.py @@ -141,6 +141,12 @@ def get_parser(): help="set service id - must be node unique (defaults to service name)" ) + parser.add_argument( + "--address", + metavar="hostname", type=str, + help="set service address (if different than agent address)", + ) + parser.add_argument( "--port", type=int, diff --git a/src/ianitor/script.py b/src/ianitor/script.py index 34ce93f..c6bf995 100644 --- a/src/ianitor/script.py +++ b/src/ianitor/script.py @@ -74,6 +74,7 @@ def main(): service_name=args.service_name, service_id=args.id, tags=args.tags, + address=args.address, port=args.port ) diff --git a/src/ianitor/service.py b/src/ianitor/service.py index b00a320..809d90c 100644 --- a/src/ianitor/service.py +++ b/src/ianitor/service.py @@ -38,7 +38,7 @@ def ignore_connection_errors(action="unknown"): class Service(object): def __init__(self, command, session, ttl, service_name, - service_id=None, tags=None, port=None): + service_id=None, tags=None, port=None, address=None): self.command = command self.session = session self.process = None @@ -47,6 +47,7 @@ def __init__(self, command, session, ttl, service_name, self.service_name = service_name self.tags = tags or [] self.port = port + self.address = address self.service_id = service_id or service_name self.check_id = "service:" + self.service_id @@ -96,6 +97,7 @@ def register(self): service_id=self.service_id, port=self.port, tags=self.tags, + address=self.address, # format the ttl into XXXs format check=Check.ttl("%ss" % self.ttl) )