Take the Hassle Out of Nagios with Mozzo

I got tired of opening a browser to ack Nagios alerts so here’s a lightweight CLI for acknowledging and managing Nagios Core alerts, with no browser required. It picks up where my Ansible-based Nagios automation post from 2016 left off, and pairs with the ansible-nagios playbook I still maintain.

Why I Built Mozzo

For years the only way to acknowledge a Nagios alert was to open the web interface in a browser, click through to the offending host or service, and type an ack comment by hand. On a pager full of pages that gets old fast, and from a sysadmin/devops/SRE perspective it was baffling that nothing else existed. Every other monitoring stack had a CLI or an API wrapper of some kind, but Nagios Core left you staring at HTML forms.

Mozzo fixes that. It talks directly to your Nagios Core installation through its native cmd.cgi and statusjson.cgi endpoints over HTTPS, so there are no special Nagios libraries to install and no fragile HTML scraping. One config file, one command, and you are acknowledging alerts from a terminal, an SSH session, or a cron job.

What Mozzo Can Do

  • Acknowledge a single service, a whole host, or everything alerting at once
  • Schedule downtime per host or service, with custom duration and messages
  • Enable and disable alerting per service, per host, or globally
  • List unhandled alerts and drill into plugin output
  • Review acknowledgement history and recent Nagios logs from the CLI
  • Generate uptime and reporting data per host and service, exportable as JSON or CSV

Why Still Nagios?

Yes, Nagios has been around forever, and its web interface is hardly a showcase of modern design. But “old” is not the same as “abandoned.” Nagios Core is actively maintained, and underneath the crusty UI sits one of the simplest, most reliable monitoring engines you can run.

It is a compact C/Perl codebase that stays out of your way, and it scales remarkably well.  It can scale to tens to hundreds of thousands of hosts across a fleet, comfortably served from a small VM. I have leaned on it for years across environments of every size and it just keeps quietly doing its job while fancier platforms come and go.

The hidden cost of the heavyweight alternatives is their own operational weight, at some point you end up needing a monitoring system for your monitoring system. Nagios does one thing, does it well, and Mozzo handles the part that actually used to hurt, acknowledging and managing alerts without a browser.

Installation

Mozzo is a single Python project, tested against Nagios Core 4.4.x. Grab it from source, install it in a virtual environment, or pull it straight from PyPI.

Run from source (requires python3-requests and python3-pyyaml):

git clone https://github.com/sadsfae/mozzo.git
cd mozzo
chmod +x mozzo.py
./mozzo.py --help

Or install it properly in a virtual environment:

git clone https://github.com/sadsfae/mozzo.git
cd mozzo
python -m venv .venv
source .venv/bin/activate
pip install .
mozzo --help

Or pull it from PyPI:

python -m venv mozzo-venv
source mozzo-venv/bin/activate
pip install mozzo

Configuration

Mozzo looks for its config.yml in ~/.config/mozzo/config.yml, then ./config.yml, then /etc/mozzo/config.yml. The example file in the repo is a good starting point:

nagios_server: https://nagios.example.com
nagios_cgi_path: /nagios/cgi-bin
nagios_username: nagiosadmin
nagios_password: mysecurepassword
default_downtime: 120 # in minutes
default_reporting_days: 365 # in days
verify_ssl: false
date_format: "%m-%d-%Y %H:%M:%S"

Everyday Usage

Want to see what is broken? You have one command for the whole fleet.

mozzo --unhandled

Ack a single service, or a host and everything on it:

mozzo --ack --host host01.example.com --service "HTTP"
mozzo --ack --host host01.example.com --all-services

Maintenance window? Schedule downtime instead of spamming the pager:

mozzo --set-downtime --host host01.example.com --all-services -m "Patching window"

When everything is on fire, ack all unhandled WARNING, CRITICAL, and UNKNOWN services in one go:

mozzo --ack --all

Kick off a maintenance envelope and check uptime later in one line, flip the JSON or CSV into your reporting:

mozzo --status --host host01.example.com --service "DNS" --uptime --format json > dns_uptime.json

Wrap Up

Mozzo is on GitHub and PyPI, with pull requests welcome against the development branch. If you are still deploying Nagios by hand, the ansible-nagios playbook and my original post from 2016 cover the deployment side. Now the acking finally works from a terminal, and the browser stays a nice-to-have.

Unknown's avatar

About Will Foster

hobo devop/sysadmin/SRE
This entry was posted in open source, sysadmin and tagged , , , . Bookmark the permalink.

Have a Squat, Leave a Reply ..

This site uses Akismet to reduce spam. Learn how your comment data is processed.