diff options
author | Ramesh Nachimuthu <rnachimu@redhat.com> | 2014-05-06 18:32:46 +0530 |
---|---|---|
committer | Sahina Bose <sabose@redhat.com> | 2015-05-19 02:01:33 -0700 |
commit | 44a1e8f43c04a8933311d6347d9bfe41a0aea78b (patch) | |
tree | 27d5c5ff24446ca2264e6ca0a02fa4734550df2a /plugins/discovery.py | |
parent | 8d1a17a906222feb3af6df7484fcba846673bae3 (diff) |
autoconf: validate the nagios server address in auto-config
Currently Nagios server address entered by the user during
auto config was not being verified. This patch helps to verify
the address entered by the user.
If IP address is given as the nagios server address then it
checks the pattern and verifies that it is mapped to one of the
non loopback device in the host
If user enters fqdn name, then it tries to resolve it,
also it verifies that resolved IP address maps to one of
the non loopback device in the host.
Bug-Url: https://bugzilla.redhat.com/1127657
Change-Id: I88d67cc6d8fa05f2934922fbc0d8e757b1d73e43
Signed-off-by: Ramesh Nachimuthu <rnachimu@redhat.com>
Reviewed-on: http://review.gluster.org/7740
Reviewed-by: darshan n <dnarayan@redhat.com>
Reviewed-by: Sahina Bose <sabose@redhat.com>
Diffstat (limited to 'plugins/discovery.py')
-rwxr-xr-x | plugins/discovery.py | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/plugins/discovery.py b/plugins/discovery.py index 46fee95..b17c81f 100755 --- a/plugins/discovery.py +++ b/plugins/discovery.py @@ -21,11 +21,13 @@ import datetime import os import shutil import sys +import socket from glusternagios import utils from glusternagios.glustercli import HostStatus from config_generator import GlusterNagiosConfManager import server_utils +import network_utils import submit_external_command from constants import DEFAULT_AUTO_CONFIG_DIR from constants import NAGIOS_CONFIG_FILE @@ -432,23 +434,21 @@ def getNagiosAddress(clusterName): nagiosAddress = autoConfigService['check_command'].split("!")[2] return nagiosAddress - (returncode, outputStr, err) = utils.execCmd([utils.hostnameCmdPath.cmd, - '--fqdn']) - if returncode == 0: - default = outputStr[0] - else: - (returncode, outputStr, err) = utils.execCmd( - [utils.hostnameCmdPath.cmd, '-I']) - if returncode == 0: - default = outputStr[0] - if default: - msg = "Enter Nagios server address [%s]: " % (default.strip()) - else: - msg = "Enter Nagios server address : " - ans = raw_input(msg) - if not ans: - ans = default - return ans + return getHostAddress() + + +def getHostAddress(): + fqdn = socket.getfqdn() + while True: + msg = 'Enter Nagios server address [%s]: ' % fqdn + address = raw_input(msg) + if not address: + address = fqdn + validationMsg = network_utils.validateHostAddress(address) + if validationMsg: + print 'Host address is not valid: %s' % validationMsg + else: + return address def getConfirmation(message, default): |