def checkVolumePerfData(clusterName): # Write command to socket cmd = ("GET services\nColumns: description host_name " "perf_data custom_variables\n" "Filter: host_name = %s\n" "Filter: description ~~ %s\n" % (clusterName, 'Volume Utilization -')) perf_data_output = livestatus.readLiveStatusAsJSON(cmd) perf_data = json.loads(perf_data_output) numvolumes = 0 totalUsed = 0.0 totalAvail = 0.0 for row in perf_data: numvolumes += 1 if len(row) <= 3: return 0.0, 0.0 perf_data = row[2] if len(perf_data) > 2: perf_arr = perf_data.split(' ') used = perf_arr[2].split('=')[1] avail = perf_arr[1].split('=')[1] totalUsed += float(re.match(r'\d*\.?\d+', used).group()) totalAvail += float(re.match(r'\d*\.?\d+', avail).group()) return numvolumes, totalUsed, totalAvail
def checkVolumePerfData(clusterName): # Write command to socket cmd = ( "GET services\nColumns: description host_name " "perf_data custom_variables\n" "Filter: host_name = %s\n" "Filter: description ~~ %s\n" % (clusterName, "Volume Utilization -") ) perf_data_output = livestatus.readLiveStatusAsJSON(cmd) perf_data = json.loads(perf_data_output) numvolumes = 0 totalUsed = 0.0 totalAvail = 0.0 for row in perf_data: numvolumes += 1 if len(row) <= 3: return 0.0, 0.0 perf_data = row[2] if len(perf_data) > 2: perf_arr = perf_data.split(" ") used = perf_arr[2].split("=")[1] avail = perf_arr[1].split("=")[1] totalUsed += float(re.match(r"\d*\.?\d+", used).group()) totalAvail += float(re.match(r"\d*\.?\d+", avail).group()) return numvolumes, totalUsed, totalAvail
def _getGlusterdStatus(hostname): status = json.loads( livestatus.readLiveStatusAsJSON( "GET services\nColumns: state\n" "Filter: description = Gluster Management\n" "Filter: host_name = " + hostname + "\n"))[0][0] return status
def _getListHosts(hostgroup): list_hosts = [] table = json.loads(livestatus.readLiveStatusAsJSON( "GET hostgroups\nColumns: members_with_state\n" "Filter: name = " + hostgroup + "\n"))[0][0] # Get the only those nodes which are UP and # glusterd service is running for row in table: if row[1] == utils.HostStatusCode.UP and \ _getGlusterdStatus(row[0]) \ == utils.PluginStatusCode.OK: list_hosts.append(row[0]) return list_hosts
def _getListHosts(hostgroup): list_hosts = [] table = json.loads( livestatus.readLiveStatusAsJSON( "GET hostgroups\nColumns: members_with_state\n" "Filter: name = " + hostgroup + "\n"))[0][0] # Get the only those nodes which are UP and # glusterd service is running for row in table: if row[1] == utils.HostStatusCode.UP and \ _getGlusterdStatus(row[0]) \ == utils.PluginStatusCode.OK: list_hosts.append(row[0]) return list_hosts
def _getQuorumStatusOutput(hostgroup): # get current volume quorum status table = json.loads(livestatus.readLiveStatusAsJSON("GET services\n" "Columns: state plugin_output\n" "Filter: description = " "Cluster - Quorum Status\n" "Filter: host_name = %s\n" % hostgroup)) servicestatus = utils.PluginStatusCode.UNKNOWN pluginoutput = '' for row in table: servicestatus = row[0] pluginoutput = row[1] if (int(servicestatus) != utils.PluginStatusCode.CRITICAL): return _executeRandomHost(hostgroup, _getQuorumStatusNRPECommand()) else: return servicestatus, pluginoutput
def _getQuorumStatusOutput(hostgroup): # get current volume quorum status table = json.loads( livestatus.readLiveStatusAsJSON("GET services\n" "Columns: state plugin_output\n" "Filter: description = " "Cluster - Quorum Status\n" "Filter: host_name = %s\n" % hostgroup)) servicestatus = utils.PluginStatusCode.UNKNOWN pluginoutput = '' for row in table: servicestatus = row[0] pluginoutput = row[1] if (int(servicestatus) != utils.PluginStatusCode.CRITICAL): return _executeRandomHost(hostgroup, _getQuorumStatusNRPECommand()) else: return servicestatus, pluginoutput
def _getVolumeStatusOutput(hostgroup, volume): status, output = _executeRandomHost(hostgroup, _getVolStatusNRPECommand(volume)) if status == utils.PluginStatusCode.OK: brick_details = json.loads( livestatus.readLiveStatusAsJSON( "GET services\n" "Columns: description state host_address host_name\n" "Filter: host_groups >= %s\n" "Filter: custom_variable_values >= %s\n" "Filter: description ~ Brick - \n" % (hostgroup, volume))) # output will be as below: # [[u'Brick - /root/b3', 0, u'10.70.42.246', u'nishanth-rhs-2']] # parse this to find the no of critical/ok bricks and list of # critical bricks bricks_ok = 0 bricks_critical = 0 brick_list_critical = [] for brick_detail in brick_details: if brick_detail[1] == utils.PluginStatusCode.OK: bricks_ok += 1 elif brick_detail[1] == utils.PluginStatusCode.CRITICAL: bricks_critical += 1 # get the critical brick's host uuid if not present # int the list custom_vars = json.loads( livestatus.readLiveStatusAsJSON( "GET hosts\n" "Columns: custom_variables\n" "Filter: groups >= %s\n" "Filter: name = %s\n" % (hostgroup, brick_detail[3]))) brick_dict = {} brick_dict['brick'] = brick_detail[2] + ":" + \ brick_detail[0][brick_detail[0].find("/"):] brick_dict['uuid'] = custom_vars[0][0]['HOST_UUID'] brick_list_critical.append(brick_dict) # Get volume details nrpeStatus, nrpeOut = _executeRandomHost( hostgroup, _getVolDetailNRPECommand(volume)) if nrpeStatus != utils.PluginStatusCode.OK: return utils.PluginStatusCode.UNKNOWN, nrpeOut volInfo = json.loads(nrpeOut) # Get the volume type vol_type = volInfo[volume]['type'] if bricks_ok == 0 and bricks_critical > 0: status = utils.PluginStatusCode.CRITICAL output = "CRITICAL: Volume : %s type - All bricks " \ "are down " % (vol_type) elif bricks_ok > 0 and bricks_critical == 0: status = utils.PluginStatusCode.OK output = "OK: Volume : %s type - All bricks " \ "are Up " % (vol_type) elif bricks_critical > 0: if (vol_type == "DISTRIBUTE"): status = utils.PluginStatusCode.CRITICAL output = "CRITICAL: Volume : %s type \n Brick(s) - <%s> " \ "is|are down " % \ (vol_type, ', '.join(dict['brick']for dict in brick_list_critical)) elif (vol_type == "DISTRIBUTED_REPLICATE" or vol_type == "REPLICATE" or vol_type == "DISTRIBUTED_DISPERSE" or vol_type == "DISPERSE"): status, output = _getDisperseOrReplicaStatus( vol_type, brick_list_critical, volInfo, volume) else: output = "WARNING: Volume : %s type \n Brick(s) - <%s> " \ "is|are down" % (vol_type, ', '.join(dict['brick'] for dict in brick_list_critical)) status = utils.PluginStatusCode.WARNING return status, output return status, output
def _getGlusterdStatus(hostname): status = json.loads(livestatus.readLiveStatusAsJSON( "GET services\nColumns: state\n" "Filter: description = Gluster Management\n" "Filter: host_name = " + hostname + "\n"))[0][0] return status
def _getVolumeStatusOutput(hostgroup, volume): status, output = _executeRandomHost(hostgroup, _getVolStatusNRPECommand(volume)) if status == utils.PluginStatusCode.OK: brick_details = json.loads(livestatus.readLiveStatusAsJSON( "GET services\n" "Columns: description state host_address host_name\n" "Filter: host_groups >= %s\n" "Filter: custom_variable_values >= %s\n" "Filter: description ~ Brick - \n" % (hostgroup, volume))) # output will be as below: # [[u'Brick - /root/b3', 0, u'10.70.42.246', u'nishanth-rhs-2']] # parse this to find the no of critical/ok bricks and list of # critical bricks bricks_ok = 0 bricks_critical = 0 brick_list_critical = [] for brick_detail in brick_details: if brick_detail[1] == utils.PluginStatusCode.OK: bricks_ok += 1 elif brick_detail[1] == utils.PluginStatusCode.CRITICAL: bricks_critical += 1 # get the critical brick's host uuid if not present # int the list custom_vars = json.loads(livestatus.readLiveStatusAsJSON( "GET hosts\n" "Columns: custom_variables\n" "Filter: groups >= %s\n" "Filter: name = %s\n" % (hostgroup, brick_detail[3]))) brick_dict = {} brick_dict['brick'] = brick_detail[2] + ":" + \ brick_detail[0][brick_detail[0].find("/"):] brick_dict['uuid'] = custom_vars[0][0]['HOST_UUID'] brick_list_critical.append(brick_dict) # Get volume details nrpeStatus, nrpeOut = _executeRandomHost( hostgroup, _getVolDetailNRPECommand(volume)) if nrpeStatus != utils.PluginStatusCode.OK: return utils.PluginStatusCode.UNKNOWN, nrpeOut volInfo = json.loads(nrpeOut) # Get the volume type vol_type = volInfo[volume]['type'] if bricks_ok == 0 and bricks_critical > 0: status = utils.PluginStatusCode.CRITICAL output = "CRITICAL: Volume : %s type - All bricks " \ "are down " % (vol_type) elif bricks_ok > 0 and bricks_critical == 0: status = utils.PluginStatusCode.OK output = "OK: Volume : %s type - All bricks " \ "are Up " % (vol_type) elif bricks_critical > 0: if (vol_type == "DISTRIBUTE"): status = utils.PluginStatusCode.CRITICAL output = "CRITICAL: Volume : %s type \n Brick(s) - <%s> " \ "is|are down " % \ (vol_type, ', '.join(dict['brick']for dict in brick_list_critical)) elif (vol_type == "DISTRIBUTED_REPLICATE" or vol_type == "REPLICATE" or vol_type == "DISTRIBUTED_DISPERSE" or vol_type == "DISPERSE"): status, output = _getDisperseOrReplicaStatus( vol_type, brick_list_critical, volInfo, volume) else: output = "WARNING: Volume : %s type \n Brick(s) - <%s> " \ "is|are down" % (vol_type, ', '.join(dict['brick'] for dict in brick_list_critical)) status = utils.PluginStatusCode.WARNING return status, output return status, output