atc0005 / go-nagios

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

Threshold checks aren't implemented/don't work #176

Closed infraweavers closed 1 year ago

infraweavers commented 1 year ago

Hiya,

Just been converting some of our slower perl checks over to golang, hoped to use this library as a drop-in replacement for https://metacpan.org/dist/Monitoring-Plugin.

It almost looks like the mechanism is there, however at the moment it is entirely "on the plugin" to do things like "if the value is over the warning threshold then set the plugin to warning" etc (unless I have completely missed the feature?).

The https://metacpan.org/dist/Monitoring-Plugin solves this problem by implementing a generic check_threshold method like:

$code = $np->check_threshold(
  check => $value,
  warning => $warning_threshold,
  critical => $critical_threshold,
);

We are looking at implementing the same framework so it would probably be something like:

perfdata := nagios.PerformanceData{
    Label:             outputValue.InstanceName,
    Value:             outputValue.Value,
    UnitOfMeasurement: *counterUnit,
    Warn: warningThreshold.value
    Crit: criticalThreshold.value
}

plugin.AddPerfData(false, perfdata)
plugin.EvaluateThreshold(perfdata)

The call to EvalulateThreshold would set the status of the plugin in accordance with the value against the threshold

atc0005 commented 1 year ago

Hi @infraweavers,

Thanks for opening this GH issue.

In short, I've been building out this library to support plugins that I've developed as I've needed functionality. Not all of the pieces fit together seamlessly, but the library as a whole is usable.

While the recent releases have been focused on adding documentation and smoothing out rough edges, this library has a lot of work left before I'd feel comfortable positioning it as a replacement for any existing options (Go or any other language).

I'm open to adding support such as you've mentioned, but need to consider the changes.

I hope to respond in further detail in the next few days (limited dev time recently).

infraweavers commented 1 year ago

Thanks for the reply. I'm glad I just didn't miss the functionality somewhere :)

Given that we've already added the functionality in an in-lined copy we have in our project, we might as well PR our implementation later on today so you can have a look. At a minimum it can form a discussion point or a basis to be tweaked/converted across to your preferred style/approach etc.