Fix typo in monitor to correctly print IP address
[doctor.git] / tests / monitor.py
index 2a78cb6..9e48986 100644 (file)
@@ -1,17 +1,11 @@
+##############################################################################
+# Copyright (c) 2016 NEC Corporation and others.
 #
-# Copyright 2016 NEC Corporation.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
 
 import argparse
 import json
@@ -34,10 +28,11 @@ class DoctorMonitorSample(object):
     def __init__(self, args):
         self.hostname = args.hostname
         self.inspector = args.inspector
-        self.ip_addr = socket.gethostbyname(self.hostname)
+        self.ip_addr = args.ip or socket.gethostbyname(self.hostname)
 
     def start_loop(self):
-        print "start ping to host %s" % self.hostname
+        print "start ping to host %(h)s (ip=%(i)s)" % {'h': self.hostname,
+                                                       'i': self.ip_addr}
         sock = socket.socket(socket.AF_INET, socket.SOCK_RAW,
                              socket.IPPROTO_ICMP)
         sock.settimeout(self.timeout)
@@ -63,6 +58,8 @@ def get_args():
     parser = argparse.ArgumentParser(description='Doctor Sample Monitor')
     parser.add_argument('hostname', metavar='HOSTNAME', type=str, nargs='?',
                         help='a hostname to monitor connectivity')
+    parser.add_argument('ip', metavar='IP', type=str, nargs='?',
+                        help='an IP address to monitor connectivity')
     parser.add_argument('inspector', metavar='INSPECTOR', type=str, nargs='?',
                         help='inspector url to report error',
                         default='http://127.0.0.1:12345/events')