apply_service_to_host.pp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # == Defined type: icinga2::object::apply_service_to_host
  2. #
  3. # This is a defined type for Icinga 2 apply objects that apply services to hosts.
  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-host
  6. # http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/configuring-icinga2#apply
  7. #
  8. # === Parameters
  9. #
  10. # See the inline comments.
  11. #
  12. define icinga2::object::apply_service_to_host (
  13. $object_servicename = $name,
  14. $template_to_import = 'generic-service',
  15. $display_name = $name,
  16. $assign_where = undef,
  17. $ignore_where = undef,
  18. $groups = [],
  19. $vars = {},
  20. $check_command = undef,
  21. $max_check_attempts = undef,
  22. $check_period = undef,
  23. $check_interval = undef,
  24. $retry_interval = undef,
  25. $enable_notifications = undef,
  26. $enable_active_checks = undef,
  27. $enable_passive_checks = undef,
  28. $enable_event_handler = undef,
  29. $enable_flapping = undef,
  30. $enable_perfdata = undef,
  31. $event_command = undef,
  32. #flapping_threshold is defined as a percentage, eg. 10%, 50%, etc.
  33. $flapping_threshold = undef,
  34. $volatile = undef,
  35. $notes = undef,
  36. $notes_url = undef,
  37. $action_url = undef,
  38. $icon_image = undef,
  39. $icon_image_alt = undef,
  40. $target_dir = '/etc/icinga2/conf.d',
  41. $target_file_name = "${name}.conf",
  42. $target_file_ensure = file,
  43. $target_file_owner = 'root',
  44. $target_file_group = 'root',
  45. $target_file_mode = '0644',
  46. $refresh_icinga2_service = true
  47. ) {
  48. #Do some validation of the class' parameters:
  49. validate_string($object_servicename)
  50. validate_string($template_to_import)
  51. validate_array($groups)
  52. validate_hash($vars)
  53. validate_string($target_dir)
  54. validate_string($target_file_name)
  55. validate_string($target_file_owner)
  56. validate_string($target_file_group)
  57. validate_string($target_file_mode)
  58. validate_bool($refresh_icinga2_service)
  59. #If the refresh_icinga2_service parameter is set to true...
  60. if $refresh_icinga2_service == true {
  61. file { "${target_dir}/${target_file_name}":
  62. ensure => $target_file_ensure,
  63. owner => $target_file_owner,
  64. group => $target_file_group,
  65. mode => $target_file_mode,
  66. content => template('icinga2/object_apply_service_to_host.conf.erb'),
  67. #...notify the Icinga 2 daemon so it can restart and pick up changes made to this config file...
  68. notify => Service['icinga2'],
  69. }
  70. }
  71. #...otherwise, use the same file resource but without a notify => parameter:
  72. else {
  73. file { "${target_dir}/${target_file_name}":
  74. ensure => $target_file_ensure,
  75. owner => $target_file_owner,
  76. group => $target_file_group,
  77. mode => $target_file_mode,
  78. content => template('icinga2/object_apply_service_to_host.conf.erb'),
  79. }
  80. }
  81. }