From 44a1e8f43c04a8933311d6347d9bfe41a0aea78b Mon Sep 17 00:00:00 2001 From: Ramesh Nachimuthu Date: Tue, 6 May 2014 18:32:46 +0530 Subject: 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 Reviewed-on: http://review.gluster.org/7740 Reviewed-by: darshan n Reviewed-by: Sahina Bose --- plugins/discovery.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'plugins/discovery.py') 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): -- cgit