func freeMemOrSwap(input string, swapOrMem string) (int, string, error) {
	amount, units, err := chkutil.SeparateByteUnits(input)
	if err != nil {
		log.WithFields(log.Fields{
			"err": err.Error(),
		}).Fatal("Couldn't separate string into a scalar and units")
	}
	var actualAmount int
	switch strings.ToLower(swapOrMem) {
	case "memory":
		actualAmount, err = memstatus.FreeMemory(units)
	case "swap":
		actualAmount, err = memstatus.FreeSwap(units)
	default:
		log.Fatalf("Invalid option passed to freeMemoOrSwap: %s", swapOrMem)
	}
	if err != nil {
		return 1, "", err
	} else if actualAmount > amount {
		return errutil.Success()
	}
	msg := "Free " + swapOrMem + " lower than defined threshold"
	actualString := fmt.Sprint(actualAmount) + units
	return errutil.GenericError(msg, input, []string{actualString})
}
freeMemOrSwap is an abstraction of FreeMemory and FreeSwap, which measures
if the desired resource has a quantity free above the amount specified
package checks
import (
	"fmt"
	"github.com/CiscoCloud/distributive/chkutil"
	"github.com/CiscoCloud/distributive/errutil"
	"github.com/CiscoCloud/distributive/fsstatus"
	"github.com/CiscoCloud/distributive/memstatus"
	log "github.com/Sirupsen/logrus"
	"io/ioutil"
	"os"
	"strconv"
	"strings"
	"syscall"
	"time"
)
type MemoryUsage struct{ maxPercentUsed uint8 }
func init() {
    chkutil.Register("MemoryUsage", func() chkutil.Check {
        return &MemoryUsage{}
    })
    chkutil.Register("SwapUsage", func() chkutil.Check {
        return &SwapUsage{}
    })
    chkutil.Register("FreeMemory", func() chkutil.Check {
        return &FreeMemory{}
    })
    chkutil.Register("FreeSwap", func() chkutil.Check {
        return &FreeSwap{}
    })
    chkutil.Register("CPUUsage", func() chkutil.Check {
        return &CPUUsage{}
    })
    chkutil.Register("DiskUsage", func() chkutil.Check {
        return &DiskUsage{}
    })
    chkutil.Register("InodeUsage", func() chkutil.Check {
        return &InodeUsage{}
    })
}
func (chk MemoryUsage) New(params []string) (chkutil.Check, error) {
	if len(params) != 1 {
		return chk, errutil.ParameterLengthError{1, params}
	}
	per, err := strconv.ParseInt(strings.Replace(params[0], "%", "", -1), 10, 8)
	if strings.HasPrefix(params[0], "-") || err != nil {
		return chk, errutil.ParameterTypeError{params[0], "uint8"}
	}
	chk.maxPercentUsed = uint8(per)
	return chk, nil
}
func (chk MemoryUsage) Status() (int, string, error) {
	actualPercentUsed, err := memstatus.FreeMemory("percent")
	if err != nil {
		return 1, "", err
	}
	if actualPercentUsed < int(chk.maxPercentUsed) {
		return errutil.Success()
	}
	msg := "Memory usage above defined maximum"
	slc := []string{fmt.Sprint(actualPercentUsed)}
	return errutil.GenericError(msg, fmt.Sprint(chk.maxPercentUsed), slc)
}
type SwapUsage struct{ maxPercentUsed int8 }
func (chk SwapUsage) ID() string { return "SwapUsage" }
func (chk SwapUsage) New(params []string) (chkutil.Check, error) {
	if len(params) != 1 {
		return chk, errutil.ParameterLengthError{1, params}
	}
	per, err := strconv.ParseInt(strings.Replace(params[0], "%", "", -1), 10, 8)
	if err != nil {
		return chk, errutil.ParameterTypeError{params[0], "positive int8"}
	}
	if per < 0 {
		return chk, errutil.ParameterTypeError{params[0], "positive int8"}
	}
	chk.maxPercentUsed = int8(per)
	return chk, nil
}
func (chk SwapUsage) Status() (int, string, error) {
	actualPercentUsed, err := memstatus.UsedSwap("percent")
	if err != nil {
		return 1, "", err
	}
	if actualPercentUsed < int(chk.maxPercentUsed) {
		return errutil.Success()
	}
	msg := "Swap usage above defined maximum"
	slc := []string{fmt.Sprint(actualPercentUsed)}
	return errutil.GenericError(msg, fmt.Sprint(chk.maxPercentUsed), slc)
}