perfdatawriter.pp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # == Defined type: icinga2::object::perfdatawriter
  2. #
  3. # This is a defined type for Icinga 2 apply objects that create Perfdata Writer
  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-perfdatawriter
  6. #
  7. # === Parameters
  8. #
  9. # See the inline comments.
  10. #
  11. define icinga2::object::perfdatawriter (
  12. $ensure = 'file',
  13. $object_perfdatawritername = $name,
  14. $host_perfdata_path = undef,
  15. $service_perfdata_path = undef,
  16. $host_temp_path = undef,
  17. $service_temp_path = undef,
  18. $host_format_template = undef,
  19. $service_format_template = undef,
  20. $rotation_interval = undef,
  21. $target_dir = '/etc/icinga2/objects/perfdatawriters',
  22. $target_file_name = "${name}.conf",
  23. $target_file_ensure = file,
  24. $target_file_owner = 'root',
  25. $target_file_group = 'root',
  26. $target_file_mode = '0644',
  27. $refresh_icinga2_service = true
  28. ) {
  29. #Do some validation of the class' parameters:
  30. if $object_perfdatawritername {
  31. validate_string($object_perfdatawritername)
  32. }
  33. if $host_perfdata_path {
  34. validate_string($host_perfdata_path)
  35. }
  36. if $service_perfdata_path {
  37. validate_string($service_perfdata_path)
  38. }
  39. if $host_temp_path {
  40. validate_string($host_temp_path)
  41. }
  42. if $service_temp_path {
  43. validate_string($service_temp_path)
  44. }
  45. if $host_format_template {
  46. validate_string($host_format_template)
  47. }
  48. if $service_format_template {
  49. validate_string($service_format_template)
  50. }
  51. if $rotation_interval {
  52. validate_string($rotation_interval)
  53. }
  54. validate_string($target_dir)
  55. validate_string($target_file_name)
  56. validate_string($target_file_owner)
  57. validate_string($target_file_group)
  58. validate_re($target_file_mode, '^\d{4}$')
  59. validate_bool($refresh_icinga2_service)
  60. #If the refresh_icinga2_service parameter is set to true...
  61. if $refresh_icinga2_service == true {
  62. file { "${target_dir}/${target_file_name}":
  63. ensure => $target_file_ensure,
  64. owner => $target_file_owner,
  65. group => $target_file_group,
  66. mode => $target_file_mode,
  67. content => template('icinga2/object_perfdatawriter.conf.erb'),
  68. #...notify the Icinga 2 daemon so it can restart and pick up changes made to this config file...
  69. notify => Service['icinga2'],
  70. }
  71. }
  72. #...otherwise, use the same file resource but without a notify => parameter:
  73. else {
  74. file { "${target_dir}/${target_file_name}":
  75. ensure => $target_file_ensure,
  76. owner => $target_file_owner,
  77. group => $target_file_group,
  78. mode => $target_file_mode,
  79. content => template('icinga2/object_perfdatawriter.conf.erb'),
  80. }
  81. }
  82. }