eventcommand.pp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # == Defined type: icinga2::object::eventcommand
  2. #
  3. # This is a defined type for Icinga 2 apply objects that create event 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-eventcommand
  6. #
  7. # === Parameters
  8. #
  9. # See the inline comments.
  10. #
  11. define icinga2::object::eventcommand (
  12. $object_eventcommandname = $name,
  13. $template_to_import = 'plugin-event-command',
  14. #$methods = undef Need to get more details about this attribute
  15. $command = undef,
  16. $cmd_path = 'PluginDir',
  17. $arguments = {},
  18. $env = {},
  19. $vars = {},
  20. $timeout = undef,
  21. $target_dir = '/etc/icinga2/objects/eventcommands',
  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. validate_string($object_eventcommandname)
  31. validate_string($template_to_import)
  32. validate_array($command)
  33. validate_string($cmd_path)
  34. validate_hash($arguments)
  35. validate_hash($env)
  36. validate_hash($vars)
  37. if $timeout {
  38. validate_re($timeout, '^\d+$')
  39. }
  40. validate_string($target_dir)
  41. validate_string($target_file_name)
  42. validate_string($target_file_owner)
  43. validate_string($target_file_group)
  44. validate_re($target_file_mode, '^\d{4}$')
  45. validate_bool($refresh_icinga2_service)
  46. #If the refresh_icinga2_service parameter is set to true...
  47. if $refresh_icinga2_service == true {
  48. file { "${target_dir}/${target_file_name}":
  49. ensure => $target_file_ensure,
  50. owner => $target_file_owner,
  51. group => $target_file_group,
  52. mode => $target_file_mode,
  53. content => template('icinga2/object_eventcommand.conf.erb'),
  54. #...notify the Icinga 2 daemon so it can restart and pick up changes made to this config file...
  55. notify => Service['icinga2'],
  56. }
  57. }
  58. #...otherwise, use the same file resource but without a notify => parameter:
  59. else {
  60. file { "${target_dir}/${target_file_name}":
  61. ensure => $target_file_ensure,
  62. owner => $target_file_owner,
  63. group => $target_file_group,
  64. mode => $target_file_mode,
  65. content => template('icinga2/object_eventcommand.conf.erb'),
  66. }
  67. }
  68. }