sdarwin.nagios

Ansible Role: Nagios

This role sets up Nagios and NRPE (both client and server) and configures Nagios using Ansible’s inventory of hosts. The aim is to create a complete Nagios monitoring system with minimal manual setup.

Prerequisites

Ensure that DNS or the /etc/hosts file can resolve names correctly. For example, you should be able to ping web3 using web3.example.com.
Having email set up is also recommended, with options like Exim or Postfix.

Role Variables

You can change any variables found in the defaults/ directory.

Contacts/Users:

To permit users to access the Nagios web interface, add them to the nagios_users variable:

nagios_users:  
  - user: nagiosadmin  
    pass: Password1change  
    email: [email protected]  

A better way to add Nagios contacts and admins is to use the users variable, which works in conjunction with https://github.com/mivok/ansible-users.

This playbook will search for users in the sysadmin group, and those will become Nagios admins.

You should create the users variable, ideally in group_vars/all. Here’s an example:

users:  
  - username: foo  
    name: Foo Barrington  
    groups: ['sysadmin']  
    uid: 1001  
    ssh_key:  
      - "ssh-rsa AAAAA.... foo@machine"  
      - "ssh-rsa AAAAB.... foo2@machine"  
    htpasswd: $apr1$SheSL4Et$xry6RljdWWvUVrh42s7OA0  
    nagios:  
      pager: "[email protected]"  
      email: "[email protected]"  

To generate the htpasswd value, use this command:

htpasswd -n mario  
mario:$apr1$SheSL4Et$xry6RljdWWvUVrh42s7OA0  

You must have at least one user in the sysadmin group for Nagios contacts to function.

Nagios Commands:

The Nagios commands are listed in the nagios_commands variable, found in defaults/main.yml. You can add or change commands as needed.

Nagios Services:

Nagios services are defined in the "checks" section for each host group in nagios_host_groups, which can be found in defaults/main.yml. You can add or change services here too. Service checks for each host are similarly managed in the nagios_hosts variable.

Nagios Hosts:

All Ansible hosts in the 'all' group will be monitored by Nagios automatically. No extra setup is required.

Nagios Hostgroups:

Ansible groups will be turned into Nagios hostgroups without additional configuration.

Skipping Hosts and Hostgroups

You can set which hosts or groups to ignore in defaults/main.yml:

nagios_hosts_ignore: ""
nagios_groups_ignore: ""

You can replace these values with the names of hosts or hostgroups you want to skip. For example:

nagios_hosts_ignore:
  - host1_skip_this_host
nagios_groups_ignore:
  - hostgroup_dev_to_skip
  - and_this_one

This specifies which hosts Nagios will not monitor as they will be left out of the configurations.

You can also choose whether to run the playbook on all servers. The example playbook default.yml has "- hosts: all", installing the Nagios client on all available servers. You could change the "hosts: " directive in your main playbook if needed, but installing the monitoring client on all servers is usually fine.

Example Playbook

Look at default.yml in this role’s root.

To install the client:

roles:   
  - { role: 'sdarwin.nagios', run_nagios_client: true }  

To install the server:

roles:  
  - { role: 'sdarwin.nagios', run_nagios_server: true }   

Add Nagios servers to the monitoring-servers group in your Ansible inventory. Example:

[monitoring-servers]  
monitor.example.com  

The URL for Nagios will be formatted like this: http://monitor.example.com/nagios/

License

BSD

Author Information

By Sam Darwin, 2016. This work is based on existing roles, see the ACKNOWLEDGEMENTS.md file for details. Feedback and bug reports are welcomed.

Analytics

Informazioni sul progetto

Install Nagios 4.x on Ubuntu or CentOS

Installa
ansible-galaxy install sdarwin.nagios
Licenza
isc
Download
539
Proprietario