/manifests/mysql.pp

https://gitlab.com/nrvale0/newrelic_plugins_puppet · Puppet · 165 lines · 67 code · 11 blank · 87 comment · 0 complexity · b1040c45677e2f96d0b7b4045b458189 MD5 · raw file

  1. # = Class: newrelic_plugins::mysql
  2. #
  3. # This class installs/configures/manages New Relic's MySQL Plugin.
  4. # Only supported on Debian-derived and Red Hat-derived OSes.
  5. #
  6. # == Parameters:
  7. #
  8. # $license_key:: License Key for your New Relic account
  9. #
  10. # $install_path:: Install Path for New Relic MySQL Plugin.
  11. # Any downloaded files will be placed here.
  12. # The plugin will be installed within this
  13. # directory at `newrelic_mysql_plugin`.
  14. #
  15. # $user:: User to run as
  16. #
  17. # $version:: New Relic MySQL Plugin Version.
  18. # Currently defaults to the latest version.
  19. #
  20. # $servers:: Array of MySQL server information. If using the default username
  21. # and password, the user and passwd attributes can be left off.
  22. # (see mysql_user and mysql_passwd)
  23. # Note also that the "name" defaults to the same as the "host"
  24. # unless overriden, and as such "name" is optional.
  25. #
  26. # $metrics:: Default set of metrics. Can override in $servers.
  27. #
  28. # $mysql_user:: Default username. Can override in $servers.
  29. #
  30. # $mysql_passwd:: Default clear text password. Can override in $servers.
  31. #
  32. # $java_options:: String of java options that will be passed to the init script java command.
  33. # E.g. -Dhttps.proxyHost=proxy.example.com -Dhttps.proxyPort=12345
  34. # for proxy support. Defaults to -Xmx128m (max 128mb heap size).
  35. #
  36. # $service_enable:: Boolean. Service enabled at boot. Maps to 'enabled' parameter for service.
  37. # Default: true
  38. #
  39. # $service_ensure:: Service 'ensure' parameter. Default: running.
  40. #
  41. # == Requires:
  42. #
  43. # puppetlabs/stdlib
  44. #
  45. # == Sample Usage:
  46. #
  47. # class { 'newrelic_plugins::mysql':
  48. # license_key => 'NEW_RELIC_LICENSE_KEY',
  49. # install_path => '/path/to/plugin',
  50. # user => 'newrelic',
  51. # metrics => 'status,newrelic',
  52. # mysql_user => 'USER_NAME_HERE',
  53. # mysql_passwd => 'USER_CLEAR_TEXT_PASSWORD_HERE',
  54. # servers => [
  55. # {
  56. # name => 'Production Master',
  57. # host => 'localhost'
  58. # },
  59. # {
  60. # name => 'Production Slave',
  61. # host => 'localhost'
  62. # }
  63. # ]
  64. # }
  65. #
  66. # class { 'newrelic_plugins::mysql':
  67. # license_key => 'NEW_RELIC_LICENSE_KEY',
  68. # install_path => '/path/to/plugin',
  69. # servers => [
  70. # {
  71. # name => 'Production Master',
  72. # host => 'localhost',
  73. # metrics => 'status,newrelic',
  74. # mysql_user => 'USER_NAME_HERE',
  75. # mysql_passwd => 'USER_CLEAR_TEXT_PASSWORD_HERE'
  76. # }
  77. # ]
  78. # }
  79. #
  80. class newrelic_plugins::mysql (
  81. $license_key,
  82. $install_path,
  83. $user,
  84. $version = $newrelic_plugins::params::mysql_version,
  85. $servers,
  86. $metrics = '',
  87. $mysql_user = '',
  88. $mysql_passwd = '',
  89. $java_options = $newrelic_plugins::params::mysql_java_options,
  90. $newrelic_template = 'newrelic_plugins/mysql/newrelic.json.erb',
  91. $plugin_template = 'newrelic_plugins/mysql/plugin.json.erb',
  92. $service_enable = true,
  93. $service_ensure = running,
  94. ) inherits params {
  95. include stdlib
  96. # verify java is installed
  97. newrelic_plugins::resource::verify_java { 'MySQL Plugin': }
  98. # verify attributes
  99. validate_absolute_path($install_path)
  100. validate_string($user)
  101. validate_string($version)
  102. validate_array($servers)
  103. # verify license_key
  104. newrelic_plugins::resource::verify_license_key { 'MySQL Plugin: Verify New Relic License Key':
  105. license_key => $license_key
  106. }
  107. $plugin_path = "${install_path}/newrelic_mysql_plugin"
  108. # install plugin
  109. newrelic_plugins::resource::install_plugin { 'newrelic_mysql_plugin':
  110. install_path => $install_path,
  111. plugin_path => $plugin_path,
  112. download_url => "${$newrelic_plugins::params::mysql_download_baseurl}-${version}.tar.gz",
  113. version => $version,
  114. user => $user
  115. }
  116. # newrelic.json template
  117. file { "${plugin_path}/config/newrelic.json":
  118. ensure => file,
  119. content => template($newrelic_template),
  120. owner => $user,
  121. notify => Service['newrelic-mysql-plugin']
  122. }
  123. # plugin.json template
  124. file { "${plugin_path}/config/plugin.json":
  125. ensure => file,
  126. content => template($plugin_template),
  127. owner => $user,
  128. notify => Service['newrelic-mysql-plugin']
  129. }
  130. # install init.d script and start service
  131. newrelic_plugins::resource::plugin_service { 'newrelic-mysql-plugin':
  132. daemon => 'plugin.jar',
  133. daemon_dir => $plugin_path,
  134. plugin_name => 'MySQL',
  135. plugin_version => $version,
  136. user => $user,
  137. run_command => "java ${java_options} -jar",
  138. service_name => 'newrelic-mysql-plugin',
  139. service_enable => $service_enable,
  140. service_ensure => $service_ensure,
  141. }
  142. # ordering
  143. Newrelic_plugins::Resource::Verify_java['MySQL Plugin']
  144. ->
  145. Newrelic_plugins::Resource::Verify_license_key['MySQL Plugin: Verify New Relic License Key']
  146. ->
  147. Newrelic_plugins::Resource::Install_plugin['newrelic_mysql_plugin']
  148. ->
  149. File["${plugin_path}/config/newrelic.json"]
  150. ->
  151. File["${plugin_path}/config/plugin.json"]
  152. ->
  153. Newrelic_plugins::Resource::Plugin_service['newrelic-mysql-plugin']
  154. }