Skip to content

Commit 97e6975

Browse files
Ian Taylorjamtur01
Ian Taylor
authored andcommitted
Changed indentation to be more consistent with style guide (4 spaces per level)
1 parent 41ce18c commit 97e6975

28 files changed

+1271
-1271
lines changed

autotest/discover.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
require 'autotest'
22

33
Autotest.add_discovery do
4-
"rspec"
4+
"rspec"
55
end
66

77
Autotest.add_discovery do
8-
"puppet"
8+
"puppet"
99
end

autotest/rspec.rb

+55-55
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,74 @@
11
require 'autotest'
22

33
Autotest.add_hook :initialize do |at|
4-
at.clear_mappings
5-
# watch out: Ruby bug (1.8.6):
6-
# %r(/) != /\//
7-
at.add_mapping(%r%^spec/.*\.rb$%) { |filename, _|
8-
filename
9-
}
10-
at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
11-
["spec/#{m[1]}_spec.rb"]
12-
}
13-
at.add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
14-
at.files_matching %r{^spec/.*_spec\.rb$}
15-
}
4+
at.clear_mappings
5+
# watch out: Ruby bug (1.8.6):
6+
# %r(/) != /\//
7+
at.add_mapping(%r%^spec/.*\.rb$%) { |filename, _|
8+
filename
9+
}
10+
at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
11+
["spec/#{m[1]}_spec.rb"]
12+
}
13+
at.add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
14+
at.files_matching %r{^spec/.*_spec\.rb$}
15+
}
1616
end
1717

1818
class RspecCommandError < StandardError; end
1919

2020
class Autotest::Rspec < Autotest
2121

22-
def initialize
23-
super
22+
def initialize
23+
super
2424

25-
self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m
26-
self.completed_re = /\Z/ # FIX: some sort of summary line at the end?
27-
end
25+
self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m
26+
self.completed_re = /\Z/ # FIX: some sort of summary line at the end?
27+
end
2828

29-
def consolidate_failures(failed)
30-
filters = Hash.new { |h,k| h[k] = [] }
31-
failed.each do |spec, failed_trace|
32-
if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then
33-
filters[f] << spec
34-
break
35-
end
29+
def consolidate_failures(failed)
30+
filters = Hash.new { |h,k| h[k] = [] }
31+
failed.each do |spec, failed_trace|
32+
if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then
33+
filters[f] << spec
34+
break
35+
end
36+
end
37+
return filters
3638
end
37-
return filters
38-
end
3939

40-
def make_test_cmd(files_to_test)
41-
return "#{ruby} -S #{spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}"
42-
end
43-
44-
def add_options_if_present
45-
File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
46-
end
40+
def make_test_cmd(files_to_test)
41+
return "#{ruby} -S #{spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}"
42+
end
4743

48-
# Finds the proper spec command to use. Precendence is set in the
49-
# lazily-evaluated method spec_commands. Alias + Override that in
50-
# ~/.autotest to provide a different spec command then the default
51-
# paths provided.
52-
def spec_command(separator=File::ALT_SEPARATOR)
53-
unless defined? @spec_command then
54-
@spec_command = spec_commands.find { |cmd| File.exists? cmd }
44+
def add_options_if_present
45+
File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
46+
end
5547

56-
raise RspecCommandError, "No spec command could be found!" unless @spec_command
48+
# Finds the proper spec command to use. Precendence is set in the
49+
# lazily-evaluated method spec_commands. Alias + Override that in
50+
# ~/.autotest to provide a different spec command then the default
51+
# paths provided.
52+
def spec_command(separator=File::ALT_SEPARATOR)
53+
unless defined? @spec_command then
54+
@spec_command = spec_commands.find { |cmd| File.exists? cmd }
5755

58-
@spec_command.gsub! File::SEPARATOR, separator if separator
56+
raise RspecCommandError, "No spec command could be found!" unless @spec_command
57+
58+
@spec_command.gsub! File::SEPARATOR, separator if separator
59+
end
60+
@spec_command
5961
end
60-
@spec_command
61-
end
6262

63-
# Autotest will look for spec commands in the following
64-
# locations, in this order:
65-
#
66-
# * bin/spec
67-
# * default spec bin/loader installed in Rubygems
68-
def spec_commands
69-
[
70-
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec')),
71-
File.join(Config::CONFIG['bindir'], 'spec')
72-
]
73-
end
63+
# Autotest will look for spec commands in the following
64+
# locations, in this order:
65+
#
66+
# * bin/spec
67+
# * default spec bin/loader installed in Rubygems
68+
def spec_commands
69+
[
70+
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec')),
71+
File.join(Config::CONFIG['bindir'], 'spec')
72+
]
73+
end
7474
end

ext/nagios/check_puppet.rb

+83-83
Original file line numberDiff line numberDiff line change
@@ -6,108 +6,108 @@
66

77
class CheckPuppet
88

