checkcommand.pp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # == Defined type: icinga2::object::checkcommand
  2. #
  3. # This is a defined type for Icinga 2 apply objects that create check 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-checkcommand
  6. #
  7. # === Parameters
  8. #
  9. # See the inline comments.
  10. #
  11. define icinga2::object::checkcommand (
  12. $object_checkcommandname = $name,
  13. $template_to_import = 'plugin-check-command',
  14. #$methods = undef, Need to get more details about this attribute
  15. $command = undef,
  16. $cmd_path = 'PluginDir',
  17. $arguments = {},
  18. $env = undef,
  19. $vars = {},
  20. $timeout = undef,
  21. $target_dir = '/etc/icinga2/objects/checkcommands',
  22. $checkcommand_template_module = 'icinga2',
  23. $checkcommand_template = 'object_checkcommand.conf.erb',
  24. $checkcommand_source_file = undef,
  25. $checkcommand_file_distribution_method = 'content',
  26. $target_file_name = "${name}.conf",
  27. $target_file_ensure = file,
  28. $target_file_owner = 'root',
  29. $target_file_group = 'root',
  30. $target_file_mode = '0644',
  31. $refresh_icinga2_service = true
  32. ) {
  33. #Do some validation of the class' parameters:
  34. validate_string($object_checkcommandname)
  35. if $checkcommand_template == 'object_checkcommand.conf.erb' {
  36. validate_string($template_to_import)
  37. validate_array($command)
  38. validate_string($cmd_path)
  39. if $env {
  40. validate_hash($env)
  41. }
  42. validate_hash($vars)
  43. if $timeout {
  44. validate_re($timeout, '^\d+$')
  45. }
  46. }
  47. validate_string($target_dir)
  48. validate_string($target_file_name)
  49. validate_string($target_file_owner)
  50. validate_string($target_file_group)
  51. validate_re($target_file_mode, '^\d{4}$')
  52. validate_bool($refresh_icinga2_service)
  53. #If the refresh_icinga2_service parameter is set to true...
  54. if $refresh_icinga2_service == true {
  55. if $checkcommand_file_distribution_method == 'content' {
  56. file {"${target_dir}/${target_file_name}":
  57. ensure => $target_file_ensure,
  58. owner => $target_file_owner,
  59. group => $target_file_group,
  60. mode => $target_file_mode,
  61. content => template("${checkcommand_template_module}/${checkcommand_template}"),
  62. notify => Service['icinga2'],
  63. }
  64. }
  65. elsif $checkcommand_file_distribution_method == 'source' {
  66. file {"${target_dir}/${target_file_name}":
  67. ensure => $target_file_ensure,
  68. owner => $target_file_owner,
  69. group => $target_file_group,
  70. mode => $target_file_mode,
  71. source => $checkcommand_source_file,
  72. notify => Service['icinga2'],
  73. }
  74. }
  75. else {
  76. notify {'Missing/Incorrect File Distribution Method':
  77. message => 'The parameter checkcommand_file_distribution_method is missing or incorrect. Please set content or source',
  78. }
  79. }
  80. }
  81. #...otherwise, use the same file resource but without a notify => parameter:
  82. else {
  83. if $checkcommand_file_distribution_method == 'content' {
  84. file {"${target_dir}/${target_file_name}":
  85. ensure => $target_file_ensure,
  86. owner => $target_file_owner,
  87. group => $target_file_group,
  88. mode => $target_file_mode,
  89. content => template("${checkcommand_template_module}/${checkcommand_template}"),
  90. }
  91. }
  92. elsif $checkcommand_file_distribution_method == 'source' {
  93. file {"${target_dir}/${target_file_name}":
  94. ensure => $target_file_ensure,
  95. owner => $target_file_owner,
  96. group => $target_file_group,
  97. mode => $target_file_mode,
  98. source => $checkcommand_source_file,
  99. }
  100. }
  101. else {
  102. notify {'Missing/Incorrect File Distribution Method':
  103. message => 'The parameter checkcommand_file_distribution_method is missing or incorrect. Please set content or source',
  104. }
  105. }
  106. }
  107. }