idomysqlconnection.pp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # == Defined type: icinga2::object::idomysqlconnection
  2. #
  3. # This is a defined type for Icinga 2 IDO MySQL connection 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-idomysqlconnection
  6. #
  7. # === Parameters
  8. #
  9. # See the inline comments.
  10. #
  11. define icinga2::object::idomysqlconnection (
  12. $object_name = $name,
  13. $host = 'localhost',
  14. $port = 3306,
  15. $user = 'icinga',
  16. $password = 'icinga',
  17. $database = 'icinga',
  18. $table_prefix = 'icinga_',
  19. $instance_name = 'default',
  20. $instance_description = undef,
  21. $cleanup = {
  22. acknowledgements_age => 0,
  23. commenthistory_age => 0,
  24. contactnotifications_age => 0,
  25. contactnotificationmethods_age => 0,
  26. downtimehistory_age => 0,
  27. eventhandlers_age => 0,
  28. externalcommands_age => 0,
  29. flappinghistory_age => 0,
  30. hostchecks_age => 0,
  31. logentries_age => 0,
  32. notifications_age => 0,
  33. processevents_age => 0,
  34. statehistory_age => 0,
  35. servicechecks_age => 0,
  36. systemcommands_age => 0
  37. },
  38. $categories = [],
  39. $target_dir = '/etc/icinga2/conf.d',
  40. $target_file_ensure = file,
  41. $target_file_name = "${name}.conf",
  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_name)
  49. validate_string($template_to_import)
  50. validate_string($host)
  51. validate_string($user)
  52. validate_string($password)
  53. validate_string($database)
  54. validate_string($table_prefix)
  55. validate_string($instance_name)
  56. validate_hash($cleanup)
  57. validate_array($categories)
  58. validate_string($target_dir)
  59. validate_string($target_file_name)
  60. validate_string($target_file_owner)
  61. validate_string($target_file_group)
  62. validate_string($target_file_mode)
  63. validate_bool($refresh_icinga2_service)
  64. #If the refresh_icinga2_service parameter is set to true...
  65. if $refresh_icinga2_service == true {
  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. content => template('icinga2/object_idomysqlconnection.conf.erb'),
  72. #...notify the Icinga 2 daemon so it can restart and pick up changes made to this config file...
  73. notify => Service['icinga2'],
  74. }
  75. }
  76. #...otherwise, use the same file resource but without a notify => parameter:
  77. else {
  78. file { "${target_dir}/${target_file_name}":
  79. ensure => $target_file_ensure,
  80. owner => $target_file_owner,
  81. group => $target_file_group,
  82. mode => $target_file_mode,
  83. content => template('icinga2/object_idomysqlconnection.conf.erb'),
  84. }
  85. }
  86. }