Centreon CLAPI Backup
This role backs up Centreon monitoring configuration using CLAPI (Command Line API) to dual NAS storage for disaster recovery.
Centreon CLAPI Backup Role
Overview
This role backs up Centreon monitoring configuration using CLAPI (Command Line API) to dual NAS storage for disaster recovery. It exports all Centreon objects (hosts, services, templates, commands, etc.) and automatically manages retention by keeping only the last 5 backups per NAS.
Purpose
- Disaster Recovery: Protects your monitoring configuration against data loss
- Configuration Management: Creates exportable snapshots of all Centreon objects
- Version History: Maintains 5 timestamped backups for rollback capability
- Dual Redundancy: Backs up to two separate NAS devices (Synology DS418 and Proxmox OMV)
- Automated Cleanup: Automatically removes old backups to manage storage space
Requirements
- Ansible 2.9 or higher
- Centreon installed with CLAPI available (
centreoncommand) - Admin credentials for Centreon stored in Ansible Vault
- NAS mount points must be accessible and writable
- Target host must have the
centreonCLI tool in PATH
Role Variables
Required Variables
| Variable | Required | Description |
|---|---|---|
vault_centreon_admin_password | Yes | Centreon admin password (stored in Ansible Vault) |
Optional Variables
| Variable | Default | Description |
|---|---|---|
centreon_clapi_backup_syno_mount_point | /media/nas_win_share/centreon/clapi | Mount point for Synology NAS backup destination |
centreon_clapi_backup_prxmxomv_mount_point | /media/nas_win_share_omv/centreon/clapi | Mount point for Proxmox OMV NAS backup destination |
centreon_clapi_backup_nases_path | See defaults/main.yml | List of destination paths with timestamps |
Variable Details
vault_centreon_admin_password
The password for the Centreon admin user. This must be stored in an Ansible Vault file.
Example vault variable:
vault_centreon_admin_password: "YourSecurePassword123"
centreon_clapi_backup_nases_path
Automatically generates timestamped filenames using ansible_facts['date_time'].iso8601_basic_short with ‘T’ replaced by ’_’ for readability (format: YYYYMMDD_HHMMSS).
Default behavior:
- Synology:
/media/nas_win_share/centreon/clapi/centreon_clapi_backup_20260107_143022.txt - Proxmox OMV:
/media/nas_win_share_omv/centreon/clapi/centreon_clapi_backup_20260107_143022.txt
Dependencies
This role has no dependencies on other Ansible roles, but requires:
- NAS mounts to be configured (see
nas_mountornas_mount_systemdroles) - Write permissions to the NAS mount points
- Centreon server with CLAPI functionality
Example Playbook
Basic Usage
---
- name: Backup Centreon Configuration
hosts: centreon
become: true
roles:
- centreon_clapi_backup
Custom Backup Locations
---
- name: Backup Centreon CLAPI to Custom Locations
hosts: centreon
become: true
vars:
centreon_clapi_backup_syno_mount_point: /mnt/backup1/centreon
centreon_clapi_backup_prxmxomv_mount_point: /mnt/backup2/centreon
roles:
- centreon_clapi_backup
Scheduled Backup with Cron
---
- name: Schedule Daily Centreon Backup
hosts: centreon
become: true
tasks:
- name: Create cron job for daily Centreon backup
ansible.builtin.cron:
name: "Daily Centreon CLAPI Backup"
minute: "0"
hour: "2"
job: "ansible-playbook /path/to/centreon_backup.yml"
What This Role Does
- Ensures backup directories exist on both NAS mount points
- Executes CLAPI export using
centreon -u admin -p <password> -e - Saves export to both NAS devices with timestamp in filename
- Finds all existing backups on each NAS
- Removes old backups, keeping only the 5 most recent per NAS
CLAPI Export Content
The CLAPI export includes all Centreon configuration objects:
- Hosts and host templates
- Services and service templates
- Commands (check, notification, discovery)
- Time periods
- Contacts and contact groups
- Host groups and service groups
- Host categories and service categories
- SNMP traps
- Escalations
- Dependencies
- ACLs and access groups
- Pollers and broker configurations
The export does NOT include:
- RRD data (performance metrics)
- Event logs
- Acknowledgements
- Downtimes
Backup Retention
The role implements automatic retention management:
- Keeps: Last 5 backups per NAS
- Deletes: Backups older than the 5th most recent
- Per-NAS logic: Each NAS independently maintains 5 backups
This ensures you have:
- 5 backups on Synology DS418
- 5 backups on Proxmox OMV
- Total: Up to 10 backup copies across both devices
File Naming Convention
Backup files are named using ISO 8601-derived format with underscore separator:
centreon_clapi_backup_YYYYMMDD_HHMMSS.txt
Examples:
centreon_clapi_backup_20260107_143022.txtcentreon_clapi_backup_20260107_190530.txt
This naming scheme:
- Sorts chronologically by default
- Uses underscore instead of ‘T’ for better readability
- Is timezone-agnostic
- Prevents filename conflicts
- Makes it easy to identify backup age
Restoration
To restore from a CLAPI backup, use the companion centreon_clapi_restore role or manually:
# On the Centreon server
centreon -u admin -p 'YourPassword' -i /path/to/centreon_clapi_backup_20260107_143022.txt
Note: Restoration will import all objects from the backup. Existing objects with the same names will be updated.
Security Considerations
- Password Protection: Admin password is marked with
no_log: trueto prevent logging - Vault Storage: Admin password must be stored in Ansible Vault
- File Permissions: Backup files are created with default umask (typically 0644)
- Sensitive Data: CLAPI exports contain configuration but not credentials (passwords are hashed)
Tags
This role does not define any tags. Use playbook-level tags if needed:
- hosts: centreon
roles:
- centreon_clapi_backup
tags:
- backup
- centreon
- monitoring
Notes
- The role uses
failed_when: falseto handle CLAPI errors gracefully - Export is marked as changed only when the command succeeds (rc == 0)
- CLAPI export is a text-based format that’s easy to version control
- Cleanup operation uses safe file handling with loop control labels
Troubleshooting
”centreon: command not found”
Ensure Centreon CLAPI is installed and the centreon binary is in the system PATH. Typically located at /usr/share/centreon/bin/centreon.
”Authentication failed” errors
Verify the vault_centreon_admin_password variable is correctly set and decrypted. Test manually:
centreon -u admin -p 'password' -e
“Permission denied” when writing to NAS
Ensure the user running Ansible has write permissions to both NAS mount points.
Empty backup files
Check Centreon logs for CLAPI errors. The export may fail silently if there are database connectivity issues.
License
MIT
Author
Created for homelab infrastructure management.