summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Burdis <keith@burdis.org>2013-02-07 12:43:50 +0000
committerKeith Burdis <keith@burdis.org>2013-02-07 12:43:50 +0000
commit6405936dae74ed336f1421a27c7c22abf6d02d9e (patch)
tree3b37c068b7814c628e77313f2cae07a9ae56322a
parenteb88e7dfeef1939130394671568fba189f752c7e (diff)
Initial Nagios server-side installation and setup.
-rw-r--r--Modulefile1
-rw-r--r--manifests/agent.pp8
-rw-r--r--manifests/config.pp31
-rw-r--r--manifests/init.pp23
-rw-r--r--manifests/install.pp73
-rw-r--r--manifests/service.pp18
-rw-r--r--templates/main.mk.erb4
-rw-r--r--templates/setup.conf.erb29
8 files changed, 184 insertions, 3 deletions
diff --git a/Modulefile b/Modulefile
index 4ba5cca..dd16c28 100644
--- a/Modulefile
+++ b/Modulefile
@@ -6,3 +6,4 @@ license 'Apache License, Version 2.0'
summary 'install and configure check_mk'
description 'Install and configure check_mk agent and Nagios plugin'
project_page 'https://github.com/erwbgy/puppet-check_mk'
+dependency 'puppetlabs/stdlib', '>= 2.6.0'
diff --git a/manifests/agent.pp b/manifests/agent.pp
index f5262bf..ab71466 100644
--- a/manifests/agent.pp
+++ b/manifests/agent.pp
@@ -61,8 +61,10 @@ class check_mk::agent (
require => Package['check_mk-agent','check_mk-agent-logwatch'],
notify => Service['xinetd'],
}
- service { 'xinetd':
- ensure => 'running',
- enable => true,
+ if ! defined(Service['xinetd']) {
+ service { 'xinetd':
+ ensure => 'running',
+ enable => true,
+ }
}
}
diff --git a/manifests/config.pp b/manifests/config.pp
new file mode 100644
index 0000000..0e0b740
--- /dev/null
+++ b/manifests/config.pp
@@ -0,0 +1,31 @@
+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'],
+ }
+ 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'],
+ }
+ file { '/etc/check_mk/main.mk':
+ ensure => present,
+ content => "all_hosts = [ 'lnxmgt-01.sbetenv.ads' ]",
+ notify => Exec['check_mk-restart'],
+ }
+ exec { 'check_mk-restart':
+ command => '/usr/bin/check_mk -O',
+ refreshonly => true,
+ }
+ # TODO:
+ # /etc/check_mk/main.mk
+ # all_hosts = [
+ # 'lnxmgt-01.sbetenv.ads',
+ # 'lnxmgt-02.sbetenv.ads',
+ # ]
+ # # cmk -I
+ # # check_mk -O
+}
diff --git a/manifests/init.pp b/manifests/init.pp
new file mode 100644
index 0000000..491571e
--- /dev/null
+++ b/manifests/init.pp
@@ -0,0 +1,23 @@
+class check_mk (
+ $version,
+ $filestore = 'puppet:///files/check_mk',
+ $workspace = '/root/check_mk',
+) {
+ if ! defined(File[$workspace]) {
+ file { $workspace:
+ ensure => directory,
+ }
+ }
+ class { 'check_mk::install':
+ filestore => $filestore,
+ version => $version,
+ workspace => $workspace,
+ require => File[$workspace],
+ }
+ class { 'check_mk::config':
+ require => Class['check_mk::install'],
+ }
+ class { 'check_mk::service':
+ require => Class['check_mk::config'],
+ }
+}
diff --git a/manifests/install.pp b/manifests/install.pp
new file mode 100644
index 0000000..95196b5
--- /dev/null
+++ b/manifests/install.pp
@@ -0,0 +1,73 @@
+class check_mk::install (
+ $filestore,
+ $version,
+ $workspace,
+) {
+ package { 'nagios':
+ ensure => present,
+ notify => Exec['set-nagiosadmin-password', 'add-apache-to-nagios-group'],
+ }
+ exec { 'set-nagiosadmin-password':
+ command => '/usr/bin/htpasswd -bc /etc/nagios/passwd nagiosadmin letmein',
+ refreshonly => true,
+ }
+ 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'],
+ }
+}
diff --git a/manifests/service.pp b/manifests/service.pp
new file mode 100644
index 0000000..3d55df8
--- /dev/null
+++ b/manifests/service.pp
@@ -0,0 +1,18 @@
+class check_mk::service {
+ if ! defined(Service[httpd]) {
+ service { 'httpd':
+ ensure => 'running',
+ enable => true,
+ }
+ }
+ if ! defined(Service[xinetd]) {
+ service { 'xinetd':
+ ensure => 'running',
+ enable => true,
+ }
+ }
+ service { 'nagios':
+ ensure => 'running',
+ enable => true,
+ }
+}
diff --git a/templates/main.mk.erb b/templates/main.mk.erb
new file mode 100644
index 0000000..e1fbe81
--- /dev/null
+++ b/templates/main.mk.erb
@@ -0,0 +1,4 @@
+all_hosts = [
+ 'lnxmgt-01.sbetenv.ads',
+ 'lnxmgt-02.sbetenv.ads',
+]
diff --git a/templates/setup.conf.erb b/templates/setup.conf.erb
new file mode 100644
index 0000000..41e1143
--- /dev/null
+++ b/templates/setup.conf.erb
@@ -0,0 +1,29 @@
+
+bindir='/usr/bin'
+confdir='/etc/check_mk'
+sharedir='/usr/share/check_mk'
+docdir='/usr/share/doc/check_mk'
+checkmandir='/usr/share/doc/check_mk/checks'
+vardir='/var/lib/check_mk'
+agentslibdir='/usr/lib/check_mk_agent'
+agentsconfdir='/etc/check_mk'
+nagiosuser='nagios'
+wwwuser='apache'
+wwwgroup='nagios'
+nagios_binary='/usr/sbin/nagios'
+nagios_config_file='/etc/nagios/nagios.cfg'
+nagconfdir='/etc/nagios/check_mk'
+nagios_startscript='/etc/init.d/nagios'
+nagpipe='/var/spool/nagios/cmd/nagios.cmd'
+check_result_path='/var/log/nagios/spool/checkresults'
+nagios_status_file='/var/log/nagios/status.dat'
+check_icmp_path='/usr/lib64/nagios/plugins/check_icmp'
+url_prefix='/'
+apache_config_dir='/etc/httpd/conf.d'
+htpasswd_file='/etc/nagios/passwd'
+nagios_auth_name='Nagios Access'
+pnptemplates='/usr/share/nagios/html/pnp4nagios/templates'
+enable_livestatus='yes'
+libdir='/usr/lib/check_mk'
+livesock='/var/spool/nagios/cmd/live'
+livebackendsdir='/usr/share/check_mk/livestatus'