This is an ansible role to set up nagios on a network. The idea is to use ansible inventory and vars to "automatically" set up hosts and services in nagios.
The target network is 10-20 devices and 1-3 admins, not large scale enterprise.
-
this is a stand-alone role
Others part of ansible will have to handle firewalls, package management, users, logging and whatever else you want of a server.
Currently,
apache2is installed as part of the role. This might change. -
ansible groups becomes nagios hostgroups
Devices in a group will automatically be in a nagios group of the same name Groups named
allandungroupedare ignored by default. -
provisioning to nagios is independent of fact collection
All the info that nagios needs are in
group_varsandhost_vars, so it is sufficient to have the devices in inventory. -
notifications use email
Proper emailing must be set up on the system, e.g using
dpkg-reconfigure exim4-config -
notification is specified per contact
Default is to use email. A notify list containing X, Y and Z gets converted to
notify-host-by-X,notify-host-by-Yandnotify-host-by-Z, which must exist, probably defined incustom-objects. -
configurations are split into default, ansible and non-ansible.
The configuration is default in
/usr/local/nagios/etc. Main config file isnagios.cfg(ansible controlled) and the subdirectories contains other config. Path is specified usingnagios_base_dir.ansible-hostscontains the autogenerated config by ansible.custom-objectscontains whatever manual stuff the admin want also, like non-default commands and non-ansible hosts. -
role is usable
out-of-the-box, ie. no config is need to have an minimal setup.
See tests directory for details
We download nagios from github and the version specified in nagios_version must match that.
Nagios plugins are also downloaded from github and nagios_plugins_version must match a version there.
The role may be used without setting any host_vars or group_vars. See test-defaults/test.yml for an example
So a playbook like this is minimum
- hosts: all
roles:
- {role: server-nagios, become: true }
This assumes that the roles is pulled to the directory roles/server-nagios.
Notifications will be minimal, localhost will have some checks, and every other device in inventory will be a host with no service checks.
- In the example the nagiosserver is called
nagioshostand there is another host calledotherhost
- the two servers are in the
serversgroup and one in theotherserversgroup
[servers]
nagioshost
otherhostA
[otherservers]
otherhostB
- in the playbook we define how to provision
- hosts: nagioshost
roles:
- { role: server-nagios, become: true }
# provision other hosts if applicable
#- hosts: otherhost?
#
# roles:
# - {}
- one group called
serversand another calledotherservers
- define the users that will be referenced in notifications
- define contact info for the default nagiosadmin user
- Both users A and B will be notified by
email(since it is default), anduserAwill also be notified usingothermean. - User A is in the admin group and will receive notification for that group
nagios_contacts:
- name: userA
mail: userA@somewhere
notify:
- email
- othermean
- name: userB
mail: userB@somewhere
nagios_admin_group_contact: userA
- define who should be notified when something happens
- define the tests that are to be used for all groups. The text written will be used directly as check command. See the nagios documentation for details.
nagios_group_contacts:
- userA
- userB
nagios_group_tests:
ping: "check_ping!100.0,20%!500.0,60%"
ssh: check_ssh
- the group
otherserversare not to be included in nagios - hosts in the groups will, unless something else is defined in hostvars, be excluded from nagios.
nagios_exclude_group: True
nagios_exclude_host: True
- host specific tests are not implemented yet
userAis the owner and will be notified. Default owner isnagiosadmin.
nagios_host_owner: userA
nagios_admin_user: nagiosadmin
nagios_admin_pass: somepass
userBis the owner and will be notified.- Specific to
otherhostA, HTTP will also be checked. Other checks from the group are still included.
nagios_host_owner: userB
nagios_host_checks:
http: check_http