9-
VERSION = '0.1'
10-
script_name = File.basename($0)
11-
12-
# default options
13-
OPTIONS = {
14-
:statefile => "/var/puppet/state/state.yaml",
15-
:process => "puppetd",
16-
:interval => 30,
17-
}
18-
19-
o = OptionParser.new do |o|
20-
o.set_summary_indent(' ')
21-
o.banner = "Usage: #{script_name} [OPTIONS]"
22-
o.define_head "The check_puppet Nagios plug-in checks that specified " +
9+
VERSION = '0.1'
10+
script_name = File.basename($0)
11+
12+
# default options
13+
OPTIONS = {
14+
:statefile => "/var/puppet/state/state.yaml",
15+
:process => "puppetd",
16+
:interval => 30,
17+
}
18+
19+
o = OptionParser.new do |o|
20+
o.set_summary_indent(' ')
21+
o.banner = "Usage: #{script_name} [OPTIONS]"
22+
o.define_head "The check_puppet Nagios plug-in checks that specified " +
2323
"Puppet process is running and the state file is no " +
2424
"older than specified interval."
25-
o.separator ""
26-
o.separator "Mandatory arguments to long options are mandatory for " +
25+
o.separator ""
26+
o.separator "Mandatory arguments to long options are mandatory for " +
2727
"short options too."
28-
29-
o.on("-s", "--statefile=statefile", String, "The state file",
28+
29+
o.on("-s", "--statefile=statefile", String, "The state file",
3030
"Default: #{OPTIONS[:statefile]}") { |OPTIONS[:statefile]| }
31-
o.on("-p", "--process=processname", String, "The process to check",
31+
o.on("-p", "--process=processname", String, "The process to check",
3232
"Default: #{OPTIONS[:process]}") { |OPTIONS[:process]| }
33-
o.on("-i", "--interval=value", Integer,
33+
o.on("-i", "--interval=value", Integer,
3434
"Default: #{OPTIONS[:interval]} minutes") { |OPTIONS[:interval]| }
35-
36-
o.separator ""
37-
o.on_tail("-h", "--help", "Show this help message.") do
38-
puts o
39-
exit
40-
end
41-
42-
o.parse!(ARGV)
43-
end
4435

45-
def check_proc
36+
o.separator ""
37+
o.on_tail("-h", "--help", "Show this help message.") do
38+
puts o
39+
exit
40+
end
4641

47-
unless ProcTable.ps.find { |p| p.name == OPTIONS[:process]}
48-
@proc = 2
49-
else
50-
@proc = 0
42+
o.parse!(ARGV)
5143
end
52-
53-
end
5444

55-
def check_state
45+
def check_proc
5646

57-
# Set variables
58-
curt = Time.now
59-
intv = OPTIONS[:interval] * 60
47+
unless ProcTable.ps.find { |p| p.name == OPTIONS[:process]}
48+
@proc = 2
49+
else
50+
@proc = 0
51+
end
6052

61-
# Check file time
62-
begin
63-
@modt = File.mtime("#{OPTIONS[:statefile]}")
64-
rescue
65-
@file = 3
6653
end
67-
68-
diff = (curt - @modt).to_i
6954

70-
if diff > intv
71-
@file = 2
72-
else
73-
@file = 0
74-
end
55+
def check_state
7556

76-
end
77-
78-
def output_status
79-
80-
case @file
81-
when 0
82-
state = "state file status okay updated on " + @modt.strftime("%m/%d/%Y at %H:%M:%S")
83-
when 2
84-
state = "state fille is not up to date and is older than #{OPTIONS[:interval]} minutes"
85-
when 3
86-
state = "state file status unknown"
87-
end
57+
# Set variables
58+
curt = Time.now
59+
intv = OPTIONS[:interval] * 60
8860

89-
case @proc
90-
when 0
91-
process = "process #{OPTIONS[:process]} is running"
92-
when 2
93-
process = "process #{OPTIONS[:process]} is not running"
94-
end
61+
# Check file time
62+
begin
63+
@modt = File.mtime("#{OPTIONS[:statefile]}")
64+
rescue
65+
@file = 3
66+
end
67+
68+
diff = (curt - @modt).to_i
69+
70+
if diff > intv
71+
@file = 2
72+
else
73+
@file = 0
74+
end
9575

96-
case @proc or @file
97-
when 0
98-
status = "OK"
99-
exitcode = 0
100-
when 2
101-
status = "CRITICAL"
102-
exitcode = 2
103-
when 3
104-
status = "UNKNOWN"
105-
exitcide = 3
10676
end
10777

108-
puts "PUPPET " + status + ": " + process + ", " + state
109-
exit(exitcode)
110-
end
78+
def output_status
79+
80+
case @file
81+
when 0
82+
state = "state file status okay updated on " + @modt.strftime("%m/%d/%Y at %H:%M:%S")
83+
when 2
84+
state = "state fille is not up to date and is older than #{OPTIONS[:interval]} minutes"
85+
when 3
86+
state = "state file status unknown"
87+
end
88+
89+
case @proc
90+
when 0
91+
process = "process #{OPTIONS[:process]} is running"
92+
when 2
93+
process = "process #{OPTIONS[:process]} is not running"
94+
end
95+
96+
case @proc or @file
97+
when 0
98+
status = "OK"
99+
exitcode = 0
100+
when 2
101+
status = "CRITICAL"
102+
exitcode = 2
103+
when 3
104+
status = "UNKNOWN"
105+
exitcide = 3
106+
end
107+
108+
puts "PUPPET " + status + ": " + process + ", " + state
109+
exit(exitcode)
110+
end
111111
end
112112

113113
cp = CheckPuppet.new

0 commit comments

Comments
 (0)