plugin - "Fixed" comments to silence go-lint
This commit is contained in:
parent
916dc35de6
commit
fc5f4c1638
1 changed files with 20 additions and 16 deletions
|
@ -1,19 +1,22 @@
|
||||||
// Package that represents a monitoring plugin.
|
// Package plugin implements a helper that can be used to implement a Nagios,
|
||||||
|
// Centreon, Icinga... service monitoring plugin.
|
||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"container/list"
|
"container/list"
|
||||||
"fmt"
|
"fmt"
|
||||||
"nocternity.net/monitoring/perfdata"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"nocternity.net/monitoring/perfdata"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Return status of the monitoring plugin. The corresponding integer
|
// Status represents the return status of the monitoring plugin. The
|
||||||
// value will be used as the program's exit code, to be interpreted
|
// corresponding integer value will be used as the program's exit code,
|
||||||
// by the monitoring system.
|
// to be interpreted by the monitoring system.
|
||||||
type Status int
|
type Status int
|
||||||
|
|
||||||
|
// Plugin exit statuses.
|
||||||
const (
|
const (
|
||||||
OK Status = iota
|
OK Status = iota
|
||||||
WARNING
|
WARNING
|
||||||
|
@ -21,13 +24,14 @@ const (
|
||||||
UNKNOWN
|
UNKNOWN
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// String representations of the plugin statuses.
|
||||||
func (s Status) String() string {
|
func (s Status) String() string {
|
||||||
return [...]string{"OK", "WARNING", "ERROR", "UNKNOWN"}[s]
|
return [...]string{"OK", "WARNING", "ERROR", "UNKNOWN"}[s]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Monitoring plugin state, including a name, return status and message,
|
// Plugin represents the monitoring plugin's state, including its name,
|
||||||
// additional lines of text, and performance data to be encoded in the
|
// return status and message, additional lines of text, and performance
|
||||||
// output.
|
// data to be encoded in the output.
|
||||||
type Plugin struct {
|
type Plugin struct {
|
||||||
name string
|
name string
|
||||||
status Status
|
status Status
|
||||||
|
@ -36,7 +40,7 @@ type Plugin struct {
|
||||||
perfData map[string]*perfdata.PerfData
|
perfData map[string]*perfdata.PerfData
|
||||||
}
|
}
|
||||||
|
|
||||||
// `New` creates the plugin with `name` as its name and an unknown status.
|
// New creates the plugin with `name` as its name and an unknown status.
|
||||||
func New(name string) *Plugin {
|
func New(name string) *Plugin {
|
||||||
p := new(Plugin)
|
p := new(Plugin)
|
||||||
p.name = name
|
p.name = name
|
||||||
|
@ -46,7 +50,7 @@ func New(name string) *Plugin {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// `SetState` sets the plugin's output code to `status` and its message to
|
// SetState sets the plugin's output code to `status` and its message to
|
||||||
// the specified `message`. Any extra text is cleared.
|
// the specified `message`. Any extra text is cleared.
|
||||||
func (p *Plugin) SetState(status Status, message string) {
|
func (p *Plugin) SetState(status Status, message string) {
|
||||||
p.status = status
|
p.status = status
|
||||||
|
@ -54,7 +58,7 @@ func (p *Plugin) SetState(status Status, message string) {
|
||||||
p.extraText = nil
|
p.extraText = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// `AddLine` adds `line` to the extra output text.
|
// AddLine adds the specified string to the extra output text buffer.
|
||||||
func (p *Plugin) AddLine(line string) {
|
func (p *Plugin) AddLine(line string) {
|
||||||
if p.extraText == nil {
|
if p.extraText == nil {
|
||||||
p.extraText = list.New()
|
p.extraText = list.New()
|
||||||
|
@ -62,16 +66,16 @@ func (p *Plugin) AddLine(line string) {
|
||||||
p.extraText.PushBack(line)
|
p.extraText.PushBack(line)
|
||||||
}
|
}
|
||||||
|
|
||||||
// `AddLines` add the specified `lines` to the output text.
|
// AddLines add the specified `lines` to the output text.
|
||||||
func (p *Plugin) AddLines(lines []string) {
|
func (p *Plugin) AddLines(lines []string) {
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
p.AddLine(line)
|
p.AddLine(line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// `AddPerfData` adds performance data described by `pd` to the output's
|
// AddPerfData adds performance data described by the "pd" argument to the
|
||||||
// performance data. If two performance data records are added for the same
|
// output's performance data. If two performance data records are added for
|
||||||
// label, the program panics.
|
// the same label, the program panics.
|
||||||
func (p *Plugin) AddPerfData(pd *perfdata.PerfData) {
|
func (p *Plugin) AddPerfData(pd *perfdata.PerfData) {
|
||||||
_, exists := p.perfData[pd.Label]
|
_, exists := p.perfData[pd.Label]
|
||||||
if exists {
|
if exists {
|
||||||
|
@ -80,7 +84,7 @@ func (p *Plugin) AddPerfData(pd *perfdata.PerfData) {
|
||||||
p.perfData[pd.Label] = pd
|
p.perfData[pd.Label] = pd
|
||||||
}
|
}
|
||||||
|
|
||||||
// `Done` generates the plugin's text output from its name, status, text data
|
// Done generates the plugin's text output from its name, status, text data
|
||||||
// and performance data, before exiting with the code corresponding to the
|
// and performance data, before exiting with the code corresponding to the
|
||||||
// status.
|
// status.
|
||||||
func (p *Plugin) Done() {
|
func (p *Plugin) Done() {
|
||||||
|
|
Loading…
Reference in a new issue