apply_notification_to_service.pp 2.8 KB

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