| 1 |
# go-monitoringplugin |
| 2 |
|
| 3 |
|
| 4 |
[](https://goreportcard.com/report/github.com/inexio/go-monitoringplugin) |
| 5 |
[](https://github.com/inexio/go-monitoringplugin/blob/master/LICENSE) |
| 6 |
[](https://godoc.org/github.com/inexio/go-monitoringplugin) |
| 7 |
## Description |
| 8 |
Golang package for writing monitoring check plugins for [nagios](https://www.nagios.org/), [icinga2](https://icinga.com/), [zabbix](https://www.zabbix.com/), [checkmk](https://checkmk.com/), etc. |
| 9 |
The package complies with the [Monitoring Plugins Development Guidelines](https://www.monitoring-plugins.org/doc/guidelines.html). |
| 10 |
|
| 11 |
## Example / Usage |
| 12 |
package main |
| 13 |
|
| 14 |
import ( |
| 15 |
monitoringplugin "github.com/inexio/go-monitoringplugin" |
| 16 |
) |
| 17 |
|
| 18 |
func main() { |
| 19 |
//Creating response with a default ok message that will be displayed when the checks exits with status ok |
| 20 |
response := monitoringplugin.NewResponse("everything checked!") |
| 21 |
|
| 22 |
//Set output delimiter (default is \n) |
| 23 |
//response.SetOutputDelimiter(" / ") |
| 24 |
|
| 25 |
//updating check plugin status and adding message to the ouput (status only changes if the new status is worse than the current one) |
| 26 |
response.UpdateStatus(monitoringplugin.OK, "something is ok!") //check status stays ok |
| 27 |
response.UpdateStatus(monitoringplugin.CRITICAL, "something else is critical!") //check status updates to critical |
| 28 |
response.UpdateStatus(monitoringplugin.WARNING, "something else is warning!") //check status stays critical, but message will be added to the output |
| 29 |
|
| 30 |
|
| 31 |
//adding performance data |
| 32 |
err := response.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("response_time", 10, "s").SetWarn(10).SetCrit(20).SetMin(0)) |
| 33 |
if err != nil { |
| 34 |
//error handling |
| 35 |
} |
| 36 |
err = response.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("memory_usage", 50, "%").SetWarn(80).SetCrit(90).SetMin(0).SetMax(100)) |
| 37 |
if err != nil { |
| 38 |
//error handling |
| 39 |
} |
| 40 |
|
| 41 |
response.OutputAndExit() |
| 42 |
/* exits program with exit code 2 and outputs: |
| 43 |
CRITICAL: something is ok! |
| 44 |
something else is critical! |
| 45 |
something else is warning! | 'response_time'=10s;10;20;0; 'memory_usage'=50%;80;90;0;100 |
| 46 |
*/ |
| 47 |
} |