本文整理匯總了Golang中github.com/CiscoCloud/distributive/errutil.Success函數的典型用法代碼示例。如果您正苦於以下問題:Golang Success函數的具體用法?Golang Success怎麽用?Golang Success使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Success函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Status
func (chk Installed) Status() (int, string, error) {
name := getManager()
options := managers[name]
cmd := exec.Command(name, options, chk.pkg)
out, err := cmd.CombinedOutput()
outstr := string(out)
var msg string
switch {
case err == nil && (name == "rpm" || name == "pacman"):
return errutil.Success()
// failures due to mising package
case name == "dpkg" && strings.Contains(outstr, "not installed"):
case name == "pacman" && strings.Contains(outstr, "not found"):
case name == "rpm" && strings.Contains(outstr, "not installed"):
msg := "Package was not found:"
msg += "\n\tPackage name: " + chk.pkg
msg += "\n\tPackage manager: " + name
msg += "\n\tCommand output: " + outstr
return 1, msg, nil
// failures that were not due to packages not being installed
case err != nil:
errutil.ExecError(cmd, outstr, err)
default:
return errutil.Success()
}
return 1, msg, nil
}
示例2: Status
func (chk SystemctlUnitFileStatus) Status() (int, string, error) {
units, statuses, err := systemdstatus.UnitFileStatuses()
if err != nil {
return 1, "", err
}
var actualStatus string
found := false
for _, unit := range units {
if unit == chk.unit {
found = true
}
}
if !found {
return 1, "Unit file could not be found: " + chk.unit, nil
}
for i, un := range units {
if un == chk.unit {
actualStatus = statuses[i]
if actualStatus == chk.status {
return errutil.Success()
}
}
}
msg := "Unit didn't have status"
return errutil.GenericError(msg, chk.status, []string{actualStatus})
}
示例3: Status
func (chk Command) Status() (int, string, error) {
cmd := exec.Command("bash", "-c", chk.Command)
err := cmd.Start()
if err != nil && strings.Contains(err.Error(), "not found in $PATH") {
return 1, "Executable not found: " + chk.Command, nil
} else if err != nil {
return 1, "", err
}
if err = cmd.Wait(); err != nil {
var exitCode int
// this is convoluted, but should work on Windows & Unix
if exiterr, ok := err.(*exec.ExitError); ok {
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
exitCode = status.ExitStatus()
}
}
// dummy, in case the above failed. We know it's not zero!
if exitCode == 0 {
exitCode = 1
}
out, _ := cmd.CombinedOutput() // don't care if this fails
exitMessage := "Command exited with non-zero exit code:"
exitMessage += "\n\tCommand: " + chk.Command
exitMessage += "\n\tExit code: " + fmt.Sprint(exitCode)
exitMessage += "\n\tOutput: " + string(out)
return 1, exitMessage, nil
}
return errutil.Success()
}
示例4: freeMemOrSwap
// freeMemOrSwap is an abstraction of FreeMemory and FreeSwap, which measures
// if the desired resource has a quantity free above the amount specified
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})
}
示例5: RoutingTableMatch
// RoutingTableMatch asks: Is this value in this column of the routing table?
func RoutingTableMatch(col string, str string) (int, string, error) {
column := RoutingTableColumn(col)
if tabular.StrIn(str, column) {
return errutil.Success()
}
return errutil.GenericError("Not found in routing table", str, column)
}
示例6: Status
func (chk DockerRunningAPI) Status() (int, string, error) {
running := getRunningContainersAPI(chk.path)
if tabular.StrContainedIn(chk.name, running) {
return errutil.Success()
}
msg := "Docker container not runnning"
return errutil.GenericError(msg, chk.name, running)
}
示例7: ResponseMatchesGeneral
// ResponseMatchesGeneral is an abstraction of ResponseMatches and
// ResponseMatchesInsecure that simply varies in the security of the connection
func ResponseMatchesGeneral(urlstr string, re *regexp.Regexp, secure bool) (int, string, error) {
body := chkutil.URLToBytes(urlstr, secure)
if re.Match(body) {
return errutil.Success()
}
msg := "Response didn't match regexp"
return errutil.GenericError(msg, re.String(), []string{string(body)})
}
示例8: Status
func (chk FileMatches) Status() (int, string, error) {
if chk.re.Match(chkutil.FileToBytes(chk.path)) {
return errutil.Success()
}
msg := "File does not match regexp:"
msg += "\n\tFile: " + chk.path
msg += "\n\tRegexp: " + chk.re.String()
return 1, msg, nil
}
示例9: Status
func (chk UserInGroup) Status() (int, string, error) {
boo, err := usrstatus.UserInGroup(chk.user, chk.group)
if err != nil {
return 1, "", err
} else if boo {
return errutil.Success()
}
return 1, "User not found in group", nil
}
示例10: timerCheck
// timerCheck is pure DRY for SystemctlTimer and SystemctlTimerLoaded
func timerCheck(unit string, all bool) (int, string, error) {
timers, err := systemdstatus.Timers(all)
if err != nil {
return 1, "", err
} else if tabular.StrIn(unit, timers) {
return errutil.Success()
}
return errutil.GenericError("Timer not found", unit, timers)
}
示例11: ipCheck
// ipCheck(int, string, error) is an abstraction of IP4 and
// IP6
func ipCheck(name string, address *net.IP, version int) (int, string, error) {
ips := netstatus.InterfaceIPs(name)
for _, ip := range ips {
if ip.Equal(*address) {
return errutil.Success()
}
}
return errutil.GenericError("Interface does not have IP", address, ips)
}
示例12: Status
func (chk PortTCP) Status() (int, string, error) {
if netstatus.PortOpen("tcp", chk.port) {
return errutil.Success()
}
// convert ports to string to send to errutil.GenericError
var strPorts []string
for _, port := range netstatus.OpenPorts("tcp") {
strPorts = append(strPorts, fmt.Sprint(port))
}
return errutil.GenericError("Port not open", fmt.Sprint(chk.port), strPorts)
}
示例13: isType
// isType checks if the resource at path is of the type specified by name by
// passing path to checker. Mostly used to abstract Directory, File, Symlink.
func isType(name string, checker fileCondition, path string) (int, string, error) {
boo, err := checker(path)
if os.IsNotExist(err) {
return 1, "No such file or directory: " + path, nil
} else if os.IsPermission(err) {
return 1, "", errors.New("Insufficient Permissions to read: " + path)
} else if boo {
return errutil.Success()
}
return 1, "Is not a " + name + ": " + path, nil
}
示例14: Status
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)
}
示例15: Status
func (chk InodeUsage) Status() (int, string, error) {
actualPercentUsed, err := fsstatus.PercentInodesUsed(chk.filesystem)
if err != nil {
return 1, "Unexpected error", err
}
if actualPercentUsed < chk.maxPercentUsed {
return errutil.Success()
}
msg := "More disk space used than expected"
slc := []string{fmt.Sprint(actualPercentUsed) + "%"}
return errutil.GenericError(msg, fmt.Sprint(chk.maxPercentUsed)+"%", slc)
}