init.sls 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. #
  2. # Icinga2
  3. #
  4. {% set roles = salt['pillar.get']('nodes:' ~ grains.id ~ ':roles', []) %}
  5. include:
  6. - apt
  7. - sudo
  8. # Install icinga2 package
  9. icinga2:
  10. pkg.installed:
  11. - name: icinga2
  12. service.running:
  13. - enable: True
  14. - reload: True
  15. # Install plugins (official + our own)
  16. monitoring-plugin-pkgs:
  17. pkg.installed:
  18. - pkgs:
  19. - monitoring-plugins
  20. - nagios-plugins-contrib
  21. - libyaml-syck-perl
  22. {% if grains['oscodename'] == 'jessie' %}
  23. - libnagios-plugin-perl
  24. {% else %}
  25. - libmonitoring-plugin-perl
  26. {% endif %}
  27. - lsof
  28. - watch_in:
  29. - service: icinga2
  30. ffho-plugins:
  31. file.recurse:
  32. - name: /usr/local/share/monitoring-plugins/
  33. - source: salt://icinga2/plugins/
  34. - file_mode: 755
  35. - dir_mode: 755
  36. - user: root
  37. - group: root
  38. # Install sudoers file for Icinga2 checks
  39. /etc/sudoers.d/icinga2:
  40. file.managed:
  41. - source: salt://icinga2/icinga2.sudoers
  42. - mode: 0440
  43. # Icinga2 master config (for master and all nodes)
  44. /etc/icinga2/icinga2.conf:
  45. file.managed:
  46. - source:
  47. - salt://icinga2/icinga2.conf.H_{{ grains.id }}
  48. - salt://icinga2/icinga2.conf
  49. - require:
  50. - pkg: icinga2
  51. - watch_in:
  52. - service: icinga2
  53. # Add FFHOPluginDir
  54. /etc/icinga2/constants.conf:
  55. file.managed:
  56. - source: salt://icinga2/constants.conf
  57. - require:
  58. - pkg: icinga2
  59. - watch_in:
  60. - service: icinga2
  61. # Connect "master" and client zones
  62. /etc/icinga2/zones.conf:
  63. file.managed:
  64. - source:
  65. - salt://icinga2/zones.conf.H_{{ grains.id }}
  66. - salt://icinga2/zones.conf
  67. - template: jinja
  68. - require:
  69. - pkg: icinga2
  70. - watch_in:
  71. - service: icinga2
  72. # Install host cert + key readable for icinga
  73. {% set pillar_name = 'nodes:' ~ grains['id'] ~ ':certs:' ~ grains['id'] %}
  74. /etc/icinga2/pki/ffhohost.cert.pem:
  75. file.managed:
  76. {% if salt['pillar.get'](pillar_name ~ ':cert') == "file" %}
  77. - source: salt://certs/certs/{{ cn }}.cert.pem
  78. {% else %}
  79. - contents_pillar: {{ pillar_name }}:cert
  80. {% endif %}
  81. - user: root
  82. - group: root
  83. - mode: 644
  84. - require:
  85. - pkg: icinga2
  86. - watch_in:
  87. - service: icinga2
  88. /etc/icinga2/pki/ffhohost.key.pem:
  89. file.managed:
  90. - contents_pillar: {{ pillar_name }}:privkey
  91. - user: root
  92. - group: nagios
  93. - mode: 440
  94. - require:
  95. - pkg: icinga2
  96. - watch_in:
  97. - service: icinga2
  98. # Activate Icinga2 features: API
  99. {% for feature in ['api'] %}
  100. /etc/icinga2/features-enabled/{{ feature }}.conf:
  101. file.symlink:
  102. - target: "../features-available/{{ feature }}.conf"
  103. - require:
  104. - pkg: icinga2
  105. - watch_in:
  106. - service: icinga2
  107. {% endfor %}
  108. # Install command definitions
  109. /etc/icinga2/commands.d:
  110. file.recurse:
  111. - source: salt://icinga2/commands.d
  112. - template: jinja
  113. - file_mode: 644
  114. - dir_mode: 755
  115. - user: root
  116. - group: root
  117. - clean: true
  118. - require:
  119. - pkg: icinga2
  120. - watch_in:
  121. - service: icinga2
  122. # Create directory for ffho specific configs
  123. /etc/icinga2/ffho-conf.d:
  124. file.directory:
  125. - makedirs: true
  126. - require:
  127. - pkg: icinga2
  128. ################################################################################
  129. # Icinga2 Server #
  130. ################################################################################
  131. {% if 'icinga2server' in roles %}
  132. # Install command definitions
  133. /etc/icinga2/ffho-conf.d/services:
  134. file.recurse:
  135. - source: salt://icinga2/services
  136. - file_mode: 644
  137. - dir_mode: 755
  138. - user: root
  139. - group: root
  140. - clean: true
  141. - require:
  142. - pkg: icinga2
  143. - watch_in:
  144. - service: icinga2
  145. # Create client node/zone objects
  146. Create /etc/icinga2/ffho-conf.d/hosts/generated/:
  147. file.directory:
  148. - name: /etc/icinga2/ffho-conf.d/hosts/generated/
  149. - makedirs: true
  150. - require:
  151. - pkg: icinga2
  152. Cleanup /etc/icinga2/ffho-conf.d/hosts/generated/:
  153. file.directory:
  154. - name: /etc/icinga2/ffho-conf.d/hosts/generated/
  155. - clean: true
  156. - watch_in:
  157. - service: icinga2
  158. # Generate config file for every client known to pillar
  159. {% for node_id, node_config in salt['pillar.get']('nodes', {}).items () %}
  160. {% if node_config.get ('icinga2', "") != 'ignore' %}
  161. /etc/icinga2/ffho-conf.d/hosts/generated/{{ node_id }}.conf:
  162. file.managed:
  163. - source: salt://icinga2/host.conf.tmpl
  164. - template: jinja
  165. - context:
  166. node_id: {{ node_id }}
  167. node_config: {{ node_config }}
  168. - require:
  169. - file: Create /etc/icinga2/ffho-conf.d/hosts/generated/
  170. - require_in:
  171. - file: Cleanup /etc/icinga2/ffho-conf.d/hosts/generated/
  172. - watch_in:
  173. - service: icinga2
  174. {% endif %}
  175. {% endfor %}
  176. # Create configuration for network devices
  177. Create /etc/icinga2/ffho-conf.d/net/wbbl/:
  178. file.directory:
  179. - name: /etc/icinga2/ffho-conf.d/net/wbbl/
  180. - makedirs: true
  181. - require:
  182. - pkg: icinga2
  183. Cleanup /etc/icinga2/ffho-conf.d/net/wbbl/:
  184. file.directory:
  185. - name: /etc/icinga2/ffho-conf.d/net/wbbl/
  186. - makedirs: true
  187. - require:
  188. - pkg: icinga2
  189. - watch_in:
  190. - service: icinga2
  191. # Generate config files for every WBBL device known to pillar
  192. {% for link_id, link_config in salt['pillar.get']('net:wbbl', {}).items () %}
  193. /etc/icinga2/ffho-conf.d/net/wbbl/{{ link_id }}.conf:
  194. file.managed:
  195. - source: salt://icinga2/wbbl.conf.tmpl
  196. - template: jinja
  197. - context:
  198. link_id: {{ link_id }}
  199. link_config: {{ link_config }}
  200. - require:
  201. - file: Create /etc/icinga2/ffho-conf.d/net/wbbl/
  202. - require_in:
  203. - file: Cleanup /etc/icinga2/ffho-conf.d/net/wbbl/
  204. - watch_in:
  205. - service: icinga2
  206. {% endfor %}
  207. ################################################################################
  208. # Icinga2 Client #
  209. ################################################################################
  210. {% else %}
  211. # Nodes should accept config and commands from Icinga2 server
  212. /etc/icinga2/features-available/api.conf:
  213. file.managed:
  214. - source: salt://icinga2/api.conf
  215. - require:
  216. - pkg: icinga2
  217. - watch_in:
  218. - service: icinga2
  219. /etc/icinga2/check-commands.conf:
  220. file.absent:
  221. - watch_in:
  222. - service: icinga2
  223. {% endif %}
  224. ################################################################################
  225. # Check related stuff #
  226. ################################################################################
  227. /etc/icinga2/ffho-conf.d/bird_ospf_interfaces_down_ok.txt:
  228. file.managed:
  229. - source: salt://icinga2/bird_ospf_interfaces_down_ok.txt.tmpl
  230. - template: jinja
  231. - require:
  232. - file: /etc/icinga2/ffho-conf.d
  233. /etc/icinga2/ffho-conf.d/bird_ibgp_sessions_down_ok.txt:
  234. file.managed:
  235. - source: salt://icinga2/bird_ibgp_sessions_down_ok.txt.tmpl
  236. - template: jinja
  237. - require:
  238. - file: /etc/icinga2/ffho-conf.d