Categorygithub.com/linode-obs/nagios_exporter
modulepackage
1.2.4
Repository: https://github.com/linode-obs/nagios_exporter.git
Documentation: pkg.go.dev

# README

nagios_exporter

Github Release Downloads license golangci-lint Go Report Card contributions

A Prometheus exporter currently supporting:

  • Nagios XI
  • Nagios Core 4
  • Nagios Core 3
  • CheckMK

It includes metrics on the current state and configuration of Nagios. This includes the number of hosts, services, and information about their monitoring setup. For example, this exporter will output the number of flapping hosts, passive checks, or hosts in downtime.

Practical use cases for this exporter may include:

  • A Nagios overview - see broad status of hosts and services
  • Visualize changes in host status after making adjustments to Nagios checks
  • Detect an uptick in unknown check results after converting many active checks to passive

This exporter does not output Nagios check results as Prometheus metrics; it is designed to export metrics of the Nagios monitoring server itself for meta-monitoring.

Table of Contents

Installation

Debian/RPM package

Substitute {{ version }} for your desired release.

wget https://github.com/linode-obs/nagios_exporter/releases/download/v{{ version }}/prometheus-nagios-exporter_{{ version }}_linux_amd64.{deb,rpm}
{dpkg,rpm} -i prometheus-nagios-exporter_{{ version }}_linux_amd64.{deb,rpm}

Docker

Populate config.toml with your APIKey = NagiosXIAPIKey

sudo docker run \
-v ./config.toml:/etc/prometheus-nagios-exporter/config.toml \
ghcr.io/linode-obs/nagios_exporter \
--nagios.scrape-uri http://localhost

Binary

wget https://github.com/linode-obs/nagios_exporter/releases/download/v{{ version }}/nagios_exporter_{{ version }}_Linux_x86_64.tar.gz
tar xvf nagios_exporter_{{ version }}_Linux_x86_64.tar.gz
./nagios_exporter/prometheus-nagios-exporter

Source

wget https://github.com/linode-obs/nagios_exporter/archive/refs/tags/v{{ version }}.tar.gz
tar xvf nagios_exporter-{{ version }}.tar.gz
cd ./nagios_exporter-{{ version }}
go build nagios_exporter.go
./nagios_exporter.go

Configuration

Create a simple config.toml in /etc/prometheus-nagios-exporter with your Nagios API key:

# prometheus-nagios-exporter configuration

APIKey = ""

Configuration File

In TOML format.

Environment VariableDescriptionDefaultRequired
APIKeyThe NagiosXI API key if exporting NagiosXI api-specific metrics

CLI

To see all available configuration flags:

./prometheus-nagios-exporter -h
CLI FlagDescriptionDefaultRequired
---config.pathConfiguration file path, only for API key/etc/prometheus-nagios-exporter/config.toml
--log.levelMinimum log level like "debug" or "info"info
--nagios.check-updatesEnable optional nagios_update_available_info metricfalse
--nagios.config_pathNagios configuration path for use with nagiostats binary/usr/local/nagios/etc/nagios.cfg
--nagios.scrape-uriNagios application address to scrapehttp://localhost
--nagios.ssl-verifySSL certificate validationfalse
--nagios.stats_binaryPath of nagiostats binary and configuration (e.g /usr/local/nagios/bin/nagiostats)
--nagios.timeoutTimeout for querying Nagios API in seconds (on big installations I recommend ~60)5
--web.listen-addressAddress to listen on for telemetry (scrape port)9927
--web.telemetry-pathPath under which to expose metrics/metrics

Nagios Core 3/4 support

This exporter also supports Nagios Core 3/4 and CheckMK, albeit with a subset of metrics and reliance on the nagiosstats binary. There is no RESTful API for either monitoring platform, so the exporter must be run directly on the Nagios host and have access to execute nagiostats.

It is also recommended to pass the path of the Nagios configuration

