atc0005 / go-nagios

Shared Golang package for Nagios plugins
MIT License
8 stars 3 forks source link

Add NagiosExitState type #6

Closed atc0005 closed 4 years ago

atc0005 commented 4 years ago

From https://github.com/atc0005/check-mail/blob/2d0f8a76772293b2a934904275b198e67287cabd/cmd/check_imap_mailbox/main.go#L38-L42:

// NagiosExitState represents the last known execution state of the
// application, including the most recent error and the final intended plugin
// state.
type NagiosExitState struct {
    LastError  error
    StatusCode int
    Message    string
}

I suspect that this can be refined further to cover additional use cases, but as of this writing I've found myself using the same type in two different projects, so it feels like a good idea to add it to this one for near-future refactoring efforts.

atc0005 commented 4 years ago

https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/macrolist.html#longserviceoutput

Macro Name Description
$SERVICEOUTPUT$ The first line of text output from the last service check (i.e. "Ping OK").
$LONGSERVICEOUTPUT$ The full text output (aside from the first line) from the last service check.

Perhaps this would be a better fit:

type NagiosExitState struct {
    LastError         error
    StatusCode        int
    ServiceOutput     string
    LongServiceOutput string
}

Change from earlier variation:

This allows the field names of this type to match the official docs.

atc0005 commented 4 years ago

I later modified the struct in the atc0005/check-cert project (not yet public, more cleanup needed) to include a field for an optional function call just before application exit. Not sure if that functionality is applicable for normal use cases.

atc0005 commented 4 years ago

I later modified the struct in the atc0005/check-cert project (not yet public, more cleanup needed) to include a field for an optional function call just before application exit. Not sure if that functionality is applicable for normal use cases.

I think it will be for Nagios projects that I work with, so for now I'll leave it in to see how it works in practice.