Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
28 changes: 0 additions & 28 deletions .github/workflows/build.yml

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Build
run: make build

- name: Test
run: make test
69 changes: 69 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: golangci-lint
on:
push:
branches:
- master
- main
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues`
# option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
# Require: The version of golangci-lint to use.
#
# When `install-mode` is `binary` (default) the value can be v1.2 or
# v1.2.3 or `latest` to use the latest version.
#
# When `install-mode` is `goinstall` the value can be v1.2.3,
# `latest`, or the hash of a commit.
version: 'latest'

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
#
# Note: By default, the `.golangci.yml` file should be at the root of
# the repository.
#
# The location of the configuration file can be changed by using
# `--config=`.
#
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default
# value is `false`.
# only-new-issues: true

# Optional: if set to true, then all caching functionality will be
# completely disabled, takes precedence over all other caching
# options.
# skip-cache: true

# Optional: if set to true, then the action won't cache or restore
# ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true, then the action won't cache or restore
# ~/.cache/go-build.
# skip-build-cache: true

# Optional: The mode to install golangci-lint. It can be 'binary' or
# 'goinstall'.
# install-mode: "goinstall"
40 changes: 0 additions & 40 deletions .github/workflows/lint.yml

This file was deleted.

30 changes: 0 additions & 30 deletions .github/workflows/test.yml

This file was deleted.

49 changes: 49 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
run:
timeout: 5m

linters:
enable:
- asciicheck
- bidichk
- errorlint
- gocritic
# - gofmt # we are using gofumpt instead
- gofumpt
- goimports
- makezero
- misspell
- nolintlint
- perfsprint
- prealloc
- testifylint
- unconvert
- usestdlibvars
- wastedassign
- wrapcheck

linters-settings:
goimports:
# A comma-separated list of prefixes, which, if set, checks import paths
# with the given prefixes are grouped after 3rd-party packages.
# Default: ""
local-prefixes: "github.com/inexio/go-monitoringplugin"

nolintlint:
# Enable to require an explanation of nonzero length after each nolint directive.
# Default: false
require-explanation: true
# Enable to require nolint directives to mention the specific linter being suppressed.
# Default: false
require-specific: true

revive:
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#receiver-naming
- name: receiver-naming
disabled: true

issues:
exclude-rules:
- path: _test\.go
linters:
- wrapcheck
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
TEST_ARGS=

test:
go test ${TEST_ARGS} ./...

build:
go build -ldflags="-s -w" ./

clean:
rm -f check_wg
98 changes: 61 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,71 @@
# go-monitoringplugin


[![Go Report Card](https://goreportcard.com/badge/github.com/inexio/go-monitoringplugin)](https://goreportcard.com/report/github.com/inexio/go-monitoringplugin)
[![GitHub license](https://img.shields.io/badge/license-BSD-blue.svg)](https://github.com/inexio/go-monitoringplugin/blob/master/LICENSE)
[![GoDoc doc](https://img.shields.io/badge/godoc-reference-blue)](https://godoc.org/github.com/inexio/go-monitoringplugin)

## Description
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.

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.

The package complies with the [Monitoring Plugins Development Guidelines](https://www.monitoring-plugins.org/doc/guidelines.html).

## Example / Usage
package main

import (
monitoringplugin "github.com/inexio/go-monitoringplugin"
)

func main() {
//Creating response with a default ok message that will be displayed when the checks exits with status ok
response := monitoringplugin.NewResponse("everything checked!")

//Set output delimiter (default is \n)
//response.SetOutputDelimiter(" / ")

//updating check plugin status and adding message to the ouput (status only changes if the new status is worse than the current one)
response.UpdateStatus(monitoringplugin.OK, "something is ok!") //check status stays ok
response.UpdateStatus(monitoringplugin.CRITICAL, "something else is critical!") //check status updates to critical
response.UpdateStatus(monitoringplugin.WARNING, "something else is warning!") //check status stays critical, but message will be added to the output


//adding performance data
err := response.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("response_time", 10, "s").SetWarn(10).SetCrit(20).SetMin(0))
if err != nil {
//error handling
}
err = response.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("memory_usage", 50, "%").SetWarn(80).SetCrit(90).SetMin(0).SetMax(100))
if err != nil {
//error handling
}

response.OutputAndExit()
/* exits program with exit code 2 and outputs:
CRITICAL: something is ok!
something else is critical!
something else is warning! | 'response_time'=10s;10;20;0; 'memory_usage'=50%;80;90;0;100
*/

``` go
package main

import "github.com/inexio/go-monitoringplugin/v2"

func main() {
// Creating response with a default ok message, that will be displayed when
// the checks exits with status ok.
response := monitoringplugin.NewResponse("everything checked!")

// Set output delimiter (default is \n)
// response.SetOutputDelimiter(" / ")

// Updating check plugin status and adding message to the output (status only
// changes if the new status is worse than the current one).

// check status stays ok
response.UpdateStatus(monitoringplugin.OK, "something is ok!")
// check status updates to critical
response.UpdateStatus(monitoringplugin.CRITICAL,
"something else is critical!")
// check status stays critical, but message will be added to the output
response.UpdateStatus(monitoringplugin.WARNING, "something else is warning!")

// adding performance data
p1 := monitoringplugin.NewPerformanceDataPoint("response_time", 10).
SetUnit("s").SetMin(0)
p1.NewThresholds(0, 10, 0, 20)
if err := response.AddPerformanceDataPoint(p1); err != nil {
// error handling
}

p2 := monitoringplugin.NewPerformanceDataPoint("memory_usage", 50.6).
SetUnit("%").SetMin(0).SetMax(100)
p2.NewThresholds(0, 80, 0, 90)
if err := response.AddPerformanceDataPoint(p2); err != nil {
// error handling
}

err = response.AddPerformanceDataPoint(
monitoringplugin.NewPerformanceDataPoint("memory_usage", 50.6).
SetUnit("%").SetMin(0).SetMax(100).
SetThresholds(monitoringplugin.NewThresholds(0, 80.0, 0, 90.0)))
if err != nil {
// error handling
}

response.OutputAndExit()
/* exits program with exit code 2 and outputs:
CRITICAL: something is ok!
something else is critical!
something else is warning! | 'response_time'=10s;10;20;0; 'memory_usage'=50%;80;90;0;100
*/
}
```
Loading