{"id":18906497,"url":"https://github.com/claranet/nagitheus","last_synced_at":"2025-04-15T04:31:36.206Z","repository":{"id":30909591,"uuid":"126353083","full_name":"claranet/nagitheus","owner":"claranet","description":"Nagios Check towards Prometheus","archived":false,"fork":false,"pushed_at":"2023-06-20T08:45:07.000Z","size":42,"stargazers_count":24,"open_issues_count":1,"forks_count":7,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-28T00:34:32.587Z","etag":null,"topics":["check","nagios","plugin","prometheus"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/claranet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-22T15:07:08.000Z","updated_at":"2024-12-16T00:32:21.000Z","dependencies_parsed_at":"2024-06-20T14:09:57.522Z","dependency_job_id":null,"html_url":"https://github.com/claranet/nagitheus","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/claranet%2Fnagitheus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/claranet%2Fnagitheus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/claranet%2Fnagitheus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/claranet%2Fnagitheus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/claranet","download_url":"https://codeload.github.com/claranet/nagitheus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249006446,"owners_count":21197279,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["check","nagios","plugin","prometheus"],"created_at":"2024-11-08T09:16:30.772Z","updated_at":"2025-04-15T04:31:35.952Z","avatar_url":"https://github.com/claranet.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Check Prometheus from Nagios\n\n\u003c!-- vim-markdown-toc GFM --\u003e\n\n* [What](#what)\n* [TL;DR](#tldr)\n* [Why](#why)\n* [How to build](#how-to-build)\n* [How to run](#how-to-run)\n* [Usage](#usage)\n* [Debug](#debug)\n* [Label](#label)\n* [Method](#method)\n* [Basic auth](#basic-auth)\n\n\u003c!-- vim-markdown-toc --\u003e\n\n## What\n\nA Nagios plugin for querying Prometheus.\n\n## TL;DR\n\n```\n$ docker run -it claranet/nagitheus:latest -h\n```\n\n## Why\n\nThis tool has been inspired by the upstream provided shell script to be found [here](https://github.com/prometheus/nagios_plugins). But unfortunately this shell script is deficient in several ways.\nNagitheus instead:\n\n1. It actually works :)\n2. No need to specify if vector or scalar\n3. It doesn't stop at the first result but iterates over whole vector\n4. Ability to print desired label\n5. Go binary: no need of specific software on the nagios monitoring\n\n## How to build\n\nbuild:\n```\n$ go build nagitheus.go\nor from mac to linux\nenv GOOS=linux GOARCH=amd64 go build nagitheus.go\n````\nrun:\n```\n $ ./nagitheus -H \"https://prometheus.example.com\" -q \"Prometheus Query\" -w 2  -c 2 -u username -p PASSWORD -m le  -l label\n```\n## How to run\n```\n$ go run nagitheus.go -H 'https://prometheus.mgt.domain.com' -q \"(kubelet_volume_stats_used_bytes/kubelet_volume_stats_capacity_bytes*100)\u003e2\" -w 2  -c 5  -m ge -u UN -p PW -l persistentvolumeclaim\nWARNING prometheus-kube-prometheus-db-prometheus-kube-prometheus-0 is 2.2607424766047886 CRITICAL prometheus-kube-prometheus-db-prometheus-kube-prometheus-0 is 5.625835543270624\nexit status 2\n```\n## Usage\n\n```\n  -H string\n      Host to query (Required, i.e. https://example.prometheus.com)\n  -q string\n      Prometheus query (Required)\n  -w string\n      Warning treshold (Required)\n  -c string\n      Critical treshold (Required)\n  -d string\n      Print whole prometheus result to output (Optional) (default \"no\")\n  -l string\n      Label to print (Optional) (default \"none\")\n  -f string\n      Format message with go template (Optional)\n  -m string\n      Comparison method (Optional) (default \"ge\")\n  -u string\n      Username (Optional)\n  -p string\n      Password (Optional)\n  -t string\n      Token (Optional)\n  --critical-on-missing\n      Return CRITICAL if query results are missing (Optional) (default \"no\")\n  --max-chars\n      Max. count of characters to print\n  --print-details\n      Prints all returned values on multiline result\n  --print-perf-data\n\t    Prints performance data for results in the format `query_result=\u003cresult\u003e;\u003cwarning\u003e;\u003ccritical\u003e`\n  --value-mapping string\n    \tMapping result metrics for output (Optional, json i.e. '{\"0\":\"down\",\"1\":\"up\"}')\n  --value-unit string\n    \tUnit of the value for output (Optional, i.e. '%')\n  -v  Prints nagitheus version\n\n```\nThis software will perform a request on the prometheus server. Required flags are the Host, Query, Warning and Critical.\n\n## Debug\n\n`-d yes` will print to outputn the whole response from Prometheus (best used from command line and not from Nagios):\n```\nPrometheus response: {\n  \"status\": \"success\",\n  \"data\": {\n    \"resultType\": \"vector\",\n    \"result\": [\n      {\n        \"metric\": {\n          \"endpoint\": \"http-metrics\",\n          \"exported_namespace\": \"aux\",\n          \"instance\": \"10.42.0.2:10255\",\n          \"job\": \"kubelet\",\n          \"namespace\": \"kube-system\",\n          \"persistentvolumeclaim\": \"prometheus-kube-prometheus-db-prometheus-kube-prometheus-0\",\n          \"service\": \"kubelet\"\n        },\n        \"value\": [\n          1521551995.114,\n          \"2.2607424766047886\"\n        ]\n      },\n      {\n        \"metric\": {\n          \"endpoint\": \"http-metrics\",\n          \"exported_namespace\": \"aux\",\n          \"instance\": \"10.42.0.4:10255\",\n          \"job\": \"kubelet\",\n          \"namespace\": \"kube-system\",\n          \"persistentvolumeclaim\": \"prometheus-kube-prometheus-db-prometheus-kube-prometheus-0\",\n          \"service\": \"kubelet\"\n        },\n        \"value\": [\n          1521551995.114,\n          \"5.625835543270624\"\n        ]\n      }\n    ]\n  }\n}\n```\n## Output\nIf the result contains multiple values, the output returns a summary and multiline results.\n\n## Label\n\n`-l labelname` takes a label that you want to print toghether with Status and value:\n```\nCRITICAL 1 persistentvolumeclaim critical, 1 persistentvolumeclaim warning, 0 persistentvolumeclaim ok :\n------\nCRITICAL persistentvolumeclaim prometheus-kube-prometheus-db-prometheus-kube-prometheus-0 is 5.625835543270624\nWARNING persistentvolumeclaim prometheus-kube-prometheus-db-prometheus-kube-prometheus-0 is 2.2607424766047886\n```\nWithout the label the result would be:\n```\nCRITICAL 1 item critical, 1 item warning, 0 item ok :\n------\nWARNING value is 2.2607424766047886\nCRITICAL value is 5.625835543270624\n```\n\n## Format\n`-f formatstring` take a go template string to print status the way you want. Some variables are available for display.\n* `Label`\n* `Value`\n* `Metric` Map of metrics returned from prometheus that you can access with `{{.Metric.\u003cmetric_name\u003e}}`\n\nExample:\n```\n-f '{{.Metric.node}}: {{.Metric.condition}} is {{.Value}}' --value-mapping '{\"1\":\"KO\",\"0\":\"OK\"}'\n```\nWill output\n```\nWARNING 0 condition critical, 1 condition warning, 2 condition ok :\n------\nWARNING kube-node-1: FrequentContainerdRestart is KO\nOK kube-node-1: CorruptDockerOverlay2 is OK\nOK kube-node-2: CorruptDockerOverlay2 is OK\nOK kube-node-2: FrequentContainerdRestart is OK\n```\n\n## Method\n\n`-m ge OR gt OR le OR lt` tells the check how to compare the result with the critical and warning flags \n\n## Basic auth\n`-u username -p password` when both are set the request will be performed with basic auth\n\n## Token\n`-t token` the request will be performed adding the token to headers\n\nFor example in Openshift you need to do\n```\nTOKEN=$(oc whoami -t)\n-t $TOKEN\n```\n\n## Value Mapping\n`-value-mapping \u003cjson key-value pairs\u003e` allow mapping of the result values to defined strings for output, e.g. 0=\u003eDOWN, 1=\u003e UP:\n```\n./nagitheus -H 'https://prometheus.mgt.domain.com' -q 'up{job=\"prometheus\"}' -c 1 -w 1 -m lt -l job -value-mapping '{\"0\":\"DOWN\",\"1\":\"UP\"}'\n```\nreturns\n```\nOK job prometheus is UP\n```\n\n## Value Unit\n`-value-unit \u003cunit\u003e` allows adding a unit to the output result values, e.g. '%', 'GB':\n```\nWARNING persistentvolumeclaim prometheus-kube-prometheus-db-prometheus-kube-prometheus-0 is 2.2607424766047886 %\nCRITICAL persistentvolumeclaim prometheus-kube-prometheus-db-prometheus-kube-prometheus-0 is 5.625835543270624 %\n```\n\n## Version\n`-v` returns the version of nagitheus\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclaranet%2Fnagitheus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclaranet%2Fnagitheus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclaranet%2Fnagitheus/lists"}