apply_dependency.pp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # == Defined type: icinga2::object::apply_dependency
  2. #
  3. # This is a defined type for Icinga 2 apply dependency objects.
  4. # See the following Icinga 2 doc page for more info:
  5. # http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/configuring-icinga2#objecttype-dependency
  6. #
  7. # === Parameters
  8. #
  9. # See the inline comments.
  10. #
  11. define icinga2::object::apply_dependency (
  12. $object_name = $name,
  13. $display_name = $name,
  14. $object_type = 'Host',
  15. $parent_host_name = undef,
  16. $parent_service_name = undef,
  17. $child_host_name = undef,
  18. $child_service_name = undef,
  19. $disable_checks = undef,
  20. $disable_notifications = undef,
  21. $period = undef,
  22. $states = [],
  23. $assign_where = undef,
  24. $ignore_where = undef,
  25. $target_dir = '/etc/icinga2/conf.d',
  26. $target_file_name = "${name}.conf",
  27. $target_file_ensure = file,
  28. $target_file_owner = 'root',
  29. $target_file_group = 'root',
  30. $target_file_mode = '0644',
  31. $refresh_icinga2_service = true
  32. ) {
  33. # Do some validation of the class' parameters:
  34. validate_string($object_name)
  35. validate_string($display_name)
  36. validate_string($host_name)
  37. validate_string($parent_host_name)
  38. validate_string($child_host_name)
  39. validate_string($child_service_name)
  40. validate_string($parent_service_name)
  41. # validate_bool($disable_checks)
  42. # validate_bool($disable_notifications)
  43. validate_string($period)
  44. validate_array($states)
  45. validate_string($target_dir)
  46. validate_string($target_file_name)
  47. validate_string($target_file_owner)
  48. validate_string($target_file_group)
  49. validate_string($target_file_mode)
  50. validate_bool($refresh_icinga2_service)
  51. validate_re($object_type, ['^Host', '^Service'])
  52. #If the refresh_icinga2_service parameter is set to true...
  53. if $refresh_icinga2_service == true {
  54. file { "${target_dir}/${target_file_name}":
  55. ensure => $target_file_ensure,
  56. owner => $target_file_owner,
  57. group => $target_file_group,
  58. mode => $target_file_mode,
  59. content => template('icinga2/object_apply_dependency.conf.erb'),
  60. #...notify the Icinga 2 daemon so it can restart and pick up changes made to this config file...
  61. notify => Service['icinga2'],
  62. }
  63. }
  64. #...otherwise, use the same file resource but without a notify => parameter:
  65. else {
  66. file { "${target_dir}/${target_file_name}":
  67. ensure => $target_file_ensure,
  68. owner => $target_file_owner,
  69. group => $target_file_group,
  70. mode => $target_file_mode,
  71. content => template('icinga2/object_apply_dependency.conf.erb'),
  72. }
  73. }
  74. }