host.pp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # == Defined type: icinga2::object::host
  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-host
  6. #
  7. # === Parameters
  8. #
  9. # See the inline comments.
  10. #
  11. define icinga2::object::host (
  12. $object_hostname = $name,
  13. $display_name = $fqdn,
  14. $ipv4_address = $ipaddress,
  15. $ipv6_address = undef,
  16. $template_to_import = 'generic-host',
  17. $groups = [],
  18. $vars = {},
  19. $check_command = undef,
  20. $max_check_attempts = undef,
  21. $check_period = undef,
  22. $check_interval = undef,
  23. $retry_interval = undef,
  24. $enable_notifications = undef,
  25. $enable_active_checks = undef,
  26. $enable_passive_checks = undef,
  27. $enable_event_handler = undef,
  28. $enable_flapping = undef,
  29. $enable_perfdata = undef,
  30. $event_command = undef,
  31. #flapping_threshold is defined as a percentage, eg. 10%, 50%, etc.
  32. $flapping_threshold = undef,
  33. $volatile = undef,
  34. $notes = undef,
  35. $notes_url = undef,
  36. $action_url = undef,
  37. $icon_image = undef,
  38. $icon_image_alt = undef,
  39. $target_dir = '/etc/icinga2/objects',
  40. $target_file_name = "${fqdn}.conf",
  41. $target_file_ensure = file,
  42. $target_file_owner = 'root',
  43. $target_file_group = 'root',
  44. $target_file_mode = '0644',
  45. $refresh_icinga2_service = true
  46. ) {
  47. #Do some validation of the class' parameters:
  48. validate_string($object_hostname)
  49. validate_string($template_to_import)
  50. validate_string($display_name)
  51. validate_string($ipv4_address)
  52. validate_array($groups)
  53. validate_hash($vars)
  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_string($target_file_mode)
  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_host.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_host.conf.erb'),
  80. }
  81. }
  82. }