notification.pp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # == Defined type: icinga2::object::notification
  2. #
  3. # This is a defined type for Icinga 2 apply objects that create notification commands
  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. #
  7. # === Parameters
  8. #
  9. # See the inline comments.
  10. #
  11. define icinga2::object::notification (
  12. $object_notificationname = $name,
  13. $command = undef,
  14. $host_name = undef,
  15. $service_name = undef,
  16. $vars = {},
  17. $users = [],
  18. $user_groups = [],
  19. $times = {},
  20. $interval = undef,
  21. $period = undef,
  22. $types = [],
  23. $states = [],
  24. $target_dir = '/etc/icinga2/objects/notifications',
  25. $target_file_name = "${name}.conf",
  26. $target_file_ensure = file,
  27. $target_file_owner = 'root',
  28. $target_file_group = 'root',
  29. $target_file_mode = '0644',
  30. $refresh_icinga2_service = true
  31. ) {
  32. #Do some validation of the class' parameters:
  33. validate_string($object_notificationname)
  34. validate_string($command)
  35. if $host_name {
  36. validate_string($host_name)
  37. }
  38. if $service_name {
  39. validate_string($service_name)
  40. }
  41. validate_hash($vars)
  42. validate_array($users)
  43. validate_array($user_groups)
  44. validate_hash($times)
  45. if $interval {
  46. validate_re($interval, '^\d$')
  47. }
  48. if $period {
  49. validate_string($period)
  50. }
  51. validate_array($types)
  52. #Array concatenation not available,
  53. #if $types - ['DowntimeStart','DowntimeEnd','DowntimeRemoved','Custom','Acknowledgement','Problem','Recovery','FlappingStart','FlappingEnd'] != [] {
  54. # fail ('You are using unavailable notification type filter.')
  55. #}
  56. validate_array($states)
  57. #Array concatenation not available,
  58. #if $states - ['OK','Warning','Critical','Unknown','Up','Down'] != [] {
  59. # fail ('You are using unavailable state type filter.')
  60. #}
  61. validate_string($target_dir)
  62. validate_string($target_file_name)
  63. validate_string($target_file_owner)
  64. validate_string($target_file_group)
  65. validate_re($target_file_mode, '^\d{4}$')
  66. validate_bool($refresh_icinga2_service)
  67. #If the refresh_icinga2_service parameter is set to true...
  68. if $refresh_icinga2_service == true {
  69. file { "${target_dir}/${target_file_name}":
  70. ensure => $target_file_ensure,
  71. owner => $target_file_owner,
  72. group => $target_file_group,
  73. mode => $target_file_mode,
  74. content => template('icinga2/object_notification.conf.erb'),
  75. #...notify the Icinga 2 daemon so it can restart and pick up changes made to this config file...
  76. notify => Service['icinga2'],
  77. }
  78. }
  79. #...otherwise, use the same file resource but without a notify => parameter:
  80. else {
  81. file { "${target_dir}/${target_file_name}":
  82. ensure => $target_file_ensure,
  83. owner => $target_file_owner,
  84. group => $target_file_group,
  85. mode => $target_file_mode,
  86. content => template('icinga2/object_notification.conf.erb'),
  87. }
  88. }
  89. }