Defined Type: omd::site

Defined in:
manifests/site.pp

Overview

Define: omd::site

This define creates a OMD site.

As default alls hosts exported for this site are collected ($config_hosts) for the ‘collected_hosts’ folder ($collected_hosts_folders).

Parameters

ensure

Site present or absent. defaults to present

uid

UID of site user ‘$name’ defaults to undef

gid

GID of site group ‘$name’ defaults to _unde

service_ensure

State of the site /stopped. defaults to running

service_reload

Site reload or restart on trigger. defaults to false

options

Site configuration hash, e.g. { ‘DEFAULT_GUI’ => ‘check_mk’ , … } defaults to undef

config_hosts

Collect and configure exported hosts for this site. defaults to true

config_hosts_folders

Folders in check_mk where to store and automatically collected hosts to. defaults to __

main_mk_content

Pass arbitrary content for the Check_mk main.mk config file. defaults to undef

Examples

omd::site { ‘default’:

config_hosts_folders => ['myhosts', 'myotherhosts']

}

or

omd::site { ‘default’:

config_hosts_folders => {
  'myhosts' => {
    'cluster' => true,
    'clutser_tags' => ['tag1', 'tag2'],
  }
}

}

Authors

Frederik Wagner <wagner@wagit.de>

Copyright 2014 Frederik Wagner

Parameters:

  • ensure (Any) (defaults to: 'present')
  • uid (Any) (defaults to: undef)
  • gid (Any) (defaults to: undef)
  • service_ensure (Any) (defaults to: 'running')
  • service_reload (Any) (defaults to: false)
  • options (Any) (defaults to: undef)
  • config_hosts (Any) (defaults to: true)
  • config_hosts_folders (Any) (defaults to: ['collected_hosts'])
  • main_mk_content (Any) (defaults to: undef)


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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'manifests/site.pp', line 72

define omd::site  (
  $ensure               = 'present',
  $uid                  = undef,
  $gid                  = undef,
  $service_ensure       = 'running',
  $service_reload       = false,
  $options              = undef,
  $config_hosts         = true,
  $config_hosts_folders = ['collected_hosts'],
  $main_mk_content      = undef,
) {
  validate_re($name, '^\w+$')
  validate_re($ensure, '^present|absent$')
  if $uid {
    validate_re($uid, '\d+')
    $_uid = "--uid ${uid} "
  }
  if $gid {
    validate_re($gid, '\d+')
    $_gid = "--gid ${gid} "
  }
  # $service_* validation in omd::service
  # $options validation in omd::config
  validate_bool($config_hosts)

  # cannot require omd::server -> creates cyclic dependency
  include omd::server
  require omd::server::install

  Exec {
    path => ['/bin', '/usr/bin']
  }

  # generic to trigger
  exec { "check_mk update site: ${name}":
    command     => "su - ${name} -c 'check_mk -O'",
    refreshonly => true,
  }

  if $ensure == 'present' {

    exec { "create omd site: ${name}":
      command => "omd create ${_uid}${_gid}${name}",
      unless  => "omd sites -b | grep -q '\\<${name}\\>'",
    }

    omd::site::service { $name:
      ensure => $service_ensure,
      reload => $service_reload,
    }

    if $options {
      Exec["create omd site: ${name}"] ->
      omd::site::config { $name: options => $options } ~>
      Omd::Site::Service[$name]
    } else {
      Exec["create omd site: ${name}"] ~>
      Omd::Site::Service[$name]
    }

    if $config_hosts {

      if is_array($config_hosts_folders) {
        $config_hosts_array = prefix($config_hosts_folders, "${name} - ")

        omd::site::config_hosts { $config_hosts_array:
          require => Omd::Site::Service[$name],
          notify  => Exec["check_mk update site: ${name}"],
        }

      } elsif is_hash($config_hosts_folders) {

        $config_hosts_array = prefix(keys($config_hosts_folders), "${name} - ")

        omd::site::helper::config_hosts { $config_hosts_array:
          configs => $config_hosts_folders,
        }

      } else {
        fail('$config_hosts_folders must be either an Array or Hash')
      }
    }

    if $main_mk_content {
      validate_string($main_mk_content)

      file { "/omd/sites/${name}/etc/check_mk/main.mk":
        ensure  => present,
        owner   => $name,
        group   => $name,
        mode    => '0644',
        content => $main_mk_content,
        notify  => Exec["check_mk update site: ${name}"],
      }
    }

  } else {

    exec { "remove omd site: ${name}":
      command => "yes yes | omd rm --kill ${name}",
      onlyif  => "omd sites -b | grep -q '\\<${name}\\>'",
    }

  }

}