nagiosfoundation

package
v0.0.0-...-7d76b79 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckCPU

func CheckCPU(warning, critical int, metricName string) (string, int)

CheckCPU executes CheckCPUWithHandler(), passing it the OS constrained GetCPULoad() function, prints the returned message and exits with the returned exit code.

func CheckCPUWithHandler

func CheckCPUWithHandler(warning, critical int, metricName string, cpuHandler func() (float64, error)) (string, int)

CheckCPUWithHandler gets the CPU load then emits a critical response if it's above the critical argument, a warning if it's above warning argument and good response for everything else.

Returns are a response message and response code.

func CheckFileExists

func CheckFileExists(pattern string, negate bool) (string, int)

CheckFileExists tests the assertion that one or more files matching specified pattern should or should not exist.

func CheckHTTP

func CheckHTTP(url string, redirect, insecure bool, host string, timeout int, format, path, expectedValue, expression string) (string, int)

CheckHTTP attempts an HTTP request against the provided url, reporting the HTTP response code and overall request state.

func CheckMemory

func CheckMemory(checkType string, warning, critical int, metricName string) (string, int)

CheckMemory executes CheckMemoryWithHandler(), passing it the OS constranted GetFreeMemory() function, prints the returned message and exits with the returned exit code.

Returns are those of CheckMemoryWithHandler()

func CheckMemoryWithHandler

func CheckMemoryWithHandler(checkType string, warning, critical int, metricName string, memoryHandler func() uint64) (string, int)

CheckMemoryWithHandler determines the percentage of memory used and emits a critical response if it's over the critical argument, a warning response if it's over the warning argument, and good response otherwise.

func CheckPerformanceCounter

func CheckPerformanceCounter(warning, critical float64, greaterThan bool, pollingAttempts, pollingDelay int, metricName, counterName string) (string, int)

CheckPerformanceCounter executes CheckPerformanceCounterWitHandler(), passing it the OS constrained ReadPerformanceCounter() function, prints the returned message and exits with the returned exit code.

func CheckPerformanceCounterWithHandler

func CheckPerformanceCounterWithHandler(warning, critical float64, greaterThan bool, pollingAttempts, pollingDelay int, metricName, counterName string, perfCounterHandler func(string, int, int) (perfcounters.PerformanceCounter, error)) (string, int)

CheckPerformanceCounterWithHandler fetches a performance counter specified with the counterName parameter. It then performs checks against the value based on the threshold test specified along with the warning and critical thresholds.

Returns are a message stating the results of the check and a return value from the check.

func CheckPort

func CheckPort(protocol CheckPortProtocol, address string, port, timeout int, invert bool, metricName string) (string, int)

CheckPort checks for a listening port at an address

func CheckProcess

func CheckProcess(name, checkType, metricName string) (string, int)

CheckProcess finds a process by name to determine if it is running or not running.

func CheckProcessCPU

func CheckProcessCPU(warning, critical int, processName, metricName string, perCoreCalculation bool) (string, int)

CheckProcessCPU executes CheckProcessCPUWithHandler(), passing it the OS constrained GetProcessCPULoad() function, prints the returned message and exits with the returned exit code.

func CheckProcessCPUWithHandler

func CheckProcessCPUWithHandler(warning, critical int, processName, metricName string, perCoreCalculation bool,
	processCPUCoreHandler func(string, bool) (float64, error)) (string, int)

CheckProcessCPUWithHandler gets the CPU load of a process then emits a critical response if it's above the critical argument, a warning if it's above warning argument and good response for everything else.

Returns are a response message and response code.

func CheckProcessMemory

func CheckProcessMemory(warning, critical int, processName, metricName string) (string, int)

CheckProcessMemory executes CheckProcessMemoryWithHandler(), passing it the OS constrained GetProcessMemoryPercentage() function, prints the returned message and exits with the returned exit code.

Returns are those of CheckProcessMemoryWithHandler()

func CheckProcessMemoryWithHandler

func CheckProcessMemoryWithHandler(warning, critical int, processName, metricName string, memoryHandler func(string) (float64, error)) (string, int)

CheckProcessMemoryWithHandler determines the percentage of memory used by a process and emits a critical response if it's over the critical argument, a warning response if it's over the warning argument, and good response otherwise.

func CheckService

func CheckService(name, state, user string, currentStateWanted bool, useSvcMgr bool, metricName string) (string, int)

CheckService checks a service based on name, state, user, and manager

func CheckUptime

