apply_notification_to_host.pp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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-notification
  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_notification_to_host (
  13. $object_notificationname = $name,
  14. $notification_to_import = undef,
  15. $assign_where = undef,
  16. $ignore_where = undef,
  17. $command = undef,
  18. $vars = {},
  19. $users = [],
  20. $user_groups = [],
  21. $times = {},
  22. $interval = undef,
  23. $period = undef,
  24. $types = [],
  25. $states = [],
  26. $target_dir = '/etc/icinga2/objects/applys',
  27. $target_file_name = "${name}.conf",
  28. $target_file_ensure = file,
  29. $target_file_owner = 'root',
  30. $target_file_group = 'root',
  31. $target_file_mode = '0644',
  32. $refresh_icinga2_service = true
  33. ) {
  34. #Do some validation of the class' parameters:
  35. validate_string($object_notificationname)
  36. validate_string($notification_to_import)
  37. validate_string($command)
  38. validate_hash($vars)
  39. validate_array($users)
  40. validate_array($user_groups)
  41. validate_hash($times)
  42. if $interval {
  43. validate_string($interval)
  44. }
  45. if $period {
  46. validate_string($period)
  47. }
  48. validate_array($types)
  49. validate_array($states)
  50. validate_string($target_dir)
  51. validate_string($target_file_name)
  52. validate_string($target_file_owner)
  53. validate_string($target_file_group)
  54. validate_re($target_file_mode, '^\d{4}$')
  55. validate_bool($refresh_icinga2_service)
  56. #If the refresh_icinga2_service parameter is set to true...
  57. if $refresh_icinga2_service == true {
  58. file { "${target_dir}/${target_file_name}":
  59. ensure => $target_file_ensure,
  60. owner => $target_file_owner,
  61. group => $target_file_group,
  62. mode => $target_file_mode,
  63. content => template('icinga2/object_apply_notification_to_host.conf.erb'),
  64. #...notify the Icinga 2 daemon so it can restart and pick up changes made to this config file...
  65. notify => Service['icinga2'],
  66. }
  67. }
  68. #...otherwise, use the same file resource but without a notify => parameter:
  69. else {
  70. file { "${target_dir}/${target_file_name}":
  71. ensure => $target_file_ensure,
  72. owner => $target_file_owner,
  73. group => $target_file_group,
  74. mode => $target_file_mode,
  75. content => template('icinga2/object_apply_notification_to_host.conf.erb'),
  76. }
  77. }
  78. }