On this page
- On this page
- What Is Ansible Monitoring?
- Why Ansible Monitoring Matters
- Ansible Monitoring Capabilities in Nagios XI
- Benefits of Nagios XI Ansible Monitoring
- Ansible Monitoring Prerequisites
- How To Monitor Ansible-Managed Infrastructure with Nagios XI
- Where Nagios XI Fits
- Frequently Asked Questions
- Related Solutions
- Put Monitoring Inside Your Automation Pipeline
- Updated 2 weeks ago
A playbook run finishes, twenty new Hosts are live, and monitoring knows about none of them. Or the reverse: patching starts at 2 a.m. and the on-call phone lights up with alerts for Services that were taken down on purpose. Nagios XI closes both gaps through its REST API, which lets an Ansible playbook create, update, and delete monitoring objects and schedule downtime as part of the same run that changes the infrastructure.
What Is Ansible Monitoring?
Ansible monitoring is the practice of keeping a monitoring system synchronized with infrastructure that Ansible provisions and configures, and of using monitoring state to drive automation in return. In a Nagios XI environment this means two directions of traffic: playbooks call the Nagios XI API to register Hosts and Services, schedule maintenance windows, and remove objects for decommissioned systems, while Nagios XI event handlers call scripts and playbooks when a Host or Service changes state.
Why Ansible Monitoring Matters
- New systems get monitored on day one: A Host added by a playbook appears in Nagios XI in the same run, instead of waiting for someone to remember it.
- Planned work stops paging people: Scheduling downtime before a patch window keeps notifications quiet for the systems you are deliberately touching.
- Decommissioned systems stop alerting: Removing a Host through the API at teardown time prevents Down alerts for machines that no longer exist.
- Configuration changes get verified: A playbook enforces a setting; a check confirms the setting is still in effect an hour later.
- Repeat work shrinks: Agent rollout, Host cloning, and object cleanup move from a console session to a repeatable, reviewable task.
- State changes trigger action: An event handler can restart a Service or launch a playbook the moment a check goes Critical.
Ansible Monitoring Capabilities in Nagios XI
Nagios XI REST API for Ansible Playbooks
The Nagios XI REST API reads, writes, updates, and deletes data in the system. Requests authenticate with a Nagios XI API key tied to a specific user, and responses return as JSON, so a playbook can call it from any machine that can reach the Nagios XI server.
- Objects: Read-only data about Hosts, Services, contacts, contact groups, logs, history, and downtime.
- Config: Admin-only endpoints that add, remove, and modify objects such as Hosts and Services.
- System: Admin-only endpoints that apply configuration, add and remove scheduled downtime, and run a mass immediate check.
- Applying changes inline: Append
applyconfig=1to a config call so the change takes effect without a second request. - Template-backed creation: Objects created from a template inherit directives such as
check_intervalandnotification_period;force=1creates an object from the directives you supply. - Shell escaping: Escape characters like
$and!in playbook-generated commands so the shell does not interpret them. - Live endpoint reference: Full endpoint documentation sits inside the interface at Help > Documentation > API Docs, pre-populated with your server URL and API key.
Documentation: How To Access And Use The REST API In Nagios XI
Automated Host Management from Ansible-Generated Configuration
Playbooks that already template configuration files can write Nagios object definitions instead of calling the API. Files ending in .cfg placed in /usr/local/nagios/etc/import/ are imported every time configuration is applied.
- One file per Host: Name the
.cfgfile after the Host and keep its Services in the same file, which makes later deletion predictable. - Single-Host Service definitions: Apply each Service definition to one Host rather than a Host list or hostgroup.
- Import and verify: Running
/usr/local/nagiosxi/scripts/reconfigure_nagios.shimports the directory, verifies the configuration, and restarts Nagios if verification succeeds. - Automatic rollback: If verification fails, Nagios XI restores the last working checkpoint, so a bad template does not take monitoring offline.
- Exit codes worth trapping: The script returns 0 for success and distinct nonzero codes for verification, import, permission, export, restart, and database failures. Fail the playbook task on anything but 0, because a broken configuration remains in the database and later changes will fail behind it.
- Ordered deletion: Remove Services before their Host. A Host cannot be deleted until every dependent relationship is gone.
Documentation: How To Automate Host Management In Nagios XI
Maintenance Window and Downtime Automation
Downtime suppresses notifications for objects you are working on. A playbook can schedule it through the System section of the API before a patch task and remove it afterward.
- Fixed downtime: Starts and stops at the exact times you specify, which suits a change window with a firm start.
- Flexible downtime: Starts whenever the object first enters a non-OK state between your start and end times, then runs for the duration you set. Use this when a reboot will happen somewhere inside a window.
- Recurring downtime: Define repeating windows for a Host, Service, hostgroup, or servicegroup at Home > Incident Management > Recurring Downtime for fixed monthly maintenance.
- Mass downtime: Schedule or clear downtime across a filtered set of Hosts and Services at Home > Incident Management > Mass Downtime.
- Comments as an audit trail: Pass the change ticket or playbook name in the downtime comment so the reason survives the window.
Documentation: How To Configure Downtime In Nagios XI | How To Add and Remove Mass Downtime In Nagios XI
NCPA Agent Deployment Across Ansible Inventory
Auto Deployment installs the Nagios Cross-Platform Agent (NCPA) on one or many systems from Configure > Auto Deployment, covering Linux, Windows, Mac OSX, and Solaris targets.
- Bulk targeting: Supply Hosts one per line or as comma-separated values, matching the way an inventory group is already grouped.
- Shared token: The NCPA Token set under Deployment Settings is applied to systems deployed from that point forward. Changing it does not alter the token on Hosts deployed earlier.
- Agent version choice: Deploy NCPA v3 for the most capable and supportable agent, or NCPA v2 (2.4.1) for operating systems v3 no longer covers.
- Windows requirement: Install and start the OpenSSH Server component on each Windows target. Windows commonly ships the OpenSSH Client only, which does not accept inbound connections.
- Credential requirement: Connect as root or as a user that can become root through sudo.
- Straight into a wizard: Select successful targets and click Run Wizard to open the NCPA Configuration Wizard with IP Address, Port, System, and Token already filled in.
- Manual installs included: Use Add Agent to bring Hosts where a playbook installed NCPA directly under the same management view.
Documentation: How To Use Auto Deployment In Nagios XI | NCPA v3 Agent Installation Instructions
Event Handlers and Automated Remediation
Event handlers are commands Nagios XI runs when a Host or Service changes state. They cover the first-level actions a team would otherwise perform by hand, including restarting a Service, parsing a log, making a database call, or launching a playbook.
- State-aware logic: Handlers fire on SOFT and HARD state types across OK, Warning, Critical, and Unknown, and receive macros such as
$SERVICESTATE$and$SERVICESTATETYPE$so the script decides what to do. - Targeted triggers: Write the script to act only on a HARD Critical state if you want a restart attempted once, after retries are exhausted.
- Global handlers: Define commands that run on every Host and Service state change or notification at Admin > System Extensions > Manage Components > Global Event Handlers, which suits ticket creation when remediation does not clear the problem.
- Downtime suppression: Enable Don’t Run in Downtime so handlers stay quiet during a scheduled window.
- Execution privileges: Global event handlers run as the nagios user on the Nagios XI server. Grant that account only the access the handler needs.
- Keep handlers fast: Run anything time-intensive as a background or daemon process so control returns to Nagios XI and other events keep processing.
Nagios XI restarting a Service and Ansible reconverging the Host solve different halves of the same problem, which is why Linux service and process monitoring is usually the first place teams wire the two together.
Documentation: Introduction To Event Handlers In Nagios XI | How To Configure Global Event Handlers In Nagios XI
Bulk Provisioning for Large Inventories
When a playbook builds many near-identical systems, the Bulk Host Cloning and Import Wizard reproduces an existing Host and its Services across a CSV list of new addresses.
- Template-driven: Pick one configured Host, select the Services to replicate, and paste the CSV of new Hosts.
- Minimum data: The Address field alone is enough; Name, hostgroup, and parent fields are optional additions.
- Matching targets: Cloned Hosts must be the same type as the template and must already run the same agent, so run agent deployment first.
- Wizard limits: Hosts created by the Network Switch/Router Wizard or the Web Transaction Wizard do not clone correctly, because those Services depend on MRTG and WebInject.
- Test before scale: Clone two or three Hosts and confirm the result before importing hundreds, since undoing a large import is difficult.
- Large imports: Raise
max_execution_time,max_input_time, andmemory_limitin/etc/php.inibefore importing very large CSV lists.
Documentation: Using The Bulk Host Cloning And Import Wizard In Nagios XI
Thresholds and Alerting After Automated Change
Thresholds are the mechanism behind every alert: a check returns a value, Nagios XI compares it to the Warning and Critical values you set, and the resulting state drives notifications and handlers.
- Set thresholds at creation: Pass threshold arguments in the same API call or template that creates the Service, so a playbook-provisioned Host arrives with usable alerting.
- Retry before alerting: Tune
max_check_attemptsandretry_intervalso a Service restarting mid-playbook does not page anyone. - Confirm the desired state holds: Check the specific setting a playbook enforces, such as a running Service, a listening port, or a file’s contents, and alert when it drifts from that value.
- Forecast growth: Capacity Planning projects performance data forward using Holt-Winters or polynomial fits and can alert a set number of days before a projected value is exceeded. This is an Enterprise Edition feature, with a 60-day trial available under Admin > System Config > License Information.
Documentation: How To Use Capacity Planning In Nagios XI
API Access Control and Credential Handling
An API key carries the rights of the user it belongs to, which makes account choice a security decision rather than a convenience one.
- Dedicated automation account: Create a Nagios XI user for automation rather than reusing a person’s login, so the key can be revoked without disrupting anyone.
- Admin rights where required: The Config and System sections need an admin account. Reporting-only playbooks can use a non-admin key against the Objects section.
- Keys stay out of playbooks: Store the key in Ansible Vault or your secrets manager and reference it as a variable such as
<API_TOKEN>. - Encrypted transport: Send API calls over HTTPS, since the key travels in the request.
- Deployment credentials: Auto Deployment stores the connection details it uses for each target. Treat that account as privileged and rotate it on the same schedule as your other administrative credentials.
Benefits of Nagios XI Ansible Monitoring
Monitoring coverage matches reality. When object creation belongs to the same playbook that provisions the Host, the gap between “the server exists” and “the server is monitored” closes to a single run. Nothing sits unwatched because a ticket was missed.
Maintenance windows stop generating noise. Downtime scheduled by automation starts at the right moment and covers exactly the objects the playbook touches, which keeps the alerts your team does receive worth reading.
Failed changes surface immediately. A playbook reports that a task succeeded. A check reports that the Service is answering. Running both means a change that applied cleanly but broke something downstream shows up as a Critical state rather than a user complaint.
Recurring incidents resolve without a page. An event handler that restarts a stuck Service at 3 a.m. turns a wake-up call into a log entry, and the alert still fires if the restart does not work.
One view across mixed tooling. Systems built by different pipelines land in the same Nagios XI console, so teams running Ansible alongside Chef monitoring or Kubernetes cluster monitoring do not need a separate dashboard per toolchain.
Fewer outages from configuration drift. Checks written against the settings a playbook enforces mean an out-of-band change is caught by monitoring, which supports the broader goal of reducing IT downtime.
Ansible Monitoring Prerequisites
- Network path to Nagios XI: The machine running the playbook needs HTTPS access to the Nagios XI web interface, since API calls travel over the same channel.
- Nagios XI API key: Available on the Account Information page for the user, or under Help > API Docs > Introduction.
- Admin-level account for object changes: Creating, modifying, or deleting Hosts and Services, applying configuration, and scheduling downtime all use admin-only endpoints.
- SSH from Nagios XI to targets: Auto Deployment connects outbound over SSH using a password and an account that is root or can sudo to root.
- OpenSSH Server on Windows targets: Install the server component, then confirm the Service is enabled and running.
- Inbound access to the NCPA listener: Allow the Nagios XI server to reach the NCPA listener port on each monitored Host through host and network firewalls.
- Shell access for file-based imports: Writing to
/usr/local/nagios/etc/import/and runningreconfigure_nagios.shrequire an account on the Nagios XI server itself. - Secret storage: Ansible Vault or an equivalent for the API key, NCPA token, and deployment credentials.
How To Monitor Ansible-Managed Infrastructure with Nagios XI
- Create an automation user and capture its API key. Give it admin rights if playbooks will create or delete objects, then store the key in Ansible Vault as
<API_TOKEN>. - Get an agent onto the targets. Deploy NCPA from Configure > Auto Deployment, or install it from a playbook and register those Hosts with Add Agent.
- Build one Host by hand and use it as the pattern. Run the NCPA Configuration Wizard against a single target, set thresholds, and confirm the Services report OK. This becomes your template for cloning or for the directives your API calls will send.
- Add an API task to your provisioning playbook. Post the Host and its Services to the config endpoints with
applyconfig=1, and add the matching delete tasks to your teardown playbook so retired systems stop alerting. - Wrap change windows in downtime. Schedule downtime through the System endpoints as the first task of a patching play and remove it as the last, passing the change reference in the comment.
- Connect state changes back to automation. Define an event handler command that calls your remediation script or playbook, then attach it to the Services where an automatic retry is safe.
Documentation: How To Access And Use The REST API In Nagios XI | How To Automate Host Management In Nagios XI | How To Use Auto Deployment In Nagios XI
Where Nagios XI Fits
Nagios XI handles Host and Service state: whether a system is Up, whether a Service answers, whether a metric sits inside the thresholds you defined. In an Ansible workflow that means object lifecycle through the API, downtime around change windows, agent rollout, and event handlers that call automation when a state changes. It does not execute playbooks itself, hold your inventory, or enforce desired state. Ansible owns that side; Nagios XI reports whether the result is working.
Capabilities in adjacent categories belong to other Nagios solutions. Collecting, searching, and retaining playbook output or system logs is the job of Nagios Log Server. Analyzing traffic flows across the network sits with Nagios Network Analyzer. Presenting several monitoring servers in one view is Nagios Fusion. Each is licensed separately.
Frequently Asked Questions
Does Ansible integration require a separate Nagios XI license?
No. The REST API, event handlers, downtime scheduling, and Auto Deployment are part of Nagios XI. Capacity Planning and the Bulk Modifications Tool are Enterprise Edition features, and a 30-day Enterprise trial can be enabled under Admin > System Config > License Information. For licensing questions, contact [email protected].
Can an Ansible playbook schedule Nagios XI downtime?
Yes. The System section of the REST API adds and removes scheduled downtime, so a playbook can call it before and after a maintenance task using the same API key it uses for object changes. Choose fixed downtime when the window has firm start and end times, and flexible downtime when you know the duration but not the exact moment a reboot will land.
Do Ansible-managed Hosts need an agent for Nagios XI to monitor them?
It depends on what you are checking. Service availability over the network, such as HTTP, SSH, or a database port, works without an agent. Operating system metrics such as CPU, memory, disk usage, and Service state need NCPA on the target. Auto Deployment installs NCPA on Linux, Windows, Mac OSX, and Solaris systems from the web interface, and a playbook can install it directly instead.
What permissions does the Nagios XI API key need?
An API key inherits the rights of the Nagios XI user it belongs to. Reading Host and Service status through the Objects section works with a standard user. Creating or deleting objects, applying configuration, and scheduling downtime require an admin account, because those endpoints are admin-only. Create a dedicated automation user so the key can be rotated or revoked on its own.
Can Nagios XI detect Ansible configuration drift?
Nagios XI compares a check result against thresholds you specify. It does not compare a Host’s running configuration against a desired state the way Ansible does. The practical approach is to write checks for the specific conditions your playbooks enforce, such as a Service running, a port listening, a package version, or the contents of a configuration file, so a change away from that value produces a Warning or Critical state and a notification.
Can Nagios XI monitor the Ansible control node or automation controller?
Yes, as a standard Host. Install NCPA on the control node and monitor CPU, memory, disk, and the state of the controller Services, and add an HTTP check against the web interface if it exposes one. There is no dedicated wizard for automation controllers, so build these checks with the NCPA Configuration Wizard and the Generic Plugin Wizard.
Can Nagios XI collect playbook output and Ansible logs?
Nagios XI checks state and thresholds rather than storing log volume. Centralizing playbook output alongside system logs, searching across it, and applying retention are handled by Nagios Log Server, which is licensed separately. A Nagios XI check can still alert on a specific pattern in a specific file on a monitored Host.
How do I stop alerts for Hosts a playbook has decommissioned?
Delete the objects at teardown time. Remove each Service first, then the Host, because a Host cannot be deleted while dependent relationships remain. Both the REST API config endpoints and the command-line deletion scripts on the Nagios XI server handle this, and adding the calls to your teardown playbook keeps retired systems from generating Down alerts.
Related Solutions
Automation and Orchestration
Systems Ansible Commonly Manages
- Linux Monitoring
- Red Hat Enterprise Linux (RHEL) Monitoring
- Windows Server Monitoring
- Server Monitoring
Operational Outcomes
Put Monitoring Inside Your Automation Pipeline
Start with one playbook. Add an API task that registers the Host it builds, and a downtime task around the next patch window. From there the pattern extends to agent rollout, teardown, and event handlers that call automation back. Nagios XI is available as a free trial, and a live demo walks through the API and Auto Deployment against a working instance.
Ready to Monitor with Nagios XI?
Get comprehensive infrastructure monitoring with our enterprise solution.
- On this page
- What Is Ansible Monitoring?
- Why Ansible Monitoring Matters
- Ansible Monitoring Capabilities in Nagios XI
- Benefits of Nagios XI Ansible Monitoring
- Ansible Monitoring Prerequisites
- How To Monitor Ansible-Managed Infrastructure with Nagios XI
- Where Nagios XI Fits
- Frequently Asked Questions
- Related Solutions
- Put Monitoring Inside Your Automation Pipeline