func CheckUptime(checkType string, warning, critical time.Duration, metricName string) (string, int)

CheckUptime gathers information about the host uptime.

func CheckUserGroup

func CheckUserGroup(user, group string) (string, int)

CheckUserGroup executes the normal user/group checks in CheckUserGroupFlags() then prints the results and exits.

func CheckUserGroupWithHandler

func CheckUserGroupWithHandler(user, group string, userGroupHandler UserGroupService) (string, int)

CheckUserGroupWithHandler checks for the existence of a user and if it belongs to the named group on the host operating system.

The user and group are provided with the user and group parameters.

Returns - result message and return code.

Types

type CheckPortProtocol

type CheckPortProtocol int

CheckPortProtocol is the type of protocol to use for checking the port

const (
	// CheckPortProtocolTCP specifies using TCP as the network protocol for
	// checking theport
	CheckPortProtocolTCP CheckPortProtocol = 0
)

func (CheckPortProtocol) String

func (cpp CheckPortProtocol) String() string

type ProcessCheck

type ProcessCheck struct {
	ProcessName string

	ProcessCheckHandler ProcessService
}

ProcessCheck is used to encapsulate a named process along with the methods used to get information about that process. Currently the only check is for the named process running.

func (ProcessCheck) IsProcessRunning

func (p ProcessCheck) IsProcessRunning() bool

IsProcessRunning interrogates the OS for the named process to check if it's running. Note this function calls IsProcessRunning in the injected service and in this implementation will ultimately call an OS constrained function.

type ProcessService

type ProcessService interface {
	IsProcessRunning(string) bool
}

ProcessService is an interface required by ProcessCheck.

The given a process name, the method IsProcessRunning() must return true if the named process is running, otherwise false. Note the code will be different for each OS.

type UserGroupCheck

type UserGroupCheck struct {
	UserName  string
	GroupName string

	Service UserGroupService
}

UserGroupCheck is a struct in which a user and group on the host OS can be populated, then information about the user and group can be retrieved.

func (UserGroupCheck) CheckGroup

func (ugc UserGroupCheck) CheckGroup() (string, int)

CheckGroup checks for the existence of a group on the host operating system.

Returns a string containing plaintext result and an integer with the return code. 0 indicates the group exists, 2 indicates the group does not exist.

func (UserGroupCheck) CheckUser

func (ugc UserGroupCheck) CheckUser() (string, int)

CheckUser checks for the existence of a user on the host operating system.

Returns a string containing plaintext result and an integer with the return code. 0 indicates the user exists, 2 indicates the user does not exist.

func (UserGroupCheck) CheckUserGroup

func (ugc UserGroupCheck) CheckUserGroup() (string, int)

CheckUserGroup checks for the existence of a user and if it belongs to the named group on the host operating system.

Returns a string containing plaintext result and an integer with the return code. 0 indicates the user exists and is in the group, 2 indicates otherwise.

type UserGroupHandler

type UserGroupHandler struct{}

UserGroupHandler is a specific implementation of the methods in the UserGroupService interface. The methods implemented use Go's user package which should be compatible with both Linux and Windows.

func (UserGroupHandler) GroupIds

func (u UserGroupHandler) GroupIds(userInfo *user.User) ([]string, error)

GroupIds is given the User struct from Go's user package and returns a list of group IDs to which the user belongs.

func (UserGroupHandler) Lookup

func (u UserGroupHandler) Lookup(userName string) (*user.User, error)

Lookup is given a user name and returns the details of a user on the host OS. This implementation calls Lookup() in Go's user package.

func (UserGroupHandler) LookupGroup

func (u UserGroupHandler) LookupGroup(groupName string) (*user.Group, error)

LookupGroup is given a group name and returns the details of the group on the host OS. This implementation calls LookupGroup() in Go's user package.

func (UserGroupHandler) LookupGroupID

func (u UserGroupHandler) LookupGroupID(groupID string) (*user.Group, error)

LookupGroupID is given a group ID and returns the details of the group on the host OS. This implmentation calls LookupGroupId() in Go's user package.

type UserGroupService

type UserGroupService interface {
	Lookup(string) (*user.User, error)
	LookupGroup(string) (*user.Group, error)
	LookupGroupID(string) (*user.Group, error)
	GroupIds(*user.User) ([]string, error)
}

UserGroupService is an interface that allows for overriding methods for looking up a user, a group, finding the ID for a group name, and fetching a list of groups to which a user belongs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL