Skip to content

Commit

Permalink
Merge pull request #9 from derjohn/master
Browse files Browse the repository at this point in the history
Made monit's PROGRAM STATUS TESTING work, made ACTION EXEC work, made exec path accept parameters.
  • Loading branch information
jonhattan committed Sep 3, 2015
2 parents ff6b3a9 + cf40f16 commit 2efb3e1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@ 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
Expand Down
7 changes: 6 additions & 1 deletion lib/puppet/parser/functions/monit_validate_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 0 additions & 2 deletions manifests/check/program.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
$order = 0,
) {

validate_absolute_path($path)

monit::check::instance { "${name}_instance":
ensure => $ensure,
name => $name,
Expand Down
7 changes: 5 additions & 2 deletions templates/check/common.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>

2 changes: 1 addition & 1 deletion templates/check/program.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CHECK PROGRAM <%= @name %> WITH PATH <%= @path %>
CHECK PROGRAM <%= @name %> WITH PATH "<%= @path %>"

0 comments on commit 2efb3e1

Please sign in to comment.