timeperiod.pp 2.2 KB

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