summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRamesh Nachimuthu <rnachimu@redhat.com>2014-04-28 18:05:25 +0530
committerSahina Bose <sabose@redhat.com>2014-04-30 07:18:34 -0700
commite34b8338759a56a3f0c03156aaa5b94377c679ed (patch)
tree09f17ca14ef8b199c9b74a5442a6e9207c496478
parent6fa90e73ddeb2a5df1e6ab01837a249274928ff6 (diff)
autoconf: Configure the nodes in auto-config using NRPE
Addning an NRPE command to configure all the newly added nodes to used passive check results using NSCA. It is done using the NRPE command 'configure_gluster_node'. Change-Id: I75d0214c8c52afdedd13dac3f38d52abc4ca5a93 Signed-off-by: Ramesh Nachimuthu <rnachimu@redhat.com> Reviewed-on: http://review.gluster.org/7593 Reviewed-by: Sahina Bose <sabose@redhat.com>
-rw-r--r--config/gluster-commands.cfg2
-rwxr-xr-xplugins/discovery.py119
2 files changed, 106 insertions, 15 deletions
diff --git a/config/gluster-commands.cfg b/config/gluster-commands.cfg
index 8c5594f..196ca08 100644
--- a/config/gluster-commands.cfg
+++ b/config/gluster-commands.cfg
@@ -73,7 +73,7 @@ define command{
define command{
command_name gluster_auto_discovery
- command_line sudo $USER1$/gluster/discovery.py -H $ARG1$ -c $HOSTNAME$ -m auto
+ command_line sudo $USER1$/gluster/discovery.py -H $ARG1$ -c $HOSTNAME$ -m auto -n $ARG2$
}
define command{
diff --git a/plugins/discovery.py b/plugins/discovery.py
index 60e8b26..72c8328 100755
--- a/plugins/discovery.py
+++ b/plugins/discovery.py
@@ -38,16 +38,22 @@ from config_generator import CHANGE_MODE_UPDATE
nrpeCmdPath = utils.CommandPath("nrpe", NRPE_PATH, )
-def excecNRPECommand(host, command):
- (returncode, outputStr, err) = utils.execCmd([nrpeCmdPath.cmd,
- "-H", host, "-c", command])
+def excecNRPECommand(host, command, arguments=None, jsonOutput=True):
+ nrpeCmd = [nrpeCmdPath.cmd, "-H", host, "-c", command]
+ if arguments:
+ nrpeCmd.append('-a')
+ nrpeCmd.extend(arguments)
+ (returncode, outputStr, err) = utils.execCmd(nrpeCmd)
#convert to dictionary
- try:
- output = json.loads(outputStr[0])
- except Exception as e:
- e.args += (outputStr[0])
- raise
- return output
+ if not jsonOutput:
+ return outputStr[0]
+ else:
+ try:
+ output = json.loads(outputStr[0])
+ except Exception as e:
+ e.args += (outputStr[0])
+ raise
+ return output
def discoverCluster(hostip, cluster):
@@ -164,9 +170,13 @@ def findDeletedServices(host):
#Check if auto config is changed. IP address in the check command will change
#when user runs the auto config using different host.
def findChangeInAutoConfig(newService, oldService):
- if newService['check_command'] != oldService['check_command']:
+ newHostIp = newService['check_command'].split('!')[1]
+ oldHostIp = oldService['check_command'].split('!')[1]
+ if newHostIp != oldHostIp:
changes = {}
- changes['check_command'] = newService['check_command']
+ checkCommand = oldService['check_command'].split("!")
+ checkCommand[1] = newHostIp
+ changes['check_command'] = "!".join(checkCommand)
changes['service_description'] = newService['service_description']
changes['host_name'] = newService['host_name']
changes['changeMode'] = CHANGE_MODE_UPDATE
@@ -258,6 +268,9 @@ def parse_input():
type=str, required=True, help='Cluster name')
parser.add_argument('-H', '--hostip', action='store', dest='hostip',
type=str, required=True, help='Host IP')
+ parser.add_argument('-n', '--nagios', action='store',
+ dest='nagiosServerIP', type=str, required=False,
+ help='Nagios Server Address')
parser.add_argument('-m', '--mode', action='store', dest='mode',
choices=['auto', 'manual'], required=False,
default='manual', help='Mode')
@@ -299,14 +312,90 @@ def previewChanges(clusterDelta):
changeMode)
+#Configure the gluster node to send passive check results through NSCA
+def configureNodes(clusterDelta, nagiosServerAddress, mode):
+ for host in clusterDelta['_hosts']:
+ #Only when a new node is added or whole cluster is added freshly.
+ if (host['use'] != 'gluster_cluster') and \
+ (host.get('changeMode') == CHANGE_MODE_ADD or
+ clusterDelta['changeMode'] == CHANGE_MODE_ADD):
+ if not nagiosServerAddress:
+ #Nagios server address should be specified as arg in auto mode
+ if mode == "manual":
+ nagiosServerAddress = getNagiosAddress(
+ clusterDelta['hostgroup_name'])
+ else:
+ print "Nagios server address is not specified in " \
+ "'auto' mode"
+ sys.exit(utils.PluginStatusCode.CRITICAL)
+
+ #Configure the nodes. clusterName, Nagios server address and
+ #host_name is passed as an argument to nrpe command
+ #'configure_gluster_node'
+ excecNRPECommand(
+ host['address'], 'configure_gluster_node',
+ [clusterDelta['hostgroup_name'], nagiosServerAddress,
+ host['host_name']], False)
+ return nagiosServerAddress
+
+
+#We have to update the cluster auto config service with the nagios
+#server address. This is needed for the auto config to configure nodes in
+#'auto' mode.
+def updateNagiosAddressInAutoConfig(clusterHostConfig, nagiosServerAddress):
+ autoConfigService = findServiceInList(clusterHostConfig['host_services'],
+ "Cluster Auto Config")
+ if autoConfigService and nagiosServerAddress:
+ checkCommandParams = autoConfigService['check_command'].split("!")
+ if len(checkCommandParams) == 2:
+ #Nagios server address will the 3rd param
+ checkCommandParams.append(nagiosServerAddress)
+ autoConfigService['check_command'] = "!".join(checkCommandParams)
+
+
#Write the cluster configurations. If force mode is used then it will clean
#the config directory before writing the changes.
-def writeDelta(clusterDelta, configManager, force):
+def writeDelta(clusterDelta, configManager, force, nagiosServerAddress, mode):
+ nagiosServerAddress = configureNodes(clusterDelta, nagiosServerAddress,
+ mode)
+ #Find the cluster host using host group name
+ clusterHostConfig = findHostInList(clusterDelta['_hosts'],
+ clusterDelta['hostgroup_name'])
+ if clusterHostConfig:
+ updateNagiosAddressInAutoConfig(clusterHostConfig, nagiosServerAddress)
if force:
cleanConfigDir(configManager.configDir)
configManager.generateConfigFiles(clusterDelta)
+def getNagiosAddress(clusterName):
+ #If there is an auto config service exist for the cluster, then we have
+ #to use the previously entered nagios server address
+ autoConfigService = server_utils.getServiceConfig("Cluster Auto Config",
+ clusterName)
+ if autoConfigService:
+ 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
+
+
def getConfirmation(message, default):
while True:
ans = raw_input("%s (Yes, No) [%s]: " % (message, default))
@@ -341,7 +430,8 @@ if __name__ == '__main__':
confirmation = getConfirmation(
"Are you sure, you want to commit the changes?", "Yes")
if confirmation:
- writeDelta(clusterDelta, configManager, args.force)
+ writeDelta(clusterDelta, configManager, args.force,
+ args.nagiosServerIP, args.mode)
print "Cluster configurations synced successfully from host %s" % \
(args.hostip)
#If Nagios is running then try to restart. Otherwise don't do
@@ -357,7 +447,8 @@ if __name__ == '__main__':
print "Start the Nagios service to monitor"
#auto mode means write the configurations without asking confirmation
elif args.mode == "auto":
- writeDelta(clusterDelta, configManager, args.force)
+ writeDelta(clusterDelta, configManager, args.force,
+ args.nagiosServerIP, args.mode)
print "Cluster configurations synced successfully from host %s" % \
(args.hostip)
if server_utils.isNagiosRunning():