Centreon CLAPI Backup

This role backs up Centreon monitoring configuration using CLAPI (Command Line API) to dual NAS storage for disaster recovery.

ARA Ansible Bash Centreon NAS Proxmox SNMP Synology

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 (centreon command)
  • Admin credentials for Centreon stored in Ansible Vault
  • NAS mount points must be accessible and writable
  • Target host must have the centreon CLI tool in PATH

Role Variables

Required Variables

VariableRequiredDescription
vault_centreon_admin_passwordYesCentreon admin password (stored in Ansible Vault)

Optional Variables

VariableDefaultDescription
centreon_clapi_backup_syno_mount_point/media/nas_win_share/centreon/clapiMount point for Synology NAS backup destination
centreon_clapi_backup_prxmxomv_mount_point/media/nas_win_share_omv/centreon/clapiMount point for Proxmox OMV NAS backup destination
centreon_clapi_backup_nases_pathSee defaults/main.ymlList 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_mount or nas_mount_systemd roles)
  • 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

  1. Ensures backup directories exist on both NAS mount points
  2. Executes CLAPI export using centreon -u admin -p <password> -e
  3. Saves export to both NAS devices with timestamp in filename
  4. Finds all existing backups on each NAS
  5. 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.txt
  • centreon_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: true to 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: false to 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.