From 7e96a620d921b4b9ded445fd5cfc102d095bb04e Mon Sep 17 00:00:00 2001 From: Andreas John Date: Wed, 2 Sep 2015 11:53:32 +0200 Subject: [PATCH 1/3] Made monit's PROGRAM STATUS TESTING work, made ACTION EXEC work, made exec path accept parameters. --- lib/puppet/parser/functions/monit_validate_tests.rb | 7 ++++++- manifests/check/program.pp | 2 -- templates/check/common.erb | 7 +++++-- templates/check/program.erb | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/puppet/parser/functions/monit_validate_tests.rb b/lib/puppet/parser/functions/monit_validate_tests.rb index 19f0724..d182c84 100644 --- a/lib/puppet/parser/functions/monit_validate_tests.rb +++ b/lib/puppet/parser/functions/monit_validate_tests.rb @@ -36,7 +36,7 @@ module Puppet::Parser::Functions ], 'HOST' => ['CONNECTION'], 'PROCESS' => RESOURCE_TESTS + ['CONNECTION',], - 'PROGRAM' => [], + 'PROGRAM' => ['STATUS'], 'SYSTEM' => RESOURCE_TESTS, } defined?(TEST_ACTIONS) or TEST_ACTIONS = ['ALERT', 'RESTART', 'START', 'STOP', 'EXEC', 'UNMONITOR'] @@ -108,6 +108,11 @@ module Puppet::Parser::Functions end test['condition'] = "FAILED #{test['type']} #{test['value']}" + # STATUS TESTING + elsif test['type'] == 'STATUS' + test['operator'] = test['operator'].upcase + test['condition'] = "#{test['type']} #{test['operator']} #{test['value']}" + # CONNECTION TESTING elsif test['type'] == 'CONNECTION' unless test.key? 'port' or test.key? 'unixsocket' diff --git a/manifests/check/program.pp b/manifests/check/program.pp index cb0bbae..4e498d8 100644 --- a/manifests/check/program.pp +++ b/manifests/check/program.pp @@ -19,8 +19,6 @@ $order = 0, ) { - validate_absolute_path($path) - monit::check::instance { "${name}_instance": ensure => $ensure, name => $name, diff --git a/templates/check/common.erb b/templates/check/common.erb index 745f371..767ae00 100644 --- a/templates/check/common.erb +++ b/templates/check/common.erb @@ -17,6 +17,9 @@ <%- if test.key? 'tolerance' -%> FOR <%= test['tolerance'] %> <%- end -%> - THEN <%= test['action'] %> -<%- end -%> + THEN <%= test['action'] -%> + <%- if test.key? 'exec' -%> + "<%= test['exec'] %>" + <%- end -%> +<%- end %> diff --git a/templates/check/program.erb b/templates/check/program.erb index 122bed1..90fb43e 100644 --- a/templates/check/program.erb +++ b/templates/check/program.erb @@ -1 +1 @@ -CHECK PROGRAM <%= @name %> WITH PATH <%= @path %> +CHECK PROGRAM <%= @name %> WITH PATH "<%= @path %>" From 5f222be654e9d4009c8f02e7b1f845a754bab43a Mon Sep 17 00:00:00 2001 From: Andreas John Date: Wed, 2 Sep 2015 17:14:56 +0200 Subject: [PATCH 2/3] Added Example for PROGRAM STATUS TESTING to README --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 95df93c..ba0bb97 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,18 @@ monit::checks : host: '127.0.0.1' port: '80' protocol: 'http' + custom-script: + type : 'program' + config : + path : "/path/to/custom/pingcheck.sh" + tests : + - type : 'status' + operator : '!=' + value : '0' + tolerance : + cycles : '2' + action : 'exec' + exec : 'sudo /sbin/reboot' ``` ## License From cf40f1658c292b010f4e4c6dd58af7e044503d45 Mon Sep 17 00:00:00 2001 From: Andreas John Date: Wed, 2 Sep 2015 17:16:15 +0200 Subject: [PATCH 3/3] Added Example for PROGRAM STATUS TESTING to README. 02. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ba0bb97..f252fc2 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,7 @@ monit::checks : host: '127.0.0.1' port: '80' protocol: 'http' + custom-script: type : 'program' config :