summaryrefslogtreecommitdiff
path: root/manifests/service/mysql.pp
blob: 2605e8d1ef80d9c73b6f82f1a3dd045171412436 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Checks a mysql instance via tcp or socket

define nagios::service::mysql(
    $ensure = present,
    $check_hostname = 'absent',
    $check_port = '3306',
    $check_username = 'nagios',
    $check_password = '',
    $check_database = 'absent',
    $check_mode = 'tcp'
){
    if ($check_hostname == 'absent') {
        fail("Please specify a hostname, ip address or socket to check a mysql instance.")
    }

    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
            }
        }
    }

    if ($check_database == 'absent') {
        nagios::service { 'mysql':
            ensure        => $ensure,
            check_command => "check_mysql!${real_check_hostname}!${check_port}!${check_username}!${check_password}",
        }
    }
    else {
        nagios::service { "mysql_${check_database}":
            ensure        => $ensure,
            check_command => "check_mysql_db!${real_check_hostname}!${check_port}!${check_username}!${check_password}!${check_database}",
        }
    }

}

define nagios::service::mysql_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'
){

  if ($check_username == '') {
    $real_check_username = 'nagios'
  }
  
  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_${check_health_mode}':
    ensure        => $ensure,
    check_command => "check_mysql_health!${check_hostname}!${check_port}!${real_check_username}!${check_password}${check_health_mode}!{check_database}",
  }
}