Defined Type: monitor::url

Defined in:
manifests/url.pp

Overview

Parameters:

  • tool (Any)
  • url (Any) (defaults to: 'http://127.0.0.1')
  • target (Any) (defaults to: '')
  • host (Any) (defaults to: '')
  • port (Any) (defaults to: '80')
  • pattern (Any) (defaults to: '')
  • username (Any) (defaults to: '')
  • password (Any) (defaults to: '')
  • monitorgroup (Any) (defaults to: '')
  • template (Any) (defaults to: '')
  • useragent (Any) (defaults to: 'UrlCheck')
  • checksource (Any) (defaults to: 'remote')
  • enable (Any) (defaults to: true)


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
100
101
102
103
104
105
106
107
108
109
110
# File 'manifests/url.pp', line 1

define monitor::url (
  $tool,
  $url          = 'http://127.0.0.1',
  $target       = '',
  $host         = '',
  $port         = '80',
  $pattern      = '',
  $username     = '',
  $password     = '',
  $monitorgroup = '',
  $template     = '',
  $useragent    = 'UrlCheck',
  $checksource  = 'remote',
  $enable       = true
  ) {

  $bool_enable=any2bool($enable)

  $ensure = $bool_enable ? {
    false => 'absent',
    true  => 'present',
  }

  # If target is not provided we get it from the Url
  $computed_target = $target ? {
    ''      => url_parse($url,host),
    default => $target,
  }

  # If host is not provided we get it from the Url
  $computed_host = $host ? {
    ''      => url_parse($url,host),
    default => $host,
  }

  # Manage template
  $real_template = $template ? {
    ''      => undef,
    default => $template,
  }

  # Needed to create flag todo files seamlessly
  $urlq = regsubst($url , '/' , '-' , 'G')

  if ($tool =~ /munin/) {
  }

  if ($tool =~ /collectd/) {
  }

  if ($tool =~ /monit/) {
  }

  $local_check_command = $username ? { # CHECK VIA NRPE STILL DOESN'T WORK WITH & and ? in URLS!
    undef   => "check_nrpe!check_url!${computed_target}!${port}!${url}!${pattern}!${useragent}!${computed_host}" ,
    ''      => "check_nrpe!check_url!${computed_target}!${port}!${url}!${pattern}!${useragent}!${computed_host}" ,
    default => "check_nrpe!check_url_auth!${computed_target}!${port}!${url}!${pattern}!${username}:${password}!${useragent}!${computed_host}" ,
  }

  $default_check_command = $username ? {
    undef   => "check_url!${computed_target}!${port}!${url}!${pattern}!${useragent}" ,
    ''      => "check_url!${computed_target}!${port}!${url}!${pattern}!${useragent}" ,
    default => "check_url_auth!${computed_target}!${port}!${url}!${pattern}!${username}:${password}!${useragent}" ,
  }

  $check_command = $checksource ? {
    local   => $local_check_command,
    default => $default_check_command
  }

  if ($tool =~ /nagios/) {
    # Use for Example42 service checks
    # (note: are used custom Nagios and nrpe commands)
    nagios::service { $name:
      ensure        => $ensure,
      template      => $real_template,
      check_command => $check_command,
    }
  }

  if ($tool =~ /icinga/) {
    icinga::service { $name:
      ensure        => $ensure,
      template      => $real_template,
      check_command => $check_command,
    }
  }

  $puppi_hostwide = $monitorgroup ? {
    undef   => 'yes' ,
    ''      => 'yes' ,
    default => 'no' ,
  }

  $puppi_command = $username ? {
    undef   => "check_http -I '${computed_target}' -p '${port}' -u '${url}' -H '${computed_host}' -r '${pattern}' -A '${useragent}'" ,
    ''      => "check_http -I '${computed_target}' -p '${port}' -u '${url}' -H '${computed_host}' -r '${pattern}' -A '${useragent}'" ,
    default => "check_http -I '${computed_target}' -p '${port}' -u '${url}' -H '${computed_host}' -r '${pattern}' -a ${username}:${password} -A '${useragent}'" ,
  }

  if ($tool =~ /puppi/) {
    # Use for Example42 puppi checks
    puppi::check { $name:
      enable   => $enable,
      hostwide => $puppi_hostwide,
      project  => $monitorgroup ,
      command  => $puppi_command,
    }
  }
}