summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMicah Anderson <micah@riseup.net>2010-10-17 18:23:42 -0400
committerMicah Anderson <micah@riseup.net>2010-10-17 18:23:42 -0400
commit60311652002861f64618417d580e2174fa3325cc (patch)
tree96841975fc27e9c26ee79d59952973ebac21f6b7
parent9463479afa16c2d25c9298d76b07e3363b3d170a (diff)
simplify the nagios check_mysql_health plugin process:
1. use the new plugin deploy feature in nagios (nagios::plugin::deploy) 2. remove unnecessary classes and inheritance - this plugin seems reasonable to install by default, and in fact it could be argued that the other 'check_mysql' plugin that still remains can be removed, as its functionality is vastly overshadowed by this one 3. add the 'repl_client_priv' mysql grant privs to the nagios user. these are needed for the check_mysql_health plugin slave replication modes. According to http://dev.mysql.com/doc/refman/5.0/en/privileges-provided.html#priv_replication-client - The REPLICATION CLIENT privilege enables the use of SHOW MASTER STATUS and SHOW SLAVE STATUS. These privileges are not too much to provide to the nagios user, as they are only informational 4. setup the define "check_health" so it can be used easily
-rw-r--r--manifests/server/nagios.pp104
1 files changed, 64 insertions, 40 deletions
diff --git a/manifests/server/nagios.pp b/manifests/server/nagios.pp
index 1815882..dde911e 100644
--- a/manifests/server/nagios.pp
+++ b/manifests/server/nagios.pp
@@ -1,61 +1,85 @@
# manifests/server/nagios.pp
-class mysql::server::nagios::base {
-
+class mysql::server::nagios {
case $nagios_mysql_password {
'': { fail("please specify \$nagios_mysql_password to enable nagios mysql check")}
}
-
+
+ # Flip this variable if you need to check MySQL through check_ssh or check_nrpe,
+ # in that case you will have to manually define nagios::service::mysql
+ if ($nagios_mysql_notcp != true) {
+ $nagios_mysql_user = 'nagios@%'
+ nagios::service::mysql { 'mysql':
+ check_hostname => $fqdn,
+ check_username => 'nagios',
+ check_password => $nagios_mysql_password,
+ check_mode => 'tcp',
+ require => Mysql_grant[$nagios_mysql_user],
+ }
+ }
+ else {
+ $nagios_mysql_user = 'nagios@localhost'
+ }
+
mysql_user{$nagios_mysql_user:
password_hash => mysql_password("${nagios_mysql_password}"),
require => Package['mysql'],
}
-
+
+ # repl_client_priv is needed to check the replication slave status
+ # modes: slave-lag, slave-io-running and slave-sql-running
mysql_grant{$nagios_mysql_user:
- privileges => 'select_priv',
+ privileges => [ 'select_priv', 'repl_client_priv' ],
require => [ Mysql_user[$nagios_mysql_user], Package['mysql'] ],
}
-}
-class mysql::server::nagios inherits mysql::server::nagios::base {
-
- # Flip this variable if you need to check MySQL through check_ssh or check_nrpe,
- # in that case you will have to manually define nagios::service::mysql
- if ($nagios_mysql_notcp != true) {
- $nagios_mysql_user = 'nagios@%'
- nagios::service::mysql { 'mysql':
- check_hostname => $fqdn,
- check_username => 'nagios',
- check_password => $nagios_mysql_password,
- check_mode => 'tcp',
- require => Mysql_grant[$nagios_mysql_user],
- }
- }
- else {
- $nagios_mysql_user = 'nagios@localhost'
- }
-}
-
-class mysql::server::nagios::check_health inherits mysql::server::nagios::base {
-
- nagios::plugin{'check_mysql_health':
- source => 'mysql/nagios/check_mysql_health';
+ nagios::plugin::deploy{'check_mysql_health':
+ source => 'mysql/nagios/check_mysql_health',
+ require_package => 'libdbd-mysql-perl';
}
@@nagios_command{
'check_mysql_health':
- command_line => '$USER1$/check_mysql_health --hostname $ARG1$ --port $ARG2$ --username $ARG3$ --password $ARG4$ --mode $ARG5$ --database $ARG6$',
- require => Nagios::Plugin['check_mysql_health'];
- }
-
- case $mysql_nagios_user {
- '': { $mysql_nagios_user = 'nagios' }
+ command_line => '$USER1$/check_mysql_health --hostname $ARG1$ --port $ARG2$ --username $ARG3$ --password $ARG4$ --mode $ARG5$ --database $ARG6$';
}
- if ($nagios_mysql_notcp != true) {
- $nagios_mysql_user = 'nagios@%'
- }
- else {
- $nagios_mysql_user = 'nagios@localhost'
+ define check_health (
+ $ensure = present,
+ $check_hostname = $fqdn,
+ $check_port = '3306',
+ $check_username = 'nagios',
+ $check_password = $nagios_mysql_password,
+ $check_database = 'information_schema',
+ $check_warning = undef,
+ $check_critical = undef,
+ $check_health_mode = $name,
+ $check_name = undef,
+ $check_name2 = undef,
+ $check_regexp = undef,
+ $check_units = undef,
+ $check_mode = 'tcp' )
+ {
+ case $check_mode {
+ 'tcp': {
+ if ($check_hostname == 'localhost') {
+ $real_check_hostname = '127.0.0.1'
+ }
+ else {
+ $real_check_hostname = $check_hostname
+ }
+ }
+ default: {
+ if ($check_hostname == '127.0.0.1') {
+ $real_check_hostname = 'localhost'
+ }
+ else {
+ $real_check_hostname = $check_hostname
+ }
+ }
+ }
+ nagios::service { "mysql_health_${name}":
+ ensure => $ensure,
+ check_command => "check_mysql_health!${check_hostname}!${check_port}!${check_username}!${check_password}!${name}!${check_database}",
+ }
}
}