init.sls 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #
  2. # Icinga2
  3. #
  4. {% set roles = salt['pillar.get']('nodes:' ~ grains.id ~ ':roles', []) %}
  5. include:
  6. - apt
  7. # Install icinga2 package
  8. icinga2:
  9. pkg.installed:
  10. - name: icinga2
  11. service.running:
  12. - enable: True
  13. - reload: True
  14. # Install plugins (official + our own)
  15. monitoring-plugin-pkgs:
  16. pkg.installed:
  17. - pkgs:
  18. - monitoring-plugins
  19. - nagios-plugins-contrib
  20. - libyaml-syck-perl
  21. - libnagios-plugin-perl
  22. - lsof
  23. - watch_in:
  24. - service: icinga2
  25. ffho-plugins:
  26. file.recurse:
  27. - name: /usr/local/share/monitoring-plugins/
  28. - source: salt://icinga2/plugins/
  29. - file_mode: 755
  30. - dir_mode: 755
  31. - user: root
  32. - group: root
  33. # Icinga2 master config (for master and all nodes)
  34. /etc/icinga2/icinga2.conf:
  35. file.managed:
  36. - source:
  37. - salt://icinga2/icinga2.conf.H_{{ grains.id }}
  38. - salt://icinga2/icinga2.conf
  39. - require:
  40. - pkg: icinga2
  41. - watch_in:
  42. - service: icinga2
  43. # Add FFHOPluginDir
  44. /etc/icinga2/constants.conf:
  45. file.managed:
  46. - source: salt://icinga2/constants.conf
  47. - require:
  48. - pkg: icinga2
  49. - watch_in:
  50. - service: icinga2
  51. # Connect "master" and client zones
  52. /etc/icinga2/zones.conf:
  53. file.managed:
  54. - source:
  55. - salt://icinga2/zones.conf.H_{{ grains.id }}
  56. - salt://icinga2/zones.conf
  57. - require:
  58. - pkg: icinga2
  59. - watch_in:
  60. - service: icinga2
  61. # Install host cert + key readable for icinga
  62. {% set pillar_name = 'nodes:' ~ grains['id'] ~ ':certs:' ~ grains['id'] %}
  63. /etc/icinga2/pki/ffhohost.cert.pem:
  64. file.managed:
  65. {% if salt['pillar.get'](pillar_name ~ ':cert') == "file" %}
  66. - source: salt://certs/certs/{{ cn }}.cert.pem
  67. {% else %}
  68. - contents_pillar: {{ pillar_name }}:cert
  69. {% endif %}
  70. - user: root
  71. - group: root
  72. - mode: 644
  73. - require:
  74. - pkg: icinga2
  75. - watch_in:
  76. - service: icinga2
  77. /etc/icinga2/pki/ffhohost.key.pem:
  78. file.managed:
  79. - contents_pillar: {{ pillar_name }}:privkey
  80. - user: root
  81. - group: nagios
  82. - mode: 440
  83. - require:
  84. - pkg: icinga2
  85. - watch_in:
  86. - service: icinga2
  87. # Activate Icinga2 features: API
  88. {% for feature in ['api'] %}
  89. /etc/icinga2/features-enabled/{{ feature }}.conf:
  90. file.symlink:
  91. - target: "../features-available/{{ feature }}.conf"
  92. - require:
  93. - pkg: icinga2
  94. - watch_in:
  95. - service: icinga2
  96. {% endfor %}
  97. # Install command definitions
  98. /etc/icinga2/commands.d:
  99. file.recurse:
  100. - source: salt://icinga2/commands.d
  101. - file_mode: 644
  102. - dir_mode: 755
  103. - user: root
  104. - group: root
  105. - clean: true
  106. - require:
  107. - pkg: icinga2
  108. - watch_in:
  109. - service: icinga2
  110. ################################################################################
  111. # Icinga2 Server #
  112. ################################################################################
  113. {% if 'icinga2server' in roles %}
  114. # Create directory for ffho specific configs
  115. /etc/icinga2/ffho-conf.d:
  116. file.directory:
  117. - makedirs: true
  118. - require:
  119. - pkg: icinga2
  120. # Install command definitions
  121. /etc/icinga2/ffho-conf.d/services:
  122. file.recurse:
  123. - source: salt://icinga2/services
  124. - file_mode: 644
  125. - dir_mode: 755
  126. - user: root
  127. - group: root
  128. - clean: true
  129. - require:
  130. - pkg: icinga2
  131. - watch_in:
  132. - service: icinga2
  133. # Create client node/zone objects
  134. /etc/icinga2/ffho-conf.d/hosts/:
  135. file.directory:
  136. - makedirs: true
  137. - require:
  138. - pkg: icinga2
  139. # Generate config file for every client known to pillar
  140. {% for node_id, node_config in salt['pillar.get']('nodes', {}).items () %}
  141. {% if node_config.get ('icinga2', "") != 'ignore' %}
  142. /etc/icinga2/ffho-conf.d/hosts/{{ node_id }}.conf:
  143. file.managed:
  144. - source: salt://icinga2/host.conf.tmpl
  145. - template: jinja
  146. - context:
  147. node_id: {{ node_id }}
  148. node_config: {{ node_config }}
  149. - require:
  150. - file: /etc/icinga2/ffho-conf.d/hosts/
  151. - watch_in:
  152. - service: icinga2
  153. {% endif %}
  154. {% endfor %}
  155. ################################################################################
  156. # Icinga2 Client #
  157. ################################################################################
  158. {% else %}
  159. # Nodes should accept config and commands from Icinga2 server
  160. /etc/icinga2/features-available/api.conf:
  161. file.managed:
  162. - source: salt://icinga2/api.conf
  163. - require:
  164. - pkg: icinga2
  165. - watch_in:
  166. - service: icinga2
  167. /etc/icinga2/ffho-conf.d/:
  168. file.absent:
  169. - watch_in:
  170. - service: icinga2
  171. /etc/icinga2/check-commands.conf:
  172. file.absent:
  173. - watch_in:
  174. - service: icinga2
  175. {% endif %}