示例#1
0
def checkFreeSpace(config):
    notification.printHeader("Checking harddrive free space")
    
    try:
        defaultMinFreePercent = config['harddrive']['minFreeSpace']
    except (KeyError, TypeError):
        defaultMinFreePercent = 80
    
    df = subprocess.Popen(["df", "-P"], stdout=subprocess.PIPE)
    output = df.communicate()[0]
    lines = output.split("\n")[1:-1]
    for line in lines:
        
        device = line.split()[0]
        percent = line.split()[4]
        mountpoint = line.split()[5]
        
        minFreePercent = defaultMinFreePercent
        
        try:
            for override in config['harddrive']['override']:
                if mountpoint == override['mountPoint']:
                    minFreePercent = override['minFreeSpace']
                    break
        except (KeyError, TypeError):
            pass
        
        percentClean = int(percent.split("%")[0])
        if percentClean >= minFreePercent:
            notification.error(config, "device " + str(device) + " usage: " + str(percentClean) + "% (min " + str(minFreePercent) + "%) mountpoint: " + mountpoint)
        else:
            notification.printVerbose("checked {0:20s} usage: {1:3d}% (min: {2:3d}%, device: {3:10s})".format(mountpoint, percentClean, minFreePercent, device))
示例#2
0
文件: hardware.py 项目: Twain69/pymon
def checkFanSpeed(config):
    notification.printHeader("Checking fan speeds")
    
    try:
        defaultMinSpeed = config['hardware']['fanSpeed']['minSpeed']
    except (KeyError, TypeError):
        defaultMinSpeed = 500
    
    # Check if the fans are enabled
    try:
        status = config['hardware']['fanSpeed']['status']
    except (KeyError, TypeError):
        status = "disabled"

    if status == "enabled":    
        try:
            p1 = subprocess.Popen(["sensors"], stdout=subprocess.PIPE)
            p2 = subprocess.Popen(["egrep", "^fan"], stdin=p1.stdout, stdout=subprocess.PIPE)
            output = p2.communicate()[0]
            fans = output.split("\n")[0:-1]
        except (OSError):
            notification.error(config, "Sensors not installed")
            
        if len(fans) == 0:
            notification.error(config, "Could not find any fans")
            
        
        for fan in fans:
            
            fanname = fan.split()[0]
            speed = int(fan.split()[1])
            fanname = fanname.split(":")[0]
            minSpeed = defaultMinSpeed
            
            try:
                for override in config['hardware']['fanSpeed']['override']:
                    if fanname in override['name']:
                        minSpeed = override['minSpeed']
                        break
            except (KeyError, TypeError):
                pass
            
            if speed < minSpeed:
                notification.error(config, "Fan speed to low for fan " + fanname + ". Current speed: " + str(speed) + " (minSpeed: " + str(minSpeed) + ")")
            else:
                notification.printVerbose("Fan speed for fan " + fanname + " currently " + str(speed) + " (minSpeed: " + str(minSpeed) + ")")
示例#3
0
def checkRaidStatus(config):
    notification.printHeader("Checking RAID status")
    
    try:
        raid = config['raid']
    except (KeyError, TypeError):
        notification.printVerbose("No raid devices have been configured. Skipping!")
        return
    
    try:
        status = raid['status']
    except (KeyError, TypeError):
        status = "disabled"
        
    if status == "enabled":
        for device in raid['devices']:
            deviceName = device['name']
            notification.printVerbose("Checking RAID " + deviceName)
            
            mdadm = subprocess.Popen(["mdadm", "--detail", deviceName], stdout=subprocess.PIPE)
            output = mdadm.communicate()[0]
            lines = output.split("\n")
            
            totalDevices = None        
            activeDevices = None
            
            for row in lines:
                if "Total Devices" in row:
                    totalDevices = int(row.split(":")[1])
                if "Active Devices" in row:
                    activeDevices = int(row.split(":")[1])
            
            if totalDevices is not None and activeDevices is not None:
                totalDevices = int(totalDevices)
                activeDevices = int(activeDevices)
                if totalDevices != activeDevices:
                    notification.error(config, "RAID " + str(deviceName) + " is degraded. " + str(totalDevices) + " disks total, " + str(activeDevices) + " disks active ")
                else:
                    notification.printVerbose("RAID " + deviceName + " is OK")
            else:
                notification.error(config, "Could not determine details of RAID " + deviceName)
    else:
        notification.printVerbose("RAID status check is disabled")
示例#4
0
文件: process.py 项目: Twain69/pymon
def checkProcessRunning(config):
    notification.printHeader("Checking running processes")

    ps = subprocess.Popen(["ps", "auxwww"], stdout=subprocess.PIPE)
    output = ps.communicate()[0]
    processList = output.split("\n")[1:-1]

    try:
        checkprocesses = config["processes"]
    except (KeyError, TypeError):
        notification.printVerbose("No processes configured to be checked. Skipping!")
        return

    for process in checkprocesses:

        processName = process["name"]
        startCommand = process["startCommand"]
        try:
            processOwner = process["processOwner"]
        except KeyError:
            processOwner = ""
        try:
            status = process["status"]
        except KeyError:
            status = "enabled"

        if status == "enabled":
            notification.printVerbose("Checking for process '" + processName + "'")

            found = False

            for line in processList:
                if found:
                    break
                elements = line.split()
                # $ ps auxwww | head -n1
                # USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
                # -> command is starting at position 10
                combinedProcessName = ""
                for row in elements[10:]:
                    combinedProcessName = combinedProcessName + " " + row
                combinedProcessName = combinedProcessName.strip()

                if processName in combinedProcessName:
                    user = elements[0]
                    found = True

            if found is False:
                notification.error(config, "Process '" + processName + "' not found, trying to start")
                os.system(startCommand)
            else:
                if processOwner is not "" and processOwner != user:
                    notification.error(
                        config,
                        "Process '"
                        + processName
                        + "' found, but process owner is wrong: "
                        + user
                        + " instead of "
                        + processOwner,
                    )
                else:
                    notification.printVerbose(" Process '" + processName + "' running, process owner: " + user)

        else:
            notification.printVerbose("Check for process '" + processName + "' is disabled, skipping")