scheduleddowntime.pp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # == Defined type: icinga2::object::scheduleddowntime
  2. #
  3. # This is a defined type for Icinga 2 ScheduledDowntime 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-scheduleddowntime
  6. #
  7. # === Parameters
  8. #
  9. # See the inline comments.
  10. #
  11. define icinga2::object::scheduleddowntime (
  12. $object_scheduleddowntimename = $name,
  13. $host_name = undef,
  14. $service_name = undef,
  15. $author = undef,
  16. $comment = undef,
  17. $fixed = true,
  18. $duration = undef,
  19. $ranges = {},
  20. $target_dir = '/etc/icinga2/objects/scheduleddowntimes',
  21. $target_file_name = "${name}.conf",
  22. $target_file_ensure = file,
  23. $target_file_owner = 'root',
  24. $target_file_group = 'root',
  25. $target_file_mode = '0644',
  26. $refresh_icinga2_service = true
  27. ) {
  28. #Do some validation of the define's parameters:
  29. validate_string($object_scheduleddowntimename)
  30. validate_string($host_name)
  31. if $service_name {
  32. validate_string($service_name)
  33. }
  34. validate_string($author)
  35. validate_string($comment)
  36. validate_bool($fixed)
  37. validate_string($duration)
  38. validate_hash($ranges)
  39. validate_string($target_dir)
  40. validate_string($target_file_name)
  41. validate_string($target_file_owner)
  42. validate_string($target_file_group)
  43. validate_string($target_file_mode)
  44. validate_bool($refresh_icinga2_service)
  45. #If the refresh_icinga2_service parameter is set to true...
  46. if $refresh_icinga2_service == true {
  47. file { "${target_dir}/${target_file_name}":
  48. ensure => $target_file_ensure,
  49. owner => $target_file_owner,
  50. group => $target_file_group,
  51. mode => $target_file_mode,
  52. content => template('icinga2/object_scheduleddowntime.conf.erb'),
  53. #...notify the Icinga 2 daemon so it can restart and pick up changes made to this config file...
  54. notify => Service['icinga2'],
  55. }
  56. }
  57. #...otherwise, use the same file resource but without a notify => parameter:
  58. else {
  59. file { "${target_dir}/${target_file_name}":
  60. ensure => $target_file_ensure,
  61. owner => $target_file_owner,
  62. group => $target_file_group,
  63. mode => $target_file_mode,
  64. content => template('icinga2/object_scheduleddowntime.conf.erb'),
  65. }
  66. }
  67. }