commit 16863fdf601967d4d6a2f675c912b17e0087150c Author: Antonio J. Delgado Date: Tue Oct 11 10:19:02 2022 +0300 Initial commit with previous code diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..e78d9ee --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,251 @@ +--- +### TODO: REMEMBER TO CONVERT TO DEFAULS ### +## Checks to-do: +## Check HTTPS services +## Check IMAP +## Check SMTP +## +nagios4_config: + admin_email: 'monitor-admin@example.org' + admin_pager: 'monitor-admin-pager@example.com' + log_file: "/var/log/nagios4/nagios.log" + object_cache_file: "/var/lib/nagios4/objects.cache" + precached_object_file: "/var/lib/nagios4/objects.precache" + resource_file: "/etc/nagios4/resource.cfg" + status_file: "/var/lib/nagios4/status.dat" + status_update_interval: 30 + nagios_user: 'nagios' + nagios_group: 'nagios' + check_external_commands: 1 + command_file: "/var/lib/nagios4/rw/nagios.cmd" + lock_file: "/var/lib/nagios4/nagios.lock" + temp_file: "/var/lib/nagios4/nagios.tmp" + temp_path: '/tmp' + event_broker_options: -1 + log_rotation_method: 'd' + log_archive_path: "/var/lib/nagios4/archive" + use_syslog: 1 + log_notifications: 1 + log_service_retries: 1 + log_host_retries: 1 + log_event_handlers: 1 + log_initial_states: 0 + log_current_states: 1 + log_external_commands: 1 + log_passive_checks: 1 + service_inter_check_delay_method: 's' + max_service_check_spread: 30 + service_interleave_factor: 's' + host_inter_check_delay_method: 's' + max_host_check_spread: 30 + max_concurrent_checks: 0 + check_result_reaper_frequency: 30 + max_check_result_reaper_time: 60 + check_result_path: "/var/lib/nagios4/spool/checkresults" + max_check_result_file_age: 3600 + cached_host_check_horizon: 15 + cached_service_check_horizon: 35 + enable_predictive_host_dependency_checks: 1 + enable_predictive_service_dependency_checks: 1 + soft_state_dependencies: 0 + auto_reschedule_checks: 0 + auto_rescheduling_interval: 90 + auto_rescheduling_window: 360 + service_check_timeout: 60 + host_check_timeout: 30 + event_handler_timeout: 30 + notification_timeout: 30 + ocsp_timeout: 5 + perfdata_timeout: 5 + retain_state_information: 1 + state_retention_file: "/var/lib/nagios4/retention.dat" + retention_update_interval: 60 + use_retained_program_state: 1 + use_retained_scheduling_info: 1 + retained_host_attribute_mask: 0 + retained_service_attribute_mask: 0 + retained_process_host_attribute_mask: 0 + retained_process_service_attribute_mask: 0 + retained_contact_host_attribute_mask: 0 + retained_contact_service_attribute_mask: 0 + interval_length: 60 + check_for_updates: 1 + bare_update_check: 0 + use_aggressive_host_checking: 0 + execute_service_checks: 1 + accept_passive_service_checks: 1 + execute_host_checks: 1 + accept_passive_host_checks: 1 + enable_notifications: 1 + enable_event_handlers: 1 + process_performance_data: 1 + #host_perfdata_file: '/usr/local/pnp4nagios/var/host-perfdata' + #service_perfdata_file: '/usr/local/pnp4nagios/var/service-perfdata' + #host_perfdata_file_template: 'DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$' + #service_perfdata_file_template: 'DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$' + #host_perfdata_file_mode: 'a' + #service_perfdata_file_mode: 'a' + #host_perfdata_file_processing_interval: 15 + #service_perfdata_file_processing_interval: 15 + #host_perfdata_file_processing_command: 'process-host-perfdata-file' + #service_perfdata_file_processing_command: 'process-service-perfdata-file' + obsess_over_services: 0 + obsess_over_hosts: 0 + translate_passive_host_checks: 0 + passive_host_checks_are_soft: 0 + check_for_orphaned_services: 1 + check_for_orphaned_hosts: 1 + check_service_freshness: 1 + service_freshness_check_interval: 60 + service_check_timeout_state: 'c' + check_host_freshness: 0 + host_freshness_check_interval: 60 + additional_freshness_latency: 15 + enable_flap_detection: 1 + low_service_flap_threshold: 5.0 + high_service_flap_threshold: 20.0 + low_host_flap_threshold: 5.0 + high_host_flap_threshold: 20.0 + date_format: 'u' + illegal_object_name_chars: "`~!$%^&*|'\"<>?,(): '" + illegal_macro_output_chars: "`~$&|'\"<>" + use_regexp_matching: 0 + use_true_regexp_matching: 0 + daemon_dumps_core: 0 + use_large_installation_tweaks: 0 + enable_environment_macros: 1 + debug_level: 0 + debug_verbosity: 1 + debug_file: "/var/log/nagios4/nagios.debug" + max_debug_file_size: 1000000 + allow_empty_hostgroup_assignment: 0 +cgi_config: + main_config_file: /etc/nagios4/nagios.cfg + physical_html_path: /usr/share/nagios4/htdocs + url_html_path: /nagios4 + show_context_help: 0 + use_pending_states: 1 + use_authentication: 0 + use_ssl_authentication: 0 + authorized_for_system_information: nagiosadmin + authorized_for_configuration_information: nagiosadmin + authorized_for_system_commands: nagiosadmin + authorized_for_all_services: nagiosadmin + authorized_for_all_hosts: nagiosadmin + authorized_for_all_service_commands: nagiosadmin + authorized_for_all_host_commands: nagiosadmin + default_statuswrl_layout: 4 + ping_syntax: /bin/ping -n -U -c 5 $HOSTADDRESS$ + refresh_rate: 90 + result_limit: 100 + escape_html_tags: 1 + action_url_target: _blank + notes_url_target: _blank + lock_author_names: 1 + navbar_search_for_addresses: 1 + navbar_search_for_aliases: 1 + +nagios_user: nagios +nagios_group: nagios +monitored_hosts: + - host_name: localhost + use: linux-server + alias: Server-1 + address: 127.0.0.1 + services: + - use: local-service + description: PING + check_command: check_ping!100.0,20%!500.0,60% + - host_name: server1 + use: linux-server + alias: Server-1 + address: server1.example.org + services: + - use: local-service + description: PING + check_command: check_ping!100.0,20%!500.0,60% +hostgroups: + - hostgroup_name: linux servers + alias: Linux Servers + members: + - localhost + - server1 + services: + - service_description: 'PING' + check_command: "check_ping!200.0,20%!500.0,60%" + - hostgroup_name: external servers + alias: External Servers + services: + - service_description: 'PING' + check_command: "check_ping!200.0,20%!500.0,60%" + - hostgroup_name: imap servers + alias: IMAP servers + services: + - service_description: 'PING' + check_command: "check_ping!200.0,20%!500.0,60%" + - hostgroup_name: mail transport agents + alias: Mail Transport Agents + services: + - service_description: 'PING' + check_command: "check_ping!200.0,20%!500.0,60%" + - hostgroup_name: appliances + alias: Appliances + services: + - service_description: 'PING' + check_command: "check_ping!200.0,20%!500.0,60%" + - hostgroup_name: web servers + alias: Web servers + services: + - service_description: 'PING' + check_command: "check_ping!200.0,20%!500.0,60%" +commands: [] +contacts: [] +templates: [] +timeperiods: [] + +vhosts: + - vhostname: nagios4.example.org + web_port: 80 + ssl_port: 443 + ssl: yes + #docroot: /var/www/host.example.org + serveradmin: webmaster@example.org + #server_aliases: [] + #root_options: + # - '-Indexes' + # - '-FollowSymLinks' + aliases: + - dest: nagios4 + src: /usr/share/nagios4/htdocs + # directories: + # - path: /var/www/host.example.org/custom_dir + # options: + # - '-Indexes' + # - '-FollowSymLinks' + # allow_override: None + # require: 'all granted' + # custom_code: "" + custom_code: " + Options FollowSymLinks + DirectoryIndex index.php index.html + AllowOverride AuthConfig + #Require ip ::1/128 fc00::/7 fe80::/10 10.0.0.0/8 127.0.0.0/8 169.254.0.0/16 172.16.0.0/12 192.168.0.0/16 + + AuthDigestDomain \"Nagios4\" + AuthDigestProvider file + AuthUserFile \"/etc/nagios4/htdigest.users\" + AuthGroupFile \"/etc/group\" + AuthName \"Nagios4\" + AuthType Digest + Require all granted + #Require valid-user + + + + + Options +ExecCGI +" + # ldap: + # url: ldap://ldap.example.org/ou=People,ou=Users,dc=example,dc=org?uid + # require: valid-user + #reverse_proxy: http://127.0.0.1:8080/ diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..dd1150b --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,10 @@ +--- +- name: Restart Nagios4 + systemd: + name: nagios4 + state: restarted + +- name: Restart Apache2 + systemd: + name: apache2 + state: restarted diff --git a/tasks/configure.yml b/tasks/configure.yml new file mode 100644 index 0000000..87ceb17 --- /dev/null +++ b/tasks/configure.yml @@ -0,0 +1,137 @@ +--- +# - name: Ensure Nagios is configured +# template: +# dest: /etc/nagios4/nagios.cfg +# src: templates/nagios.cfg.j2 +# owner: "{{ nagios_user }}" +# group: "{{ nagios_group }}" +# mode: 0660 +# backup: yes +# notify: Restart Nagios4 + +- name: Ensure folder for Nagios configurations exists + file: + path: /etc/nagios4/conf.d + state: directory + owner: "{{ nagios_user }}" + group: "{{ nagios_group }}" + +- name: Ensure nagios is configured + lineinfile: + path: /etc/nagios4/nagios.cfg + line: "{{ item.key }}={{ item.value }}" + regexp: "^{{ item.key }}=" + backup: yes + create: yes + #validate: '/usr/sbin/nagios4 --verify-config %s' + loop: "{{ lookup('dict', nagios4_config) }}" + notify: Restart Nagios4 + +- name: Ensure nagios CGI is configured + lineinfile: + path: /etc/nagios4/cgi.cfg + line: "{{ item.key }}={{ item.value }}" + regexp: "^{{ item.key }}=" + backup: yes + create: yes + #validate: '/usr/sbin/nagios4 --verify-config %s' + loop: "{{ lookup('dict', cgi_config) }}" + notify: Restart Nagios4 + +- name: Ensure commands are configured + template: + dest: /etc/nagios4/objects/commands.cfg + src: templates/commands.cfg.j2 + owner: "{{ nagios_user }}" + group: "{{ nagios_group }}" + mode: 0660 + backup: yes + #validate: '/usr/sbin/nagios4 --verify-config /etc/nagios4/nagios.cfg #%s' + notify: Restart Nagios4 + +- name: Ensure sudo commands are added + community.general.sudoers: + name: "allow_sudo_{{ item.command_name }}" + state: present + user: nagios + commands: "{{ item.command_line.split(' ')[1] | replace('$USER1$', '/usr/lib/nagios/plugins') }}" + nopassword: true + loop: "{{ commands }}" + when: "'sudo ' in item.command_line" + +- name: Ensure hostgroups are configured + template: + dest: /etc/nagios4/conf.d/hostgroups.cfg + src: templates/hostgroups.cfg.j2 + owner: "{{ nagios_user }}" + group: "{{ nagios_group }}" + mode: 0660 + backup: yes + #validate: '/usr/sbin/nagios4 --verify-config /etc/nagios4/nagios.cfg #%s' + notify: Restart Nagios4 + +- name: Ensure contacts and contactgroups are configured + template: + dest: /etc/nagios4/objects/contacts.cfg + src: templates/contacts.cfg.j2 + owner: "{{ nagios_user }}" + group: "{{ nagios_group }}" + mode: 0660 + backup: yes + #validate: '/usr/sbin/nagios4 --verify-config /etc/nagios4/nagios.cfg #%s' + notify: Restart Nagios4 + +- name: Ensure hosts are configured + template: + dest: "/etc/nagios4/conf.d/{{ item.host_name }}.cfg" + src: templates/host_template.j2 + owner: "{{ nagios_user }}" + group: "{{ nagios_group }}" + mode: 0660 + backup: yes + #validate: '/usr/sbin/nagios4 --verify-config /etc/nagios4/nagios.cfg #%s' + notify: Restart Nagios4 + with_items: "{{ monitored_hosts }}" + +- name: Ensure templates are configured + template: + dest: "/etc/nagios4/objects/templates.cfg" + src: templates/templates_template.j2 + owner: "{{ nagios_user }}" + group: "{{ nagios_group }}" + mode: 0660 + backup: yes + #validate: '/usr/sbin/nagios4 --verify-config /etc/nagios4/nagios.cfg #%s' + notify: Restart Nagios4 + +- name: Ensure timeperiods are configured + template: + dest: "/etc/nagios4/objects/timeperiods.cfg" + src: templates/timeperiods.cfg.j2 + owner: "{{ nagios_user }}" + group: "{{ nagios_group }}" + mode: 0660 + backup: yes + #validate: '/usr/sbin/nagios4 --verify-config /etc/nagios4/nagios.cfg #%s' + notify: Restart Nagios4 + +- name: Ensure nagios is not loading the locahost.cfg file + lineinfile: + path: /etc/nagios4/nagios.cfg + line: "#cfg_file=/etc/nagios4/objects/localhost.cfg" + regexp: "^cfg_file=/etc/nagios4/objects/localhost.cfg$" + backup: yes + create: yes + #validate: '/usr/sbin/nagios4 --verify-config %s' + notify: Restart Nagios4 + +- name: Ensure locahost.cfg file is absent + file: + path: /etc/nagios4/objects/localhost.cfg + state: absent + +- name: Ensure Nagios service is enabled and started + systemd: + name: nagios4 + enabled: yes + state: started \ No newline at end of file diff --git a/tasks/configure_apache.yml b/tasks/configure_apache.yml new file mode 100644 index 0000000..0a2d777 --- /dev/null +++ b/tasks/configure_apache.yml @@ -0,0 +1,23 @@ +--- +- name: Ensure configuration file is available to Apache + template: + dest: "/etc/apache2/sites-available/25-{{ vhost_name }}.conf" + src: templates/apache_vhost.j2 + mode: 0644 + backup: yes + +- name: Create auth user file + htpasswd: + path: "{{ auth_user_file }}" + name: "{{ nagios_admin_user }}" + password: "{{ nagios_admin_password }}" + owner: root + group: www-data + mode: 0640 + +- name: Ensure vhost is enabled + file: + state: link + src: "/etc/apache2/sites-available/25-{{ vhost_name }}.conf" + path: "/etc/apache2/sites-enabled/25-{{ vhost_name }}.conf" + notify: Restart Apache2 \ No newline at end of file diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..5019e44 --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,18 @@ +--- +- name: Ensure software is installed + package: + name: + - apache2 + - apache2-utils + - libapache2-mod-php + - php-gd + #- libgdchart-gd2-xpm-dev + - snmp + - smbclient + - fping + - iputils-ping + - gettext + - daemon + - nagios4 + - nagios-nrpe-plugin + - rrdtool \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..84d5e85 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,9 @@ +--- +- name: Ensure Nagios is installed + include_tasks: install.yml + +- name: Ensure Nagios is configured + include_tasks: configure.yml + +- name: Ensure Apache is configured for Nagios + include_tasks: configure_apache.yml \ No newline at end of file diff --git a/templates/apache_vhost.j2 b/templates/apache_vhost.j2 new file mode 100644 index 0000000..2fff918 --- /dev/null +++ b/templates/apache_vhost.j2 @@ -0,0 +1,125 @@ + + ServerName {{ vhost_name }} + ServerAdmin {{ webadmin }} + ServerAlias {{ vhost_aliases }} + + ## Logging + ErrorLog "/var/log/apache2/{{ vhost_name }}_error_ssl.log" + ServerSignature Off + CustomLog "/var/log/apache2/{{ vhost_name }}_access_ssl.log" combined + ErrorDocument 404 https://susurrando.com/notfound.php + ErrorDocument 500 https://susurrando.com/error500.php + ErrorDocument 503 https://susurrando.com/error503.php + + + ScriptAlias /cgi-bin/nagios4 /usr/lib/cgi-bin/nagios4 + ScriptAlias /nagios4/cgi-bin /usr/lib/cgi-bin/nagios4 + + # Where the stylesheets (config files) reside + Alias /nagios4/stylesheets /etc/nagios4/stylesheets + + # Where the HTML pages live + Alias /nagios4 /usr/share/nagios4/htdocs + + + Options +FollowSymLinks + DirectoryIndex index.php index.html + AllowOverride None + = 2.3> + + Require all granted + AuthName "Nagios Access" + AuthType Basic + AuthUserFile {{ auth_user_file }} + Require valid-user + + + + Order allow,deny + Allow from all + AuthName "Nagios Access" + AuthType Basic + AuthUserFile {{ auth_user_file }} + Require valid-user + + + + + Options +ExecCGI + + + # PNP4Nagios + Alias /pnp4nagios "/usr/local/pnp4nagios/share" + + + AllowOverride None + Order allow,deny + Allow from all + # + # Use the same value as defined in nagios.conf + # + AuthName "Nagios Access" + AuthType Basic + AuthUserFile {{ auth_user_file }} + Require valid-user + + # Turn on URL rewriting + RewriteEngine On + Options +symLinksIfOwnerMatch + # Installation directory + RewriteBase /pnp4nagios/ + # Protect application and system files from being viewed + RewriteRule "^(?:application|modules|system)/" - [F] + # Allow any files or directories that exist to be displayed directly + RewriteCond "%{REQUEST_FILENAME}" !-f + RewriteCond "%{REQUEST_FILENAME}" !-d + # Rewrite all other URLs to index.php/URL + RewriteRule "^.*$" "index.php/$0" [PT] + + + + # HighCharts + Alias /highcharts "/usr/local/highcharts" + + Options None + AllowOverride None + Order allow,deny + Allow from all + ## Only for apache 2.4 ## + # Require all granted + + + + + + ServerName {{ vhost_name }} + ServerAdmin {{ webadmin }} + + ## Logging + ErrorLog "/var/log/apache2/{{ vhost_name }}_ssl_error_ssl.log" + ServerSignature Off + CustomLog "/var/log/apache2/{{ vhost_name }}_ssl_access_ssl.log" combined + ErrorDocument 404 https://susurrando.com/notfound.php + ErrorDocument 500 https://susurrando.com/error500.php + ErrorDocument 503 https://susurrando.com/error503.php + ## Rewrite rules + RewriteEngine On + + + ## SSL directives + SSLEngine on + SSLCertificateFile "/etc/letsencrypt/live/{{ vhost_name }}/fullchain.pem" + SSLCertificateKeyFile "/etc/letsencrypt/live/{{ vhost_name }}/privkey.pem" + SSLProtocol all -SSLv3 -SSLv2 -TLSv1 -TLSv1.1 + SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA + + ## Custom fragment + + SSLHonorCipherOrder on + Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains" + SSLProxyEngine On + SSLProxyCheckPeerCN on + SSLProxyCheckPeerExpire on + ProxyPass / http://{{ vhost_name }}/ + ProxyPassReverse / http://{{ vhost_name }}/ + \ No newline at end of file diff --git a/templates/commands.cfg.j2 b/templates/commands.cfg.j2 new file mode 100644 index 0000000..a549c6d --- /dev/null +++ b/templates/commands.cfg.j2 @@ -0,0 +1,10 @@ +# File managed by Ansible + +# COMMANDS DEFINITIONS +{% if commands %}{% for command in commands %} +define command{ +{% for key, value in command.items() %} + {{ key }} {{ value }} +{% endfor %} + } +{% endfor %}{% endif %} diff --git a/templates/contacts.cfg.j2 b/templates/contacts.cfg.j2 new file mode 100644 index 0000000..012398a --- /dev/null +++ b/templates/contacts.cfg.j2 @@ -0,0 +1,25 @@ +# File managed by Ansible + +# CONTACTS DEFINITIONS +{% if contacts %}{% for contact in contacts %} +define contact{ +{% for key, value in contact.items() %} + {{ key }} {{ value }} +{% endfor %} + } +{% endfor %}{% endif %} + + +# CONTACTGROUPS DEFINITIONS +{% if contactgroups %}{% for contactgroup in contactgroups %} +define contactgroup{ +{% for key, value in contactgroup.items() %} +{% if key != "members" %} + {{ key }} {{ value }} +{% endif %} +{% if 'members' in contactgroup %} + members {{ contactgroup.members | join(',') }} +{% endif %} +{% endfor %} + } +{% endfor %}{% endif %} diff --git a/templates/host_template.j2 b/templates/host_template.j2 new file mode 100644 index 0000000..3b27d9c --- /dev/null +++ b/templates/host_template.j2 @@ -0,0 +1,23 @@ +# File managed by Ansible + +# HOST DEFINITION +define host{ +{% for key, value in item.items() %} +{% if key != "services" %} + {{ key }} {{ value }} +{% endif %} +{% endfor %} +} + +{% if 'services' in item %} +# SERVICES DEFINITION +{% for service in item.services %} + +define service{ + host {{ item.host_name }} +{% for key, value in service.items() %} + {{ key }} {% if key == "service_description" %}{{ value | replace(" ", "_") }}{% else %}{{ value }}{% endif %} + +{% endfor %} +} +{% endfor %}{% endif %} diff --git a/templates/hostgroups.cfg.j2 b/templates/hostgroups.cfg.j2 new file mode 100644 index 0000000..7e56085 --- /dev/null +++ b/templates/hostgroups.cfg.j2 @@ -0,0 +1,34 @@ +# File managed by Ansible + +# HOSTGROUPS DEFINITIONS +{% if hostgroups %}{% for group in hostgroups %} +# Group {{ group.hostgroup_name }} +define hostgroup{ +{% for key, value in group.items() %} +{% if key != "members" and key != "services" %} + {{ key }} {{ value }} +{% endif %} +{% endfor %} +{% if 'members' in group %} + members {{ group.members | join(',') }} +{% endif %} + } +{% if group.services is defined %}{% for service in group.services %} +# Service {{ service.service_description }} +define service{ + use {{ service.service_template |default('local-service') }} + hostgroup_name {{ group.hostgroup_name }} + service_description {{ service.service_description | replace(" ", "_") }} + check_command {{ service.check_command }} + notifications_enabled {{ service.notifications_enabled |default(1) }} + {% if service.action_url is defined %} + action_url {{ service.action_url }} + {% endif %} + {% if service.notes_url is defined %} + notes_url {{ service.notes_url }} + {% endif %} + +} +{% endfor %}{% endif %} +{% endfor %}{% endif %} + diff --git a/templates/nagios.cfg.j2 b/templates/nagios.cfg.j2 new file mode 100644 index 0000000..18b1dbc --- /dev/null +++ b/templates/nagios.cfg.j2 @@ -0,0 +1,3 @@ +{% if nagios4_config %}{% for key, value in nagios4_config.items() %} +{{ key }}={{ value }} +{% endfor %}{% endif %} \ No newline at end of file diff --git a/templates/templates_template.j2 b/templates/templates_template.j2 new file mode 100644 index 0000000..b0a593c --- /dev/null +++ b/templates/templates_template.j2 @@ -0,0 +1,72 @@ +############################################################################### +# MANAGED BY ANSIBLE!! +# TEMPLATES.CFG - SAMPLE OBJECT TEMPLATES +# +# +# NOTES: This config file provides you with some example object definition +# templates that are refered by other host, service, contact, etc. +# definitions in other config files. +# +# You don't need to keep these definitions in a separate file from your +# other object definitions. This has been done just to make things +# easier to understand. +# +############################################################################### + + +{% if templates.contacts is defined %} +############################################################################### +############################################################################### +# +# CONTACT TEMPLATES +# +############################################################################### +############################################################################### + +# Generic contact definition template - This is NOT a real contact, just a template! +{% for contact in templates.contacts %} +define contact{ +{% for key, value in contact.items() %} + {{ key }} {{ value }} +{% endfor %} +} +{% endfor %} +{% endif %} + +{% if templates.hosts is defined %} +############################################################################### +############################################################################### +# +# HOSTS TEMPLATES +# +############################################################################### +############################################################################### + +# Generic host definition template - This is NOT a real host, just a template! +{% for host in templates.hosts %} +define host{ +{% for key, value in host.items() %} + {{ key }} {{ value }} +{% endfor %} +} +{% endfor %} +{% endif %} + +{% if templates.contacts is defined %} +############################################################################### +############################################################################### +# +# SERVICE TEMPLATES +# +############################################################################### +############################################################################### + +# Generic service definition template - This is NOT a real service, just a template! +{% for service in templates.services %} +define service{ +{% for key, value in service.items() %} + {{ key }} {{ value }} +{% endfor %} +} +{% endfor %} +{% endif %} diff --git a/templates/timeperiods.cfg.j2 b/templates/timeperiods.cfg.j2 new file mode 100644 index 0000000..283bbef --- /dev/null +++ b/templates/timeperiods.cfg.j2 @@ -0,0 +1,32 @@ +############################################################################### +# ATTENTION!!! FILE MANAGED BY ANSIBLE ROLE NAGIOS +# TIMEPERIODS.CFG - SAMPLE TIMEPERIOD DEFINITIONS +# +# +# NOTES: This config file provides you with some example timeperiod definitions +# that you can reference in host, service, contact, and dependency +# definitions. +# +# You don't need to keep timeperiods in a separate file from your other +# object definitions. This has been done just to make things easier to +# understand. +# +############################################################################### + + + +############################################################################### +############################################################################### +# +# TIME PERIODS +# +############################################################################### +############################################################################### +{% if timeperiods is defined %}{% for period in timeperiods %} +define timeperiod{ +{% for key, value in period.items() %} + {{ key }} {{ value }} +{% endfor %} + } +{% endfor %}{% endif %} +