[Nagios] rework packstack nagios puppet generation

Packstack from now on should not put generated puppet code into hiera variable
and it won't restart httpd service with each run.

Change-Id: I9cbd7eac31f62ca0abca2800f82b9034b1aca84d
This commit is contained in:
Lukas Bezdicka
2015-06-05 11:12:58 -04:00
parent d1211af056
commit 06b9806822
3 changed files with 96 additions and 115 deletions

View File

@@ -71,119 +71,26 @@ def initSequences(controller):
controller.addSequence("Installing Nagios", [], [], nagiossteps)
# ------------------------- helper functions -------------------------
def _serviceentry(**kwargs):
s = 'define service {\n'
for key in sorted(kwargs.keys()):
s += "\t%s\t%s\n" % (key, kwargs[key])
s += "\t}\n"
return s
def _copy_script(**kwargs):
# TODO : Replace all these shell templates with with python
return ('file{"/usr/lib64/nagios/plugins/%(name)s":'
'mode => 755, owner => "nagios", '
'seltype => "nagios_unconfined_plugin_exec_t", '
'content => template("packstack/%(name)s.erb"),}\n'
'nagios_command {"%(name)s": '
'command_line => "/usr/lib64/nagios/plugins/%(name)s",}\n'
% kwargs)
def nagios_host(hostname, **kwargs):
out = ("nagios_host { '%s': " % hostname)
for key, value in kwargs.items():
out = "%s, %s => '%s'" % (out, key, value)
return "%s}\n" % out
# -------------------------- step functions --------------------------
def create_manifest(config, messages):
manifest_entries = ''
# I should be adding service entries with nagios_service
# but it appears to be broken http://projects.puppetlabs.com/issues/3420
service_entries = ''
for hostname in filtered_hosts(config):
manifest_entries += nagios_host(hostname, address=hostname,
use='linux-server')
service_entries += _serviceentry(
name='load5-%s' % hostname,
service_description='5 minute load average',
host_name=hostname,
check_command="check_nrpe!load5",
use="generic-service",
normal_check_interval='5'
)
service_entries += _serviceentry(
name='df_var-%s' % hostname,
service_description='Percent disk space used on /var',
host_name=hostname,
check_command="check_nrpe!df_var",
use="generic-service"
)
manifest_entries += _copy_script(name="keystone-user-list")
service_entries += _serviceentry(
name='keystone-user-list',
service_description='number of keystone users',
host_name=config['CONFIG_CONTROLLER_HOST'],
check_command="keystone-user-list",
use="generic-service",
normal_check_interval='5'
)
config['CONFIG_NAGIOS_NODES'] = list(filtered_hosts(config))
openstack_services = []
openstack_services.append('keystone-user-list')
if config['CONFIG_GLANCE_INSTALL'] == 'y':
manifest_entries += _copy_script(name="glance-index")
service_entries += _serviceentry(
name='glance-index',
service_description='number of glance images',
host_name=config['CONFIG_CONTROLLER_HOST'],
check_command="glance-index", use="generic-service",
normal_check_interval='5'
)
openstack_services.append('glance-index')
if config['CONFIG_NOVA_INSTALL'] == 'y':
manifest_entries += _copy_script(name="nova-list")
service_entries += _serviceentry(
name='nova-list',
service_description='number of nova vm instances',
host_name=config['CONFIG_CONTROLLER_HOST'],
check_command="nova-list", use="generic-service",
normal_check_interval='5'
)
openstack_services.append('nova-list')
if config['CONFIG_CINDER_INSTALL'] == 'y':
manifest_entries += _copy_script(name="cinder-list")
service_entries += _serviceentry(
name='cinder-list',
service_description='number of cinder volumes',
host_name=config['CONFIG_CONTROLLER_HOST'],
check_command="cinder-list", use="generic-service",
normal_check_interval='5'
)
openstack_services.append('cinder-list')
if config['CONFIG_SWIFT_INSTALL'] == 'y':
manifest_entries += _copy_script(name="swift-list")
service_entries += _serviceentry(
name='swift-list',
service_description='number of swift containers',
host_name=config['CONFIG_CONTROLLER_HOST'],
check_command="swift-list", use="generic-service",
normal_check_interval='5'
)
openstack_services.append('swift-list')
manifest_entries += ("file { '/etc/nagios/nagios_service.cfg': \n"
"ensure => present, mode => 644,\n"
"owner => 'nagios', group => 'nagios',\n"
"before => Service['nagios'],\n"
"content => '%s'}" % service_entries)
config['CONFIG_NAGIOS_MANIFEST_CONFIG'] = manifest_entries
config['CONFIG_NAGIOS_SERVICES'] = openstack_services
manifestfile = "%s_nagios.pp" % config['CONFIG_CONTROLLER_HOST']
manifestdata = getManifestTemplate("nagios_server")

