summaryrefslogtreecommitdiffstats
path: root/plugins/discovery.py
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/discovery.py')
-rwxr-xr-xplugins/discovery.py110
1 files changed, 55 insertions, 55 deletions
diff --git a/plugins/discovery.py b/plugins/discovery.py
index 90a9e50..698873e 100755
--- a/plugins/discovery.py
+++ b/plugins/discovery.py
@@ -40,10 +40,10 @@ from config_generator import HOST_SERVICES
from config_generator import GLUSTER_AUTO_CONFIG
-#Discovers volumes info one by one.
-#First it fetches the volumes list and then it fetches the bricks
-#details of volume one by one. Its an work around for size limitation issue
-#in NRPE.
+# Discovers volumes info one by one.
+# First it fetches the volumes list and then it fetches the bricks
+# details of volume one by one. Its an work around for size limitation issue
+# in NRPE.
def discoverVolumes(hostip, timeout):
resultDict = {'volumes': []}
volumeList = server_utils.execNRPECommand(hostip,
@@ -84,23 +84,23 @@ def discoverCluster(hostip, cluster, timeout):
"""
clusterdata = {}
- #Discover the logical components
+ # Discover the logical components
componentlist = discoverVolumes(hostip, timeout)
- #Discover the peers
+ # Discover the peers
hostlist = server_utils.execNRPECommand(hostip,
"discoverpeers",
timeout=timeout)
- #Add the ip address of the root node given by the user to the peer list
+ # Add the ip address of the root node given by the user to the peer list
hostlist[0]['hostip'] = hostip
for host in hostlist:
- #Get host names for all the connected hosts
+ # Get host names for all the connected hosts
if host['status'] == HostStatus.CONNECTED:
hostDetails = server_utils.execNRPECommand(
host['hostip'],
"discoverhostparams",
timeout=timeout)
host.update(hostDetails)
- #Get the list of bricks for this host and add to dictionary
+ # Get the list of bricks for this host and add to dictionary
host['bricks'] = []
for volume in componentlist['volumes']:
for brick in volume['bricks']:
@@ -110,10 +110,10 @@ def discoverCluster(hostip, cluster, timeout):
clusterdata['hosts'] = hostlist
clusterdata['volumes'] = componentlist['volumes']
clusterdata['name'] = cluster
- #Host names returned by "discoverhostparams" supposed to be unique. So host
- #name can be used to configure the host_name in nagios host.
- #But if host names are not unique then we have to use IP address to
- #configure host_name in nagios.
+ # Host names returned by "discoverhostparams" supposed to be unique.
+ # So host name can be used to configure the host_name in nagios host.
+ # But if host names are not unique then we have to use IP address to
+ # configure host_name in nagios.
if not isHostsNamesUnique(clusterdata):
setHostNameWithIP(clusterdata)
return clusterdata
@@ -146,7 +146,7 @@ def getConfigManager(args):
return configManager
-#Find the given service in service list.
+# Find the given service in service list.
def findServiceInList(serviceList, serviceDescription):
for service in serviceList:
if service['service_description'] == serviceDescription:
@@ -154,7 +154,7 @@ def findServiceInList(serviceList, serviceDescription):
return None
-#Find the given host in host list
+# Find the given host in host list
def findHostInList(hostList, hostName):
for host in hostList:
if host['host_name'] == hostName:
@@ -162,12 +162,12 @@ def findHostInList(hostList, hostName):
return None
-#Find all deleted services in the host.
+# Find all deleted services in the host.
def findDeletedServices(host):
deletedService = []
serviceConfigs = server_utils.getServiceConfigByHost(host['host_name'])
for serviceConfig in serviceConfigs:
- #Consider only the service generated by autoconfig
+ # Consider only the service generated by autoconfig
if not serviceConfig[GENERATED_BY_AUTOCONFIG]:
continue
service = findServiceInList(host.get(HOST_SERVICES, []),
@@ -179,9 +179,9 @@ def findDeletedServices(host):
return deletedService
-#Looks for changes in the interesting service config fields. These fields
-#will be force synced without preserving user changes. All these fields
-#are list as part of config_generator.SERVICE_FIELDS_TO_FORCE_SYNC
+# Looks for changes in the interesting service config fields. These fields
+# will be force synced without preserving user changes. All these fields
+# are list as part of config_generator.SERVICE_FIELDS_TO_FORCE_SYNC
def findChangeInService(newService, oldService):
changes = {}
for field in SERVICE_FIELDS_TO_FORCE_SYNC:
@@ -195,8 +195,8 @@ def findChangeInService(newService, oldService):
return changes
-#Check if auto config is changed. IP address in the check command will change
-#when user runs the auto config using different 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):
newHostIp = newService['check_command'].split('!')[1]
oldHostIp = oldService['check_command'].split('!')[1]
@@ -212,10 +212,10 @@ def findChangeInAutoConfig(newService, oldService):
return None
-#Find all Added/Updated/Deleted services in the given host.
-#Note: 'Cluster Auto Config' is a special service. When user runs the
-#auto-config using different host instead what is used previously then we
-#have to update the host ip in existing auto-config service.
+# Find all Added/Updated/Deleted services in the given host.
+# Note: 'Cluster Auto Config' is a special service. When user runs the
+# auto-config using different host instead what is used previously then we
+# have to update the host ip in existing auto-config service.
def findServiceDelta(host):
serviceDelta = []
for service in host.get(HOST_SERVICES, []):
@@ -236,7 +236,7 @@ def findServiceDelta(host):
return serviceDelta
-#Find newly added hosts and newly added services to the existing hosts
+# Find newly added hosts and newly added services to the existing hosts
def findAddUpdateHosts(hosts):
delta = []
for host in hosts:
@@ -253,7 +253,7 @@ def findAddUpdateHosts(hosts):
return delta
-#Find deleted hosts in the given cluster.
+# Find deleted hosts in the given cluster.
def findDeletedHosts(hostgroup, hosts, ignoredHosts):
deletedHosts = []
hostConfigs = server_utils.getHostConfigsForCluster(hostgroup)
@@ -266,7 +266,7 @@ def findDeletedHosts(hostgroup, hosts, ignoredHosts):
return deletedHosts
-#Find Added/Deleted/Updated hosts in cluster
+# Find Added/Deleted/Updated hosts in cluster
def findHostDelta(clusterConfig, ignoredHosts):
hostDelta = []
updated = findAddUpdateHosts(clusterConfig['_hosts'])
@@ -276,7 +276,7 @@ def findHostDelta(clusterConfig, ignoredHosts):
return hostDelta
-#Find changes to the cluster
+# Find changes to the cluster
def findDelta(clusterConfig, ignoredHosts):
delta = {}
delta['hostgroup_name'] = clusterConfig['hostgroup_name']
@@ -321,7 +321,7 @@ def parse_input():
return args
-#Clean the config directory
+# Clean the config directory
def cleanConfigDir(dir):
if os.path.exists(dir):
# Deleting the config dir to write new configs
@@ -329,8 +329,8 @@ def cleanConfigDir(dir):
os.mkdir(dir)
-#Create a summary for mail notification. "\n" should be preserved in the
-#string to get the proper format in mail.
+# Create a summary for mail notification. "\n" should be preserved in the
+# string to get the proper format in mail.
def getSummary(clusterDelta):
summary = "\nChanges :"
clusterChangeMode = clusterDelta[CHANGE_MODE]
@@ -357,15 +357,15 @@ def formatTextForMail(text):
return output
-#Configure the gluster node to send passive check results through NSCA
+# Configure the gluster node to send passive check results through NSCA
def configureNodes(clusterDelta, nagiosServerAddress, mode, timeout):
for host in clusterDelta['_hosts']:
- #Only when a new node is added or whole cluster is added freshly.
+ # Only when a new node is added or whole cluster is added freshly.
if (clusterDelta.get(CHANGE_MODE) == CHANGE_MODE_ADD or
host.get(CHANGE_MODE) == CHANGE_MODE_ADD) \
and (host['use'] == 'gluster-host'):
if not nagiosServerAddress:
- #Nagios server address should be specified as arg in auto mode
+ # Nagios server address should be specified as arg in auto mode
if mode == "manual":
nagiosServerAddress = getNagiosAddress(
clusterDelta['hostgroup_name'])
@@ -374,9 +374,9 @@ def configureNodes(clusterDelta, nagiosServerAddress, mode, timeout):
"'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'
+ # Configure the nodes. clusterName, Nagios server address and
+ # host_name is passed as an argument to nrpe command
+ # 'configure_gluster_node'
server_utils.execNRPECommand(
host['address'], 'configure_gluster_node',
arguments=[clusterDelta['hostgroup_name'],
@@ -387,22 +387,22 @@ def configureNodes(clusterDelta, nagiosServerAddress, mode, timeout):
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.
+# 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],
GLUSTER_AUTO_CONFIG)
if autoConfigService and nagiosServerAddress:
checkCommandParams = autoConfigService['check_command'].split("!")
if len(checkCommandParams) == 2:
- #Nagios server address will the 3rd param
+ # 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.
+# 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,
@@ -413,7 +413,7 @@ def writeDelta(clusterDelta,
nagiosServerAddress,
mode,
timeout)
- #Find the cluster host using host group name
+ # Find the cluster host using host group name
clusterHostConfig = findHostInList(clusterDelta['_hosts'],
clusterDelta['hostgroup_name'])
if clusterHostConfig:
@@ -424,8 +424,8 @@ def writeDelta(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
+ # 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(GLUSTER_AUTO_CONFIG,
clusterName)
if autoConfigService:
@@ -465,7 +465,7 @@ def getConfirmation(message, default):
return False
-#Send a custom notification about the config changes to admin
+# Send a custom notification about the config changes to admin
def sendCustomNotification(cluster, summary):
now = datetime.datetime.now()
cmdStr = "[%s] SEND_CUSTOM_SVC_NOTIFICATION;%s;%s;0;" \
@@ -490,7 +490,7 @@ def _getHostGroupNames(hostConfig):
def _findDuplicateHost(hosts, clusterName):
for host in hosts:
- #Host name may be empty if the host is in disconnected status
+ # Host name may be empty if the host is in disconnected status
if host.get('hostname'):
hostConfig = server_utils.getHostConfigByName(host.get('hostname'))
if hostConfig:
@@ -524,8 +524,8 @@ if __name__ == '__main__':
if clusterDelta.get(CHANGE_MODE) is None:
print "Cluster configurations are in sync"
sys.exit(utils.PluginStatusCode.OK)
- #When auto config is run in manual mode, we will ask confirmation
- #before writing the config file and before restarting the Nagios
+ # When auto config is run in manual mode, we will ask confirmation
+ # before writing the config file and before restarting the Nagios
if args.mode == "manual":
print "Cluster configurations changed"
print getSummary(clusterDelta)
@@ -549,8 +549,8 @@ if __name__ == '__main__':
)
except Exception as e:
pass
- #If Nagios is running then try to restart. Otherwise don't do
- #anything.
+ # If Nagios is running then try to restart. Otherwise don't do
+ # anything.
if server_utils.isNagiosRunning():
confirmation = getConfirmation(
"Do you want to restart Nagios to start monitoring newly "
@@ -560,7 +560,7 @@ if __name__ == '__main__':
print "Nagios re-started successfully"
else:
print "Start the Nagios service to monitor"
- #auto mode means write the configurations without asking confirmation
+ # auto mode means write the configurations without asking confirmation
elif args.mode == "auto":
removed_hosts_count = getRemovedHostsCount(clusterDelta)
if removed_hosts_count > 0: