Skip to content

Commit

Permalink
Merge pull request #3 from antonlindstrom/89a0f18f12d6b19783a4136fd40…
Browse files Browse the repository at this point in the history
…1b79bb0fc5be6

Comply with puppetlabs style guide
uggedal committed May 12, 2012
2 parents 1787464 + 89a0f18 commit da99c81
Showing 12 changed files with 110 additions and 33 deletions.
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source :rubygems

gem 'puppet'

group :test do
gem 'puppet-lint'
gem 'rspec-puppet', '~> 0.1.3'
end
26 changes: 26 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
GEM
remote: http://rubygems.org/
specs:
diff-lcs (1.1.3)
facter (1.6.7)
puppet (2.7.13)
facter (>= 1.5.1)
puppet-lint (0.1.13)
rspec (2.9.0)
rspec-core (~> 2.9.0)
rspec-expectations (~> 2.9.0)
rspec-mocks (~> 2.9.0)
rspec-core (2.9.0)
rspec-expectations (2.9.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.9.0)
rspec-puppet (0.1.3)
rspec

PLATFORMS
ruby

DEPENDENCIES
puppet
puppet-lint
rspec-puppet (~> 0.1.3)
11 changes: 11 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'rake'

require 'puppet-lint/tasks/puppet-lint'
require 'rspec/core/rake_task'

task :default => [:lint, :spec]

RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = 'spec/*/*_spec.rb'
t.rspec_opts = '--color'
end
61 changes: 33 additions & 28 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
class monit($ensure=present, $admin="", $interval=60) {
$is_present = $ensure == "present"
class monit($ensure=present, $admin='', $interval=60) {
$is_present = $ensure == 'present'

package { "monit":
$service_pattern = $ensure ? {
'present' => '/usr/sbin/monit',
default => undef,
}

package { 'monit':
ensure => $ensure,
}

file {
"/etc/monit/monitrc":
ensure => $ensure,
content => template("monit/monitrc.erb"),
mode => 600,
require => Package["monit"];
file { '/etc/monit/monitrc':
ensure => $ensure,
content => template('monit/monitrc.erb'),
mode => '0600',
require => Package['monit'],
}

"/etc/default/monit":
ensure => $ensure,
content => "startup=1\n",
require => Package["monit"];
file { '/etc/default/monit':
ensure => $ensure,
content => "startup=1\n",
require => Package['monit'],
}

"/etc/logrotate.d/monit":
ensure => $ensure,
source => "puppet:///modules/monit/monit.logrotate",
require => Package[monit];
file { '/etc/logrotate.d/monit':
ensure => $ensure,
source => 'puppet:///modules/monit/monit.logrotate',
require => Package['monit'],
}

service { "monit":
ensure => $is_present,
enable => $is_present,
hasrestart => $is_present,
pattern => $ensure ? {
'present' => "/usr/sbin/monit",
default => undef,
},
subscribe => File["/etc/monit/monitrc"],
require => [File["/etc/monit/monitrc"],
File["/etc/logrotate.d/monit"]],
service { 'monit':
ensure => $is_present,
enable => $is_present,
hasrestart => $is_present,
pattern => $service_pattern,
subscribe => File['/etc/monit/monitrc'],
require => [
File['/etc/monit/monitrc'],
File['/etc/logrotate.d/monit']
],
}
}
10 changes: 5 additions & 5 deletions manifests/monitor.pp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
define monit::monitor($pidfile,
$ensure=present,
$ip_port=0,
$socket="",
$socket='',
$checks=[]) {

file { "/etc/monit/conf.d/$name.conf":
ensure => $ensure,
content => template("monit/process.conf.erb"),
notify => Service["monit"],
require => Package["monit"],
ensure => $ensure,
content => template('monit/process.conf.erb'),
notify => Service['monit'],
require => Package['monit'],
}
}
5 changes: 5 additions & 0 deletions spec/classes/monit__monitor_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe 'monit::monitor', :type => :class do
# Empty
end
5 changes: 5 additions & 0 deletions spec/classes/monit_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe 'monit', :type => :class do
# Empty
end
Empty file added spec/fixtures/manifests/site.pp
Empty file.
1 change: 1 addition & 0 deletions spec/fixtures/modules/monit
12 changes: 12 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'puppet'
require 'rspec'
require 'rspec-puppet'

def param_value(subject, type, title, param)
subject.resource(type, title).send(:parameters)[param.to_sym]
end

RSpec.configure do |c|
c.module_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures/modules'))
c.manifest_dir = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures/manifests'))
end
1 change: 1 addition & 0 deletions tests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include monit
3 changes: 3 additions & 0 deletions tests/monitor.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
monit::monitor { 'ssh':
pidfile => '/var/run/sshd.pid',
}

0 comments on commit da99c81

Please sign in to comment.