diff options
author | Keith Burdis <keith@burdis.org> | 2013-02-08 14:24:09 +0000 |
---|---|---|
committer | Keith Burdis <keith@burdis.org> | 2013-02-08 14:24:09 +0000 |
commit | 8d8887c4ee333b620bdfb0a4c5888efb88f48493 (patch) | |
tree | 4e099d4f6933980ffd8e4c69cfd4ba60c2e9856a | |
parent | e2dbf51aaae246e3b8e5d07c01cacac2ed4477ee (diff) |
* Switched to using OMD rather than manually compiling check_mk
* Added support for host tags and creating host groups based on these tags
* Allow local check_mk configuration to be specified in
/etc/check_mk/main.mk.local that is appended to /etc/check_mk/main.mk as
check_mk can do a lot more than is covered by this module
-rw-r--r-- | Changelog | 17 | ||||
-rw-r--r-- | Modulefile | 2 | ||||
-rw-r--r-- | README.md | 50 | ||||
-rw-r--r-- | manifests/config.pp | 78 | ||||
-rw-r--r-- | manifests/host.pp | 18 | ||||
-rw-r--r-- | manifests/hostgroup.pp | 18 | ||||
-rw-r--r-- | manifests/init.pp | 14 | ||||
-rw-r--r-- | manifests/install.pp | 105 | ||||
-rw-r--r-- | manifests/install_tarball.pp | 91 | ||||
-rw-r--r-- | manifests/service.pp | 2 |
10 files changed, 266 insertions, 129 deletions
diff --git a/Changelog b/Changelog new file mode 100644 index 0000000..07780ee --- /dev/null +++ b/Changelog @@ -0,0 +1,17 @@ +0.2.0: + +* Switched to using OMD rather than manually compiling check_mk + +* Added support for host tags and creating host groups based on these tags + +* Allow local check_mk configuration to be specified in +/etc/check_mk/main.mk.local that is appended to /etc/check_mk/main.mk as +check_mk can do a lot more than is covered by this module + +0.1.1: + +* Brown paper bag release to fix a silly typo + +0.1: + +* Initial release @@ -1,5 +1,5 @@ name 'erwbgy-check_mk' -version '0.1.1' +version '0.2.0' source 'https://github.com/erwbgy/puppet-check_mk.git' author 'erwbgy' license 'Apache License, Version 2.0' @@ -1,38 +1,56 @@ # check_mk -Puppet module for installing and configuring a Nagios server with check_mk and -check_mk agents. Agent hostnames are automatically added to the server -all_hosts configuration using stored configs. +Puppet module for: + +* Installing and configuring the Open Monitoring Distribution (OMD) which + includes Nagios, check_mk and lots of other tools + +* Installing check_mk agents. + +Agent hostnames are automatically added to the server all_hosts configuration +using stored configs. Currently only tested on Redhat-like systems. ## Server -* Installs nagios packages from EPEL. - -* Unpacks the check_mk tarball and runs the setup script - this requires -installing the g++ compiler and related tools so if this is an issue then use -the OMD distribution instead (which you should probably use anyway for any -important setup). +* Installs omd package either using the system repository (eg. yum, apt) or + from a package file retrieved from the Puppet file store * Populates the all_hosts array in /etc/check_mk/main.mk with hostnames exported by check::agent classes on agent hosts -### Example +### Example 1 + + include check_mk + +Installs the 'omd' package from the system repository. The default 'omd' site is used. + +### Example 2 class { 'check_mk': - version => '1.2.0p3' + filestore => 'puppet:///files/check_mk', + package => 'omd-0.56-rh60-29.x86_64.rpm' } +Installs the specified 'omd' package after retrieving it from the Puppet file store. + +### Example 3 + + class { 'check_mk': + site => 'acme', + } + +Installs the 'omd' package from the system repository. A site called 'acme' is +used making the URL http://hostname/acme/check_mk/ + ### check_mk parameters -*version*: The version in the check_mk tarball - for example if the tarball is -'check_mk-1.2.0p3.tar.gz' then the version is '1.2.0p3'. REQUIRED. +*package*: The omd package (rpm or deb) to install. Optional. -*filestore*: The location of the tarball. Default: 'puppet:///files/check_mk' +*filestore*: The Puppet file store location where the package can be found (eg. 'puppet:///files/check_mk'). Optional. -*workspace*: The directory to use to store files used during installation. -Default: '/root/check_mk' +*workspace*: The directory to use to store files used during installation. Default: '/root/check_mk' ## Agent diff --git a/manifests/config.pp b/manifests/config.pp index 14dc873..c25fd1a 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,46 +1,86 @@ -class check_mk::config { - file_line { 'nagios-remove-localhost': - ensure => absent, - line => 'cfg_file=/etc/nagios/objects/localhost.cfg', - path => '/etc/nagios/nagios.cfg', - notify => Class['check_mk::service'], +class check_mk::config ( + site, + host_groups = undef, +) { + $etc_dir = "/omd/sites/${site}/etc" + $bin_dir = "/omd/sites/${site}/bin" + exec { 'omd-create-site': + command => "/usr/bin/omd create ${site}", + creates => $etc_dir, + } + file { "${etc_dir}/nagios/local": + ensure => directory, } file_line { 'nagios-add-check_mk-cfg_dir': - ensure => present, - line => 'cfg_dir=/etc/nagios/check_mk', - path => '/etc/nagios/nagios.cfg', - notify => Class['check_mk::service'], + ensure => present, + line => "cfg_dir=${etc_dir}/nagios/local", + path => "${etc_dir}/nagios/nagios.cfg", + require => File["${etc_dir}/nagios/local"], + notify => Class['check_mk::service'], } file_line { 'add-guest-users': ensure => present, line => 'guest_users = [ "guest" ]', - path => '/etc/check_mk/multisite.mk', + path => "${etc_dir}/check_mk/multisite.mk", notify => Class['check_mk::service'], } - concat { '/etc/check_mk/main.mk': + concat { "${etc_dir}/check_mk/main.mk": owner => 'root', group => 'root', mode => '0644', notify => Exec['check_mk-refresh'], } + # all_hosts concat::fragment { 'all_hosts-header': - target => '/etc/check_mk/main.mk', + target => "${etc_dir}/check_mk/main.mk", content => "all_hosts = [\n", - order => 01, + order => 10, } concat::fragment { 'all_hosts-footer': - target => '/etc/check_mk/main.mk', + target => "${etc_dir}/check_mk/main.mk", content => "]\n", - order => 03, + order => 19, + } + Check_mk::Host <<| |>> { + target => "${etc_dir}/check_mk/main.mk", + notify => Exec['check_mk-refresh'] + } + # host_groups + if $host_groups { + file { "${etc_dir}/nagios/local/hostgroups": + ensure => directory, + } + concat::fragment { 'host_groups-header': + target => "${etc_dir}/check_mk/main.mk", + content => "host_groups = [\n", + order => 20, + } + concat::fragment { 'host_groups-footer': + target => "${etc_dir}/check_mk/main.mk", + content => "]\n", + order => 29, + } + check_mk::hostgroup { keys($host_groups): + dir => "${etc_dir}/nagios/local/hostgroups", + host_groups => $host_groups, + target => "${etc_dir}/check_mk/main.mk", + notify => Exec['check_mk-refresh'] + } + } + # local config is in /omd/sites/${site}/etc/check_mk/main.mk.local and is appended + concat::fragment { 'check_mk-local-config': + target => "${etc_dir}/check_mk/main.mk", + ensure => "${etc_dir}/check_mk/main.mk.local", + order => 99, } - Check_mk::Host <<| |>> { notify => Exec['check_mk-refresh'] } + # re-read config exec { 'check_mk-refresh': - command => '/usr/bin/check_mk -I', + command => "${bin_dir}/check_mk -I", refreshonly => true, notify => Exec['check_mk-reload'], } exec { 'check_mk-reload': - command => '/usr/bin/check_mk -O', + command => "${bin_dir}/check_mk -O", refreshonly => true, } } diff --git a/manifests/host.pp b/manifests/host.pp index 5c83b96..87687a4 100644 --- a/manifests/host.pp +++ b/manifests/host.pp @@ -1,8 +1,18 @@ -define check_mk::host { +define check_mk::host ( + $target, + $host_tags = [], +) { $host = $title + if size($host_tags) > 0 + $_tags = join($host_tags,'|') + $entry = "${host}|${_tags}" + } + else { + $entry = $host + } concat::fragment { "check_mk-${host}": - target => '/etc/check_mk/main.mk', - content => " '${host}',\n", - order => 02, + target => $target, + content => " '${entry}',\n", + order => 11, } } diff --git a/manifests/hostgroup.pp b/manifests/hostgroup.pp new file mode 100644 index 0000000..756ef50 --- /dev/null +++ b/manifests/hostgroup.pp @@ -0,0 +1,18 @@ +define check_mk::hostgroup ( + $dir, + $hostgroups, + $target, +) { + $group = $title + $group_tags = join($hostgroups[$group], ',') + concat::fragment { "check_mk-hostgroup-${host}": + target => $target, + content => " ( '${group}', [ ${group_tags} ], ALL_HOSTS ),\n", + order => 21, + } + file { "${dir}/${group}.cfg": + ensure => present, + content => "define hostgroup {\n hostgroup_name ${group}\n}\n", + require => File[$dir], + } +} diff --git a/manifests/init.pp b/manifests/init.pp index 491571e..31d9fd7 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,20 +1,16 @@ class check_mk ( - $version, - $filestore = 'puppet:///files/check_mk', + $filestore = undef, + $package = 'omd', + $site = 'omd', $workspace = '/root/check_mk', ) { - if ! defined(File[$workspace]) { - file { $workspace: - ensure => directory, - } - } class { 'check_mk::install': filestore => $filestore, - version => $version, + package => $package, workspace => $workspace, - require => File[$workspace], } class { 'check_mk::config': + site => $site, require => Class['check_mk::install'], } class { 'check_mk::service': diff --git a/manifests/install.pp b/manifests/install.pp index 2762165..28c645f 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -1,85 +1,32 @@ class check_mk::install ( $filestore, - $version, + $package, $workspace, ) { - package { 'nagios': - ensure => present, - notify => Exec['set-nagiosadmin-password', 'set-guest-password', 'add-apache-to-nagios-group'], - } - file { '/etc/nagios/passwd': - ensure => present, - owner => 'root', - group => 'apache', - mode => '0640', - } - exec { 'set-nagiosadmin-password': - command => '/usr/bin/htpasswd -b /etc/nagios/passwd nagiosadmin letmein', - refreshonly => true, - require => File['/etc/nagios/passwd'], - } - exec { 'set-guest-password': - command => '/usr/bin/htpasswd -b /etc/nagios/passwd guest guest', - refreshonly => true, - require => File['/etc/nagios/passwd'], - } - exec { 'add-apache-to-nagios-group': - command => '/usr/sbin/usermod -a -G nagios apache', - refreshonly => true, - } - package { 'nagios-plugins-all': - ensure => present, - require => Package['nagios'], - } - package { [ 'xinetd', 'mod_python', 'make', 'gcc-c++', 'tar', 'gzip' ]: - ensure => present, - } - file { "${workspace}/check_mk-${version}.tar.gz": - ensure => present, - source => "${filestore}/check_mk-${version}.tar.gz", - } - exec { 'unpack-check_mk-tarball': - command => "/bin/tar -zxf ${workspace}/check_mk-${version}.tar.gz", - cwd => $workspace, - creates => "${workspace}/check_mk-${version}", - require => File["${workspace}/check_mk-${version}.tar.gz"], - } - exec { 'change-setup-config-location': - command => "/usr/bin/perl -pi -e 's#^SETUPCONF=.*?$#SETUPCONF=${workspace}/check_mk_setup.conf#' ${workspace}/check_mk-${version}/setup.sh", - unless => "/bin/egrep '^SETUPCONF=${workspace}/check_mk_setup.conf$' ${workspace}/check_mk-${version}/setup.sh", - require => Exec['unpack-check_mk-tarball'], - } - # Avoid header like 'Written by setup of check_mk 1.2.0p3 at Thu Feb 7 12:26:17 GMT 2013' - # that changes every time the setup script is run - exec { 'remove-setup-header': - command => "/usr/bin/perl -pi -e 's#^DIRINFO=.*?$#DIRINFO=#' ${workspace}/check_mk-${version}/setup.sh", - unless => "/bin/egrep '^DIRINFO=$' ${workspace}/check_mk-${version}/setup.sh", - require => Exec['unpack-check_mk-tarball'], - } - file { "${workspace}/check_mk_setup.conf": - ensure => present, - content => template('check_mk/setup.conf.erb'), - notify => Exec['check_mk-setup'], - } - file { '/etc/nagios/check_mk': - ensure => directory, - owner => 'nagios', - group => 'nagios', - recurse => true, - require => Package['nagios'], - } - exec { 'check_mk-setup': - command => "${workspace}/check_mk-${version}/setup.sh --yes", - cwd => "${workspace}/check_mk-${version}", - refreshonly => true, - require => [ - Exec['change-setup-config-location'], - Exec['remove-setup-header'], - Exec['unpack-check_mk-tarball'], - File["${workspace}/check_mk_setup.conf"], - File['/etc/nagios/check_mk'], - Package['nagios'], - ], - notify => Class['check_mk::service'], + if $filestore { + if ! defined(File[$workspace]) { + file { $workspace: + ensure => directory, + } + } + file { "${workspace}/${package}": + ensure => present, + source => "${filestore}/${package}", + require => File[$workspace], + } + if $package =~ /^omd-(.*?)\.(rpm|deb)$/ { + $type = $1 + package { 'omd': + ensure => installed, + provider => $type, + source => "${workspace}/${package_file}", + require => File["${workspace}/${package}"], + } + } + } + else { + package { $package: + ensure => installed, + } } } diff --git a/manifests/install_tarball.pp b/manifests/install_tarball.pp new file mode 100644 index 0000000..4a0af23 --- /dev/null +++ b/manifests/install_tarball.pp @@ -0,0 +1,91 @@ +class check_mk::install_tarball ( + $filestore, + $version, + $workspace, +) { + package { 'nagios': + ensure => present, + notify => Exec['set-nagiosadmin-password', 'set-guest-password', 'add-apache-to-nagios-group'], + } + file { '/etc/nagios/passwd': + ensure => present, + owner => 'root', + group => 'apache', + mode => '0640', + } + exec { 'set-nagiosadmin-password': + command => '/usr/bin/htpasswd -b /etc/nagios/passwd nagiosadmin letmein', + refreshonly => true, + require => File['/etc/nagios/passwd'], + } + exec { 'set-guest-password': + command => '/usr/bin/htpasswd -b /etc/nagios/passwd guest guest', + refreshonly => true, + require => File['/etc/nagios/passwd'], + } + exec { 'add-apache-to-nagios-group': + command => '/usr/sbin/usermod -a -G nagios apache', + refreshonly => true, + } + package { 'nagios-plugins-all': + ensure => present, + require => Package['nagios'], + } + package { [ 'xinetd', 'mod_python', 'make', 'gcc-c++', 'tar', 'gzip' ]: + ensure => present, + } + file { "${workspace}/check_mk-${version}.tar.gz": + ensure => present, + source => "${filestore}/check_mk-${version}.tar.gz", + } + exec { 'unpack-check_mk-tarball': + command => "/bin/tar -zxf ${workspace}/check_mk-${version}.tar.gz", + cwd => $workspace, + creates => "${workspace}/check_mk-${version}", + require => File["${workspace}/check_mk-${version}.tar.gz"], + } + exec { 'change-setup-config-location': + command => "/usr/bin/perl -pi -e 's#^SETUPCONF=.*?$#SETUPCONF=${workspace}/check_mk_setup.conf#' ${workspace}/check_mk-${version}/setup.sh", + unless => "/bin/egrep '^SETUPCONF=${workspace}/check_mk_setup.conf$' ${workspace}/check_mk-${version}/setup.sh", + require => Exec['unpack-check_mk-tarball'], + } + # Avoid header like 'Written by setup of check_mk 1.2.0p3 at Thu Feb 7 12:26:17 GMT 2013' + # that changes every time the setup script is run + exec { 'remove-setup-header': + command => "/usr/bin/perl -pi -e 's#^DIRINFO=.*?$#DIRINFO=#' ${workspace}/check_mk-${version}/setup.sh", + unless => "/bin/egrep '^DIRINFO=$' ${workspace}/check_mk-${version}/setup.sh", + require => Exec['unpack-check_mk-tarball'], + } + file { "${workspace}/check_mk_setup.conf": + ensure => present, + content => template('check_mk/setup.conf.erb'), + notify => Exec['check_mk-setup'], + } + file { '/etc/nagios/check_mk': + ensure => directory, + owner => 'nagios', + group => 'nagios', + recurse => true, + require => Package['nagios'], + } + file { '/etc/nagios/check_mk/hostgroups': + ensure => directory, + owner => 'nagios', + group => 'nagios', + require => File['/etc/nagios/check_mk'], + } + exec { 'check_mk-setup': + command => "${workspace}/check_mk-${version}/setup.sh --yes", + cwd => "${workspace}/check_mk-${version}", + refreshonly => true, + require => [ + Exec['change-setup-config-location'], + Exec['remove-setup-header'], + Exec['unpack-check_mk-tarball'], + File["${workspace}/check_mk_setup.conf"], + File['/etc/nagios/check_mk'], + Package['nagios'], + ], + notify => Class['check_mk::service'], + } +} diff --git a/manifests/service.pp b/manifests/service.pp index 3d55df8..4b31df9 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -11,7 +11,7 @@ class check_mk::service { enable => true, } } - service { 'nagios': + service { 'omd': ensure => 'running', enable => true, } |