Typical location and usage of the binary:

  • Nagios Core 3/4:
    • --nagios.stats_binary: /usr/local/nagios/bin/nagiostats
    • --nagios.config_path: /usr/local/nagios/etc/nagios.cfg
  • CheckMK:
    • --nagios.stats_binary: /omd/sites/<your-site>/bin/nagiostats
    • --nagios.config_path: /omd/sites/<your-site>/tmp/nagios/nagios.cfg

Example usage:

./nagios_exporter --nagios.stats_binary "/usr/local/nagios/bin/nagiostats" --nagios.config_path "/usr/local/nagios/etc/nagios.cfg"

Note that this flag nullifies all others. It cannot be used in conjunction with the Nagios XI API.

Metrics

Click to expand metrics
Metric NameDescriptionType
nagios_build_infoNagios exporter build informationgauge
nagios_host_checks_executionHost check executionhistogram
nagios_host_checks_latencyHost check latencyhistogram
nagios_host_checks_minutesHost checks over timehistogram
nagios_host_checks_performance_secondsHost checks performancegauge
nagios_hosts_acknowledges_totalAmount of host problems acknowledgedgauge
nagios_hosts_checked_totalAmount of hosts checkedgauge
nagios_hosts_downtime_totalAmount of hosts in downtimegauge
nagios_hosts_status_totalAmount of hosts in different statesgauge
nagios_hosts_totalAmount of hosts present in configurationgauge
nagios_service_checks_executionService check executionhistogram
nagios_service_checks_latencyService check latencyhistogram
nagios_service_checks_minutesService checks over timehistogram
nagios_service_checks_performance_secondsService checks performancegauge
nagios_services_acknowledges_totalAmount of service problems acknowledgedgauge
nagios_services_checked_totalAmount of services checkedgauge
nagios_services_downtime_totalAmount of services in downtimegauge
nagios_services_status_totalAmount of services in different statesgauge
nagios_services_totalAmount of services present in configurationgauge
nagios_upWhether Nagios can be reachedgauge
nagios_update_available_infoNagiosXI update is available (optional metric!)gauge
nagios_users_privileges_totalAmount of admin or regular usersgauge
nagios_users_status_totalAmount of disabled or enabled usersgauge
nagios_users_totalAmount of users present on the systemgauge
nagios_version_infoNagios version informationgauge

nagios_update_available_info is optional because the user may not want their Nagios server scraping the external version webpage every scrape_interval.

Grafana

Import the dashboard template (instructions).

grafana

Troubleshooting

Ensure nagios_up returns 1.

NagiosXI

Please check your API key and Nagios reachability:

curl -GET "http://<nagios_url>/nagiosxi/api/v1/objects/host?apikey=<apikey>&pretty=1"

Nagios Core 3/4, CheckMK

Ensure the user running the Nagios Exporter can execute nagiostats fully:

sudo su <prometheus-user> -s /bin/bash -c "/usr/local/nagios/bin/nagiostats -c /usr/local/nagios/etc/nagios.cfg"

Resources Used

Contributing

To build and run the Debian package, install go-releaser and run:

goreleaser release --clean --snapshot
# currently I develop on a VM running NagiosXI, but a container would be cool too
scp dist/prometheus-nagios-exporter_1.2.2-next_linux_386.deb root@<nagiosXI-VM-ip>:/root/
dpkg -i prometheus-nagios-exporter_1.2.2-next_linux_amd64.deb
# examine metrics
ssh root@<nagiosXI-VM-ip>
curl -s localhost:9927/metrics | grep "^nagios"

Install pre-commit hooks:

pre-commit install

Releasing

Follow goreleaser's quick start instructions.

# make changes, merge into main
export GITHUB_TOKEN="YOUR_GH_TOKEN"
git tag -a v<semver> -m "Release summary"
git push origin v<semver>
# login to ghcr too
# https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-with-a-personal-access-token-classic
echo $CR_PAT | docker login ghcr.io -u $USERNAME --password-stdin

goreleaser release

Contributors ✨

TJ Hoplock
TJ Hoplock

💻 🧑‍🏫

This project follows the all-contributors specification.

# Packages

No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
Build info for nagios exporter itself, will be populated by linker during build.

# Structs

https://stackoverflow.com/a/16491396.
No description provided by the author