refactor(pkg): rename plugin status constants
This commit is contained in:
parent
ebdb99be8b
commit
b3aa7dfcad
4 changed files with 26 additions and 26 deletions
|
@ -224,20 +224,20 @@ func (program *checkProgram) Done() {
|
||||||
// if the arguments made sense.
|
// if the arguments made sense.
|
||||||
func (program *checkProgram) CheckArguments() bool {
|
func (program *checkProgram) CheckArguments() bool {
|
||||||
if program.hostname == "" {
|
if program.hostname == "" {
|
||||||
program.plugin.SetState(plugin.UNKNOWN, "no hostname specified")
|
program.plugin.SetState(plugin.StatusUnknown, "no hostname specified")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if program.port < 1 || program.port > 65535 {
|
if program.port < 1 || program.port > 65535 {
|
||||||
program.plugin.SetState(plugin.UNKNOWN, "invalid or missing port number")
|
program.plugin.SetState(plugin.StatusUnknown, "invalid or missing port number")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if program.warn != -1 && program.crit != -1 && program.warn <= program.crit {
|
if program.warn != -1 && program.crit != -1 && program.warn <= program.crit {
|
||||||
program.plugin.SetState(plugin.UNKNOWN, "nonsensical thresholds")
|
program.plugin.SetState(plugin.StatusUnknown, "nonsensical thresholds")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if _, ok := certGetters[program.startTLS]; !ok {
|
if _, ok := certGetters[program.startTLS]; !ok {
|
||||||
errstr := "unsupported StartTLS protocol " + program.startTLS
|
errstr := "unsupported StartTLS protocol " + program.startTLS
|
||||||
program.plugin.SetState(plugin.UNKNOWN, errstr)
|
program.plugin.SetState(plugin.StatusUnknown, errstr)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
program.hostname = strings.ToLower(program.hostname)
|
program.hostname = strings.ToLower(program.hostname)
|
||||||
|
@ -262,13 +262,13 @@ func (program *checkProgram) getCertificate() error {
|
||||||
// matches the requested host name.
|
// matches the requested host name.
|
||||||
func (program *checkProgram) checkSANlessCertificate() bool {
|
func (program *checkProgram) checkSANlessCertificate() bool {
|
||||||
if !program.ignoreCnOnly || len(program.extraNames) != 0 {
|
if !program.ignoreCnOnly || len(program.extraNames) != 0 {
|
||||||
program.plugin.SetState(plugin.WARNING,
|
program.plugin.SetState(plugin.StatusWarning,
|
||||||
"certificate doesn't have SAN domain names")
|
"certificate doesn't have SAN domain names")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
dn := strings.ToLower(program.certificate.Subject.String())
|
dn := strings.ToLower(program.certificate.Subject.String())
|
||||||
if !strings.HasPrefix(dn, fmt.Sprintf("cn=%s,", program.hostname)) {
|
if !strings.HasPrefix(dn, fmt.Sprintf("cn=%s,", program.hostname)) {
|
||||||
program.plugin.SetState(plugin.CRITICAL, "incorrect certificate CN")
|
program.plugin.SetState(plugin.StatusCritical, "incorrect certificate CN")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -298,7 +298,7 @@ func (program *checkProgram) checkNames() bool {
|
||||||
certificateIsOk = program.checkHostName(name) && certificateIsOk
|
certificateIsOk = program.checkHostName(name) && certificateIsOk
|
||||||
}
|
}
|
||||||
if !certificateIsOk {
|
if !certificateIsOk {
|
||||||
program.plugin.SetState(plugin.CRITICAL, "names missing from SAN domain names")
|
program.plugin.SetState(plugin.StatusCritical, "names missing from SAN domain names")
|
||||||
}
|
}
|
||||||
return certificateIsOk
|
return certificateIsOk
|
||||||
}
|
}
|
||||||
|
@ -308,7 +308,7 @@ func (program *checkProgram) checkNames() bool {
|
||||||
// values.
|
// values.
|
||||||
func (program *checkProgram) checkCertificateExpiry(tlDays int) (plugin.Status, string) {
|
func (program *checkProgram) checkCertificateExpiry(tlDays int) (plugin.Status, string) {
|
||||||
if tlDays <= 0 {
|
if tlDays <= 0 {
|
||||||
return plugin.CRITICAL, "certificate expired"
|
return plugin.StatusCritical, "certificate expired"
|
||||||
}
|
}
|
||||||
|
|
||||||
var limitStr string
|
var limitStr string
|
||||||
|
@ -317,15 +317,15 @@ func (program *checkProgram) checkCertificateExpiry(tlDays int) (plugin.Status,
|
||||||
switch {
|
switch {
|
||||||
case program.crit > 0 && tlDays <= program.crit:
|
case program.crit > 0 && tlDays <= program.crit:
|
||||||
limitStr = fmt.Sprintf(" (<= %d)", program.crit)
|
limitStr = fmt.Sprintf(" (<= %d)", program.crit)
|
||||||
state = plugin.CRITICAL
|
state = plugin.StatusCritical
|
||||||
|
|
||||||
case program.warn > 0 && tlDays <= program.warn:
|
case program.warn > 0 && tlDays <= program.warn:
|
||||||
limitStr = fmt.Sprintf(" (<= %d)", program.warn)
|
limitStr = fmt.Sprintf(" (<= %d)", program.warn)
|
||||||
state = plugin.WARNING
|
state = plugin.StatusWarning
|
||||||
|
|
||||||
default:
|
default:
|
||||||
limitStr = ""
|
limitStr = ""
|
||||||
state = plugin.OK
|
state = plugin.StatusOK
|
||||||
}
|
}
|
||||||
|
|
||||||
statusString := fmt.Sprintf("certificate will expire in %d days%s",
|
statusString := fmt.Sprintf("certificate will expire in %d days%s",
|
||||||
|
@ -351,7 +351,7 @@ func (program *checkProgram) setPerfData(tlDays int) {
|
||||||
func (program *checkProgram) RunCheck() {
|
func (program *checkProgram) RunCheck() {
|
||||||
err := program.getCertificate()
|
err := program.getCertificate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
program.plugin.SetState(plugin.UNKNOWN, err.Error())
|
program.plugin.SetState(plugin.StatusUnknown, err.Error())
|
||||||
} else if program.checkNames() {
|
} else if program.checkNames() {
|
||||||
timeLeft := time.Until(program.certificate.NotAfter)
|
timeLeft := time.Until(program.certificate.NotAfter)
|
||||||
tlDays := int((timeLeft + 86399*time.Second) / (24 * time.Hour))
|
tlDays := int((timeLeft + 86399*time.Second) / (24 * time.Hour))
|
||||||
|
|
|
@ -88,7 +88,7 @@ func NewProgram() program.Program {
|
||||||
// Terminate the monitoring check program.
|
// Terminate the monitoring check program.
|
||||||
func (program *checkProgram) Done() {
|
func (program *checkProgram) Done() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
program.plugin.SetState(plugin.UNKNOWN, "Internal error")
|
program.plugin.SetState(plugin.StatusUnknown, "Internal error")
|
||||||
program.plugin.AddLinef("Error info: %v", r)
|
program.plugin.AddLinef("Error info: %v", r)
|
||||||
}
|
}
|
||||||
program.plugin.Done()
|
program.plugin.Done()
|
||||||
|
@ -97,23 +97,23 @@ func (program *checkProgram) Done() {
|
||||||
// Check the values that were specified from the command line. Returns true if the arguments made sense.
|
// Check the values that were specified from the command line. Returns true if the arguments made sense.
|
||||||
func (program *checkProgram) CheckArguments() bool {
|
func (program *checkProgram) CheckArguments() bool {
|
||||||
if program.hostname == "" {
|
if program.hostname == "" {
|
||||||
program.plugin.SetState(plugin.UNKNOWN, "no DNS hostname specified")
|
program.plugin.SetState(plugin.StatusUnknown, "no DNS hostname specified")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if program.port < 1 || program.port > 65535 {
|
if program.port < 1 || program.port > 65535 {
|
||||||
program.plugin.SetState(plugin.UNKNOWN, "invalid DNS port number")
|
program.plugin.SetState(plugin.StatusUnknown, "invalid DNS port number")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if program.zone == "" {
|
if program.zone == "" {
|
||||||
program.plugin.SetState(plugin.UNKNOWN, "no DNS zone specified")
|
program.plugin.SetState(plugin.StatusUnknown, "no DNS zone specified")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if program.rsHostname == "" {
|
if program.rsHostname == "" {
|
||||||
program.plugin.SetState(plugin.UNKNOWN, "no reference DNS hostname specified")
|
program.plugin.SetState(plugin.StatusUnknown, "no reference DNS hostname specified")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if program.rsPort < 1 || program.rsPort > 65535 {
|
if program.rsPort < 1 || program.rsPort > 65535 {
|
||||||
program.plugin.SetState(plugin.UNKNOWN, "invalid reference DNS port number")
|
program.plugin.SetState(plugin.StatusUnknown, "invalid reference DNS port number")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
program.hostname = strings.ToLower(program.hostname)
|
program.hostname = strings.ToLower(program.hostname)
|
||||||
|
@ -180,12 +180,12 @@ func (program *checkProgram) RunCheck() {
|
||||||
cOk, cSerial := program.getSerial("checked", checkResponse)
|
cOk, cSerial := program.getSerial("checked", checkResponse)
|
||||||
rOk, rSerial := program.getSerial("reference", refResponse)
|
rOk, rSerial := program.getSerial("reference", refResponse)
|
||||||
if !(cOk && rOk) {
|
if !(cOk && rOk) {
|
||||||
program.plugin.SetState(plugin.UNKNOWN, "could not read serials")
|
program.plugin.SetState(plugin.StatusUnknown, "could not read serials")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if cSerial == rSerial {
|
if cSerial == rSerial {
|
||||||
program.plugin.SetState(plugin.OK, "serials match")
|
program.plugin.SetState(plugin.StatusOK, "serials match")
|
||||||
} else {
|
} else {
|
||||||
program.plugin.SetState(plugin.CRITICAL, "serials mismatch")
|
program.plugin.SetState(plugin.StatusCritical, "serials mismatch")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ type Plugin struct {
|
||||||
func New(name string) *Plugin {
|
func New(name string) *Plugin {
|
||||||
p := new(Plugin)
|
p := new(Plugin)
|
||||||
p.name = name
|
p.name = name
|
||||||
p.status = UNKNOWN
|
p.status = StatusUnknown
|
||||||
p.message = "no status set"
|
p.message = "no status set"
|
||||||
p.perfData = make(map[string]*perfdata.PerfData)
|
p.perfData = make(map[string]*perfdata.PerfData)
|
||||||
return p
|
return p
|
||||||
|
|
|
@ -7,10 +7,10 @@ type Status int
|
||||||
|
|
||||||
// Plugin exit statuses.
|
// Plugin exit statuses.
|
||||||
const (
|
const (
|
||||||
OK Status = iota
|
StatusOK Status = iota
|
||||||
WARNING
|
StatusWarning
|
||||||
CRITICAL
|
StatusCritical
|
||||||
UNKNOWN
|
StatusUnknown
|
||||||
)
|
)
|
||||||
|
|
||||||
// String representations of the plugin statuses.
|
// String representations of the plugin statuses.
|
||||||
|
|
Loading…
Reference in a new issue