apilistener.pp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # == Defined type: icinga2::object::apilistener
  2. #
  3. # This is a defined type for Icinga 2 apply objects that create apilistener 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-apilistener
  6. #
  7. # === Parameters
  8. #
  9. # See the inline comments.
  10. #
  11. define icinga2::object::apilistener (
  12. $ensure = 'file',
  13. $object_name = $name,
  14. $cert_path = 'SysconfDir + "/icinga2/pki/" + NodeName + ".crt"',
  15. $key_path = 'SysconfDir + "/icinga2/pki/" + NodeName + ".key"',
  16. $ca_path = 'SysconfDir + "/icinga2/pki/ca.crt"',
  17. $crl_path = undef,
  18. $bind_host = '0.0.0.0',
  19. $bind_port = 5665,
  20. $accept_config = false,
  21. $accept_commands = false,
  22. $target_dir = '/etc/icinga2/objects/apilisteners',
  23. $target_file_name = "${name}.conf",
  24. $target_file_ensure = file,
  25. $target_file_owner = 'root',
  26. $target_file_group = 'root',
  27. $target_file_mode = '0644',
  28. $refresh_icinga2_service = true,
  29. ) {
  30. validate_string($cert_path)
  31. validate_string($key_path)
  32. validate_string($ca_path)
  33. if $crl_path { validate_string($crl_path) }
  34. if $bind_host { validate_string($bind_host) }
  35. if $bind_port { validate_re($bind_port, '^\d{1,5}$') }
  36. if $accept_config { validate_bool($accept_config) }
  37. if $accept_commands { validate_bool($accept_commands) }
  38. validate_string($target_dir)
  39. validate_string($target_file_name)
  40. validate_string($target_file_owner)
  41. validate_string($target_file_group)
  42. validate_re($target_file_mode, '^\d{4}$')
  43. validate_bool($refresh_icinga2_service)
  44. #If the refresh_icinga2_service parameter is set to true...
  45. if $refresh_icinga2_service == true {
  46. file { "${target_dir}/${target_file_name}":
  47. ensure => $target_file_ensure,
  48. owner => $target_file_owner,
  49. group => $target_file_group,
  50. mode => $target_file_mode,
  51. content => template('icinga2/object_apilistener.conf.erb'),
  52. #...notify the Icinga 2 daemon so it can restart and pick up changes made to this config file...
  53. notify => Service['icinga2'],
  54. }
  55. }
  56. #...otherwise, use the same file resource but without a notify => parameter:
  57. else {
  58. file { "${target_dir}/${target_file_name}":
  59. ensure => $target_file_ensure,
  60. owner => $target_file_owner,
  61. group => $target_file_group,
  62. mode => $target_file_mode,
  63. content => template('icinga2/object_apilistener.conf.erb'),
  64. }
  65. }
  66. }