service.pp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # == Defined type: icinga2::object::service
  2. #
  3. # This is a defined type for Icinga 2 service 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-service
  6. #
  7. # === Parameters
  8. #
  9. # See the inline comments.
  10. #
  11. define icinga2::object::service (
  12. $object_servicename = $name,
  13. $template_to_import = 'generic-service',
  14. $display_name = $name,
  15. $host_name = $fqdn,
  16. $groups = [],
  17. $vars = {},
  18. $check_command = undef,
  19. $max_check_attempts = undef,
  20. $check_period = undef,
  21. $check_interval = undef,
  22. $retry_interval = undef,
  23. $enable_notifications = undef,
  24. $enable_active_checks = undef,
  25. $enable_passive_checks = undef,
  26. $enable_event_handler = undef,
  27. $enable_flapping = undef,
  28. $enable_perfdata = undef,
  29. $event_command = undef,
  30. #flapping_threshold is defined as a percentage, eg. 10%, 50%, etc.
  31. $flapping_threshold = undef,
  32. $volatile = undef,
  33. $notes = undef,
  34. $notes_url = undef,
  35. $action_url = undef,
  36. $icon_image = undef,
  37. $icon_image_alt = undef,
  38. $target_dir = '/etc/icinga2/conf.d',
  39. $target_file_name = "${name}.conf",
  40. $target_file_ensure = file,
  41. $target_file_owner = 'root',
  42. $target_file_group = 'root',
  43. $target_file_mode = '0644',
  44. $refresh_icinga2_service = true
  45. ) {
  46. #Do some validation of the class' parameters:
  47. validate_string($object_servicename)
  48. validate_string($template_to_import)
  49. validate_string($display_name)
  50. validate_string($host_name)
  51. validate_array($groups)
  52. validate_hash($vars)
  53. validate_string($target_dir)
  54. validate_string($target_file_name)
  55. validate_string($target_file_owner)
  56. validate_string($target_file_group)
  57. validate_string($target_file_mode)
  58. validate_bool($refresh_icinga2_service)
  59. #If the refresh_icinga2_service parameter is set to true...
  60. if $refresh_icinga2_service == true {
  61. file { "${target_dir}/${target_file_name}":
  62. ensure => $target_file_ensure,
  63. owner => $target_file_owner,
  64. group => $target_file_group,
  65. mode => $target_file_mode,
  66. content => template('icinga2/object_service.conf.erb'),
  67. #...notify the Icinga 2 daemon so it can restart and pick up changes made to this config file...
  68. notify => Service['icinga2'],
  69. }
  70. }
  71. #...otherwise, use the same file resource but without a notify => parameter:
  72. else {
  73. file { "${target_dir}/${target_file_name}":
  74. ensure => $target_file_ensure,
  75. owner => $target_file_owner,
  76. group => $target_file_group,
  77. mode => $target_file_mode,
  78. content => template('icinga2/object_service.conf.erb'),
  79. }
  80. }
  81. }