From bccb10031c7ad120bbdd939067a0af3097c57d84 Mon Sep 17 00:00:00 2001 From: Guillaume Thouvenin Date: Tue, 13 Sep 2016 10:06:33 +0200 Subject: [PATCH] Modify the cron job to use specific version of the plugin This patch modifies the cron job used to update the nagios configuration to solve a bug that occurs when several version of the plugin are available. This happens after an upgrade procedure. Change-Id: I41831e43707e7ca5e88fd0a329508ad4813d26bb Closes-Bug: #1622628 --- deployment_scripts/puppet/manifests/nagios.pp | 2 ++ .../files/update-lma-configuration | 15 ++++++++++++++- .../lma_infra_alerting/manifests/nagios.pp | 3 ++- .../classes/lma_infra_alerting_nagios_spec.rb | 6 ++++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/deployment_scripts/puppet/manifests/nagios.pp b/deployment_scripts/puppet/manifests/nagios.pp index bba2b90..4e99388 100644 --- a/deployment_scripts/puppet/manifests/nagios.pp +++ b/deployment_scripts/puppet/manifests/nagios.pp @@ -19,6 +19,7 @@ $env_id = hiera('deployment_id') $fuel_version = 0 + hiera('fuel_version') $plugin = hiera('lma_infrastructure_alerting') +$plugin_version = $plugin['metadata']['plugin_version'] $nagios_authnz = hiera('lma::infrastructure_alerting::authnz') $password = $nagios_authnz['password'] if $notify_warning == false and @@ -92,6 +93,7 @@ class { 'lma_infra_alerting::nagios': ldap_authorization_enabled => $nagios_authnz['ldap_authorization_enabled'], ldap_group_attribute => $nagios_authnz['ldap_group_attribute'], ldap_admin_group_dn => $nagios_authnz['ldap_admin_group_dn'], + plugin_version => $plugin_version, notify => Service['apache2-nagios'], } diff --git a/deployment_scripts/puppet/modules/lma_infra_alerting/files/update-lma-configuration b/deployment_scripts/puppet/modules/lma_infra_alerting/files/update-lma-configuration index 264392e..ec1b370 100755 --- a/deployment_scripts/puppet/modules/lma_infra_alerting/files/update-lma-configuration +++ b/deployment_scripts/puppet/modules/lma_infra_alerting/files/update-lma-configuration @@ -1,13 +1,26 @@ #!/bin/bash +if [ -z "$1" ]; then + echo "The name of the plugin is empty" + exit 1 +fi + +if [ -z "$2" ]; then + echo "The version of the plugin is empty" + exit 1 +fi + PLUGIN_NAME=$1 +PLUGIN_VERSION=$2 +PLUGIN_MAJOR=$(echo "$PLUGIN_VERSION" | cut -d. -f1) +PLUGIN_MINOR=$(echo "$PLUGIN_VERSION" | cut -d. -f2) MANIFEST=nagios.pp CONFIG_DIR=/etc/nagios3/conf.d PREFIX_FILENAMES=lma_ EXTENSION_FILENAMES=.cfg PUPPET=$(which puppet) -PLUGIN_PUPPET_DIR=$(ls -d /etc/fuel/plugins/"$PLUGIN_NAME"*/puppet) +PLUGIN_PUPPET_DIR=$(ls -d /etc/fuel/plugins/"$PLUGIN_NAME-$PLUGIN_MAJOR.$PLUGIN_MINOR"/puppet) LAST_CHECK=/var/cache/lma_last_astute_yaml.md5sum LAST_CHECK_NODES=/var/cache/lma_last_nodes_yaml.md5sum CURRENT_CHECK=/var/cache/lma_current_astute_yaml.md5sum diff --git a/deployment_scripts/puppet/modules/lma_infra_alerting/manifests/nagios.pp b/deployment_scripts/puppet/modules/lma_infra_alerting/manifests/nagios.pp index 637251a..c1d97c9 100644 --- a/deployment_scripts/puppet/modules/lma_infra_alerting/manifests/nagios.pp +++ b/deployment_scripts/puppet/modules/lma_infra_alerting/manifests/nagios.pp @@ -40,6 +40,7 @@ class lma_infra_alerting::nagios ( $ldap_group_attribute = undef, $ldap_admin_group_dn = undef, $httpd_dir = '/etc/apache2', + $plugin_version = undef, ) inherits lma_infra_alerting::params { include nagios::params @@ -104,7 +105,7 @@ class lma_infra_alerting::nagios ( $prefix = $lma_infra_alerting::params::nagios_config_filename_prefix cron { 'update lma infra alerting': ensure => present, - command => "/usr/bin/flock -n /tmp/lma.lock -c \"${cron_bin} lma_infrastructure_alerting\"", + command => "/usr/bin/flock -n /tmp/lma.lock -c \"${cron_bin} lma_infrastructure_alerting ${plugin_version}\"", minute => '*', hour => '*', month => '*', diff --git a/deployment_scripts/puppet/modules/lma_infra_alerting/spec/classes/lma_infra_alerting_nagios_spec.rb b/deployment_scripts/puppet/modules/lma_infra_alerting/spec/classes/lma_infra_alerting_nagios_spec.rb index 3589814..5bcdcfe 100644 --- a/deployment_scripts/puppet/modules/lma_infra_alerting/spec/classes/lma_infra_alerting_nagios_spec.rb +++ b/deployment_scripts/puppet/modules/lma_infra_alerting/spec/classes/lma_infra_alerting_nagios_spec.rb @@ -24,12 +24,14 @@ describe 'lma_infra_alerting::nagios' do let(:params) do {:http_password => 'foo', :http_port => '999', :nagios_ui_address => '1.1.1.1', - :nagios_address => '2.3.3.3' + :nagios_address => '2.3.3.3', + :plugin_version => '1.2.3', } end it { should contain_class('nagios') } it { should create_class('nagios::cgi') } - it { should create_cron('update lma infra alerting') } + it { should create_cron('update lma infra alerting'). + with_command("/usr/bin/flock -n /tmp/lma.lock -c \"/usr/local/bin/update-lma-configuration lma_infrastructure_alerting 1.2.3\"") } it { should create_file('/usr/local/bin/update-lma-configuration') } end end