def getClusterQuorumStatus(): exitstatus = 0 message = "" try: volumes = glustercli.volumeInfo() except glustercli.GlusterLockedException as e: out = ("UNKNOWN: temporary error. %s" % '.'.join(e.err)) return utils.PluginStatusCode.UNKNOWN, out except glustercli.GlusterCmdFailedException as e: out = ("Quorum status could not be determined. %s" % '.'.join(e.err)) return utils.PluginStatusCode.WARNING, out quorumVolumes = [] for volumename, volume in volumes.iteritems(): if (volume.get('options') and volume.get('options').get('cluster.server-quorum-type') == "server"): quorumVolumes.append(volumename) if not quorumVolumes: exitstatus = utils.PluginStatusCode.UNKNOWN message = "Server quorum not turned on for any volume" else: exitstatus = utils.PluginStatusCode.OK message = ("Server quorum turned on for %s" % (','.join(quorumVolumes))) return exitstatus, message
def discoverVolumes(volumeName, list): """ This method helps to discover volumes list and volume info Parameters ---------- list: Flag used for getting volume info. If the flag is 'True' then the method will return only list of volume names with volume Type and doesn't include the brick details. . If list is 'False' then returns the volume details with brick information. volumeName: Fetch information only for the given volume. Note: glustercli.volumeInfo(volName) command accept a volumeName. But if the volume name is not passed then it returns details about all the volumes in the cluster. Returns --------- Returns volume details in the following dictionary format { 'vol-name' : {vol-details} 'vol-name' : {vol-details} 'vol-name' : {vol-details} ... } """ resultlist = {} try: volumes = glustercli.volumeInfo(volumeName) except glustercli.GlusterLockedException as e: resultString = ("UNKNOWN: temporary error. %s" % '.'.join(e.err)) return utils.PluginStatusCode.UNKNOWN, resultString except glustercli.GlusterCmdFailedException as e: resultString = ("UNKNOWN: Failed to get the volume Information. " "%s" % '.'.join(e.err)) return utils.PluginStatusCode.UNKNOWN, resultString for key, volume in volumes.iteritems(): volDict = {} volDict['name'] = key volDict['type'] = volume['volumeType'] if not list: volOptions = volume.get('options') if volOptions: quotaStatus = volOptions.get('features.quota') if quotaStatus == "on": volDict['quota'] = quotaStatus geoRepStatus = volOptions.get('geo-replication.indexing') if geoRepStatus == "on": volDict['geo-rep'] = geoRepStatus volDict['replicaCount'] = volume['replicaCount'] volDict['bricks'] = [] volDict['disperseCount'] = volume['disperseCount'] volDict['redundancyCount'] = volume['redundancyCount'] for brick in volume['bricksInfo']: brickproplist = brick['name'].split(':') volDict['bricks'].append({'brickaddress': brickproplist[0], 'brickpath': brickproplist[1], 'hostUuid': brick['hostUuid']}) resultlist[key] = volDict resultString = json.dumps(resultlist) return utils.PluginStatusCode.OK, resultString
def getVolumeStatus(args): exitstatus = 0 message = "" try: volumes = glustercli.volumeInfo(args.volume) if volumes.get(args.volume) is None: exitstatus = utils.PluginStatusCode.CRITICAL message = "CRITICAL: Volume not found" return exitstatus, message elif volumes[args.volume]["volumeStatus"] == (glustercli. VolumeStatus.ONLINE): exitstatus = utils.PluginStatusCode.OK message = "OK: Volume : %s type - Volume is up" % \ (volumes[args.volume]["volumeType"]) elif volumes[args.volume]["volumeStatus"] == (glustercli. VolumeStatus.OFFLINE): exitstatus = utils.PluginStatusCode.CRITICAL message = "CRITICAL: Volume : %s type is stopped" % \ (volumes[args.volume]["volumeType"]) except glustercli.GlusterLockedException as e: out = ("UNKNOWN: Glusterd cannot be queried. %s" % '.'.join(e.err)) return utils.PluginStatusCode.UNKNOWN, out except glustercli.GlusterCmdFailedException as e: out = ("WARNING: Command execution failed. %s" % '.'.join(e.err)) return utils.PluginStatusCode.WARNING, out return exitstatus, message
def getVolumeStatus(args): exitstatus = 0 message = "" try: volumes = glustercli.volumeInfo(args.volume) if volumes.get(args.volume) is None: exitstatus = utils.PluginStatusCode.CRITICAL message = "CRITICAL: Volume not found" return exitstatus, message elif volumes[args.volume]["volumeStatus"] == ( glustercli.VolumeStatus.ONLINE): exitstatus = utils.PluginStatusCode.OK message = "OK: Volume : %s type - Volume is up" % \ (volumes[args.volume]["volumeType"]) elif volumes[args.volume]["volumeStatus"] == ( glustercli.VolumeStatus.OFFLINE): exitstatus = utils.PluginStatusCode.CRITICAL message = "CRITICAL: Volume : %s type is stopped" % \ (volumes[args.volume]["volumeType"]) except glustercli.GlusterLockedException as e: out = ("UNKNOWN: Glusterd cannot be queried. %s" % '.'.join(e.err)) return utils.PluginStatusCode.UNKNOWN, out except glustercli.GlusterCmdFailedException as e: out = ("WARNING: Command execution failed. %s" % '.'.join(e.err)) return utils.PluginStatusCode.WARNING, out return exitstatus, message
def check_volume_status(volume): try: volumes = glustercli.volumeInfo(volume) if volumes.get(volume) is None: sys.stdout.write("CRITICAL: Volume not found\n") sys.exit(utils.PluginStatusCode.CRITICAL) elif volumes[volume]["volumeStatus"] == \ glustercli.VolumeStatus.OFFLINE: sys.stdout.write("CRITICAL: Volume is stopped\n") sys.exit(utils.PluginStatusCode.CRITICAL) except glustercli.GlusterCmdFailedException: sys.stdout.write("UNKNOWN: Failed to get the " "Volume Utilization Data\n") sys.exit(utils.PluginStatusCode.UNKNOWN)
def run(self): hostName = nscautils.getCurrentHostNameInNagiosServer() sleepTime = int(nscautils.getProcessMonitorSleepTime()) glusterdStatus = Status() nfsStatus = Status() smbStatus = Status() shdStatus = Status() quotaStatus = Status() ctdbStatus = Status() brickStatus = {} while True: if not hostName: hostName = nscautils.getCurrentHostNameInNagiosServer() if not hostName: logger.warn("'hostname_in_nagios' is not configured " "in %s" % nagios_server_conf_path) time.sleep(sleepTime) continue status, msg = check_proc_util.getGlusterdStatus() if glusterdStatus.isStatusChanged(status, msg): nscautils.send_to_nsca(hostName, _glusterdService, status, msg) # Get the volume status only if glusterfs is running to avoid # unusual delay if status != utils.PluginStatusCode.OK: logger.warn("Glusterd is not running") time.sleep(sleepTime) continue try: volInfo = glustercli.volumeInfo() except glusternagios.glustercli.GlusterCmdFailedException: logger.error("failed to find volume info") time.sleep(sleepTime) continue status, msg = check_proc_util.getNfsStatus(volInfo) if nfsStatus.isStatusChanged(status, msg): nscautils.send_to_nsca(hostName, _nfsService, status, msg) status, msg = check_proc_util.getSmbStatus(volInfo) if smbStatus.isStatusChanged(status, msg): nscautils.send_to_nsca(hostName, _smbService, status, msg) status, msg = check_proc_util.getCtdbStatus( smbStatus.code, nfsStatus.code) if ctdbStatus.isStatusChanged(status, msg): nscautils.send_to_nsca(hostName, _ctdbdService, status, msg) status, msg = check_proc_util.getShdStatus(volInfo) if shdStatus.isStatusChanged(status, msg): nscautils.send_to_nsca(hostName, _shdService, status, msg) status, msg = check_proc_util.getQuotadStatus(volInfo) if quotaStatus.isStatusChanged(status, msg): nscautils.send_to_nsca(hostName, _quotadService, status, msg) brick = getBrickStatus(volInfo) # brickInfo contains status, and message for brickService, brickInfo in brick.iteritems(): if brickInfo != brickStatus.get(brickService, [None]) \ or brickInfo[0] == utils.PluginStatusCode.CRITICAL: brickStatus[brickService] = brickInfo nscautils.send_to_nsca(hostName, brickService, brickInfo[0], brickInfo[1]) time.sleep(sleepTime)
def _findBrickName(volInfo, brickPath): hostUuid = glustercli.hostUUIDGet() for volumeName, volumeInfo in volInfo.iteritems(): for brick in volumeInfo['bricksInfo']: if brick.get('hostUuid') == hostUuid \ and brick['name'].split(':')[1] == brickPath: return brick['name'] if __name__ == '__main__': args = parse_input() status, msg = check_proc_util.getGlusterdStatus() if status == utils.PluginStatusCode.OK: if args.type == _NFS: status, msg = check_proc_util.getNfsStatus(glustercli.volumeInfo()) elif args.type == _SMB: status, msg = check_proc_util.getSmbStatus(glustercli.volumeInfo()) elif args.type == _SHD: status, msg = check_proc_util.getShdStatus(glustercli.volumeInfo()) elif args.type == _QUOTA: status, msg = check_proc_util.getQuotadStatus( glustercli.volumeInfo()) elif args.type == _CTDB: volInfo = glustercli.volumeInfo() nfsStatus, nfsMsg = check_proc_util.getNfsStatus(volInfo) smbStatus, smbMsg = check_proc_util.getSmbStatus(volInfo) status, msg = check_proc_util.getCtdbStatus(smbStatus, nfsStatus) elif args.type == _BRICK: volInfo = glustercli.volumeInfo(args.volume) brickName = _findBrickName(volInfo, args.brickPath)
def run(self): hostName = nscautils.getCurrentHostNameInNagiosServer() sleepTime = int(nscautils.getProcessMonitorSleepTime()) glusterdStatus = Status() nfsStatus = Status() smbStatus = Status() shdStatus = Status() quotaStatus = Status() ctdbStatus = Status() brickStatus = {} while True: if not hostName: hostName = nscautils.getCurrentHostNameInNagiosServer() if not hostName: logger.warn("'hostname_in_nagios' is not configured " "in %s" % nagios_server_conf_path) time.sleep(sleepTime) continue status, msg = check_proc_util.getGlusterdStatus() if glusterdStatus.isStatusChanged(status, msg): nscautils.send_to_nsca(hostName, _glusterdService, status, msg) # Get the volume status only if glusterfs is running to avoid # unusual delay if status != utils.PluginStatusCode.OK: logger.warn("Glusterd is not running") time.sleep(sleepTime) continue try: volInfo = glustercli.volumeInfo() except glusternagios.glustercli.GlusterCmdFailedException: logger.error("failed to find volume info") time.sleep(sleepTime) continue status, msg = check_proc_util.getNfsStatus(volInfo) if nfsStatus.isStatusChanged(status, msg): nscautils.send_to_nsca(hostName, _nfsService, status, msg) status, msg = check_proc_util.getSmbStatus(volInfo) if smbStatus.isStatusChanged(status, msg): nscautils.send_to_nsca(hostName, _smbService, status, msg) status, msg = check_proc_util.getCtdbStatus(smbStatus.code, nfsStatus.code) if ctdbStatus.isStatusChanged(status, msg): nscautils.send_to_nsca(hostName, _ctdbdService, status, msg) status, msg = check_proc_util.getShdStatus(volInfo) if shdStatus.isStatusChanged(status, msg): nscautils.send_to_nsca(hostName, _shdService, status, msg) status, msg = check_proc_util.getQuotadStatus(volInfo) if quotaStatus.isStatusChanged(status, msg): nscautils.send_to_nsca(hostName, _quotadService, status, msg) brick = getBrickStatus(volInfo) # brickInfo contains status, and message for brickService, brickInfo in brick.iteritems(): if brickInfo != brickStatus.get(brickService, [None]) \ or brickInfo[0] == utils.PluginStatusCode.CRITICAL: brickStatus[brickService] = brickInfo nscautils.send_to_nsca(hostName, brickService, brickInfo[0], brickInfo[1]) time.sleep(sleepTime)