View File

@@ -0,0 +1,72 @@
define packstack_nagios_host {
nagios_host { $name:
use => 'linux-server',
address => $name,
owner => 'nagios',
group => 'nagios',
mode => '0644',
}
}
define packstack_nagios_generic_services {
nagios_service { "load5-${name}":
check_command => 'check_nrpe!load5',
host_name => $name,
normal_check_interval => '5',
service_description => '5 minute load average',
use => 'generic-service',
owner => 'nagios',
group => 'nagios',
mode => '0644',
}
nagios_service { "df_var${name}":
check_command => 'check_nrpe!df_var',
host_name => $name,
service_description => 'Percent disk space used on /var',
use => 'generic-service',
owner => 'nagios',
group => 'nagios',
mode => '0644',
}
}
define packstack_nagios_services {
file { "/usr/lib64/nagios/plugins/${name}":
mode => 755,
owner => 'nagios',
seltype => 'nagios_unconfined_plugin_exec_t',
content => template("packstack/${name}.erb"),
}
nagios_command { $name:
command_line => "/usr/lib64/nagios/plugins/${name}",
owner => 'nagios',
group => 'nagios',
mode => '0644',
}
nagios_service { $name:
host_name => $packstack::nagios_configs::controller_host,
normal_check_interval => '5',
check_command => $name,
use => 'generic-service',
owner => 'nagios',
group => 'nagios',
mode => '0644',
}
}
class packstack::nagios_config_wrapper (
$nagios_hosts = [],
$nagios_openstack_services = [],
$controller_host,
) {
nagios_command { 'check_nrpe':
command_line => '/usr/lib64/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c $ARG1$',
owner => 'nagios',
group => 'nagios',
mode => '0644',
}
packstack_nagios_host { $nagios_hosts: }
packstack_nagios_generic_services { $nagios_hosts: }
packstack_nagios_services { $nagios_openstack_services: }
}

View File

@@ -12,7 +12,7 @@ exec { 'nagios-plugins-ping':
}
class nagios_configs(){
file { ['/etc/nagios/nagios_command.cfg', '/etc/nagios/nagios_host.cfg']:
file { ['/etc/nagios/nagios_command.cfg', '/etc/nagios/nagios_host.cfg', '/etc/nagios/nagios_service.cfg']:
ensure => file,
mode => '0644',
owner => 'nagios',
@@ -41,16 +41,6 @@ class nagios_configs(){
line => 'cfg_file=/etc/nagios/nagios_service.cfg',
}
nagios_command { 'check_nrpe':
command_line => '/usr/lib64/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c $ARG1$',
}
$cfg_nagios_pw = hiera('CONFIG_NAGIOS_PW')
exec { 'nagiospasswd':
command => "/usr/bin/htpasswd -b /etc/nagios/passwd nagiosadmin ${cfg_nagios_pw}",
}
$nagios_cfg_ks_adm_pw = hiera('CONFIG_KEYSTONE_ADMIN_PW')
$nagios_cfg_keystone_url = hiera('CONFIG_KEYSTONE_ADMIN_URL')
$keystone_admin_username = hiera('CONFIG_KEYSTONE_ADMIN_USERNAME')
@@ -65,19 +55,31 @@ export OS_PASSWORD=${nagios_cfg_ks_adm_pw}
export OS_AUTH_URL=${nagios_cfg_keystone_url}",
}
%(CONFIG_NAGIOS_MANIFEST_CONFIG)s
class { 'packstack::nagios_config_wrapper':
nagios_hosts => hiera('CONFIG_NAGIOS_NODES'),
nagios_openstack_services => hiera('CONFIG_NAGIOS_SERVICES'),
controller_host => hiera('CONFIG_CONTROLLER_HOST'),
require => Package['nagios'],
notify => Service['nagios'],
}
}
class { '::nagios_configs':
notify => [ Service['nagios'], Service['httpd']],
}
include ::concat::setup
class { '::apache':
purge_configs => false,
}
$cfg_nagios_pw = hiera('CONFIG_NAGIOS_PW')
exec { 'nagiospasswd':
command => "/usr/bin/htpasswd -b /etc/nagios/passwd nagiosadmin ${cfg_nagios_pw}",
require => Package['nagios'],
before => Service['nagios'],
}
class { '::apache::mod::php': }
service { ['nagios']: