notification.pp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_owner = 'root',
  27. $target_file_group = 'root',
  28. $target_file_mode = '0644'
  29. ) {
  30. #Do some validation of the class' parameters:
  31. validate_string($object_notificationname)
  32. validate_string($command)
  33. if $host_name {
  34. validate_string($host_name)
  35. }
  36. if $service_name {
  37. validate_string($service_name)
  38. }
  39. validate_hash($vars)
  40. validate_array($users)
  41. validate_array($user_groups)
  42. validate_hash($times)
  43. if $interval {
  44. validate_re($interval, '^\d$')
  45. }
  46. if $period {
  47. validate_string($period)
  48. }
  49. validate_array($types)
  50. /** Array concatenation not available,
  51. if $types - ['DowntimeStart','DowntimeEnd','DowntimeRemoved','Custom','Acknowledgement','Problem','Recovery','FlappingStart','FlappingEnd'] != [] {
  52. fail ('You are using unavailable notification type filter.')
  53. }
  54. */
  55. validate_array($states)
  56. /** Array concatenation not available,
  57. if $states - ['OK','Warning','Critical','Unknown','Up','Down'] != [] {
  58. fail ('You are using unavailable state type filter.')
  59. }
  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. file {"${target_dir}/${target_file_name}":
  67. ensure => file,
  68. owner => $target_file_owner,
  69. group => $target_file_group,
  70. mode => $target_file_mode,
  71. content => template('icinga2/object_notification.conf.erb'),
  72. notify => Service['icinga2'],
  73. }
  74. }