summaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/extlookup.rb26
-rwxr-xr-xext/nagios/check_puppet.rb49
-rwxr-xr-xext/puppetlisten/puppetrun.rb2
-rw-r--r--ext/puppetstoredconfigclean.rb5
-rw-r--r--ext/regexp_nodes/regexp_nodes.rb10
5 files changed, 52 insertions, 40 deletions
diff --git a/ext/extlookup.rb b/ext/extlookup.rb
index b0978ef12..b9ebc43c8 100644
--- a/ext/extlookup.rb
+++ b/ext/extlookup.rb
@@ -1,10 +1,10 @@
-# Puppet External Data Sources
+# Puppet External Data Sources
#
# This is a parser function to read data from external files, this version
# uses CSV files but the concept can easily be adjust for databases, yaml
# or any other queryable data source.
#
-# The object of this is to make it obvious when it's being used, rather than
+# The object of this is to make it obvious when it's being used, rather than
# magically loading data in when an module is loaded I prefer to look at the code
# and see statements like:
#
@@ -34,7 +34,7 @@
#
# Now create the following data files in /etc/puppet/manifests/extdata
#
-# domain_myclient.com.csv:
+# domain_myclient.com.csv:
# snmp_contact,John Doe <john@myclient.com>
# root_contact,support@%{domain}
# client_trusted_ips,192.168.1.130,192.168.10.0/24
@@ -48,7 +48,7 @@
#
# $snmp_contact = extlookup("snmp_contact")
#
-# The obove code shows some other features, you can use any fact or variable that
+# The obove code shows some other features, you can use any fact or variable that
# is in scope by simply using %{varname} in your data files, you can return arrays
# by just having multiple values in the csv after the initial variable name.
#
@@ -57,8 +57,8 @@
# in empty values etc. You can however specify a default value:
#
# $ntp_servers = extlookup("ntp_servers", "1.${country}.pool.ntp.org")
-#
-# In this case it will default to "1.${country}.pool.ntp.org" if nothing is defined in
+#
+# In this case it will default to "1.${country}.pool.ntp.org" if nothing is defined in
# any data file.
#
# You can also specify an additional data file to search first before any others at use
@@ -78,7 +78,7 @@
#
# For further help contact Volcane on #puppet
require 'csv'
-
+
module Puppet::Parser::Functions
newfunction(:extlookup, :type => :rvalue) do |args|
key = args[0]
@@ -110,12 +110,12 @@ module Puppet::Parser::Functions
extlookup_precedence << prec
end
-
+
datafiles = Array.new
# if we got a custom data file, put it first in the array of search files
- if datafile != ""
+ if datafile != ""
if File.exists?(extlookup_datadir + "/#{datafile}.csv")
datafiles << extlookup_datadir + "/#{datafile}.csv"
end
@@ -135,14 +135,14 @@ module Puppet::Parser::Functions
result = CSV.read(file).find_all do |r|
r[0] == key
end
-
+
# return just the single result if theres just one,
# else take all the fields in the csv and build an array
if result.length > 0
if result[0].length == 2
val = result[0][1].to_s
-
+
# parse %{}'s in the CSV into local variables using lookupvar()
while val =~ /%\{(.+?)\}/
val.gsub!(/%\{#{$1}\}/, lookupvar($1))
@@ -152,7 +152,7 @@ module Puppet::Parser::Functions
elsif result[0].length > 1
length = result[0].length
cells = result[0][1,length]
-
+
# Individual cells in a CSV result are a weird data type and throws
# puppets yaml parsing, so just map it all to plain old strings
desired = cells.map do |c|
@@ -172,7 +172,7 @@ module Puppet::Parser::Functions
# don't accidently return nil's and such rather throw a parse error
if desired == "_ExtUNSET_" && default == "_ExtUNSET_"
raise Puppet::ParseError, "No match found for '#{key}' in any data file during extlookup()"
- else
+ else
desired = default if desired == "_ExtUNSET_"
end
diff --git a/ext/nagios/check_puppet.rb b/ext/nagios/check_puppet.rb
index c569566ad..5d448b6fc 100755
--- a/ext/nagios/check_puppet.rb
+++ b/ext/nagios/check_puppet.rb
@@ -20,26 +20,35 @@ class CheckPuppet
o.set_summary_indent(' ')
o.banner = "Usage: #{script_name} [OPTIONS]"
o.define_head "The check_puppet Nagios plug-in checks that specified " +
- "Puppet process is running and the state file is no " +
- "older than specified interval."
- o.separator ""
- o.separator "Mandatory arguments to long options are mandatory for " +
- "short options too."
-
- o.on("-s", "--statefile=statefile", String, "The state file",
- "Default: #{OPTIONS[:statefile]}") { |OPTIONS[:statefile]| }
- o.on("-p", "--process=processname", String, "The process to check",
- "Default: #{OPTIONS[:process]}") { |OPTIONS[:process]| }
- o.on("-i", "--interval=value", Integer,
- "Default: #{OPTIONS[:interval]} minutes") { |OPTIONS[:interval]| }
-
- o.separator ""
- o.on_tail("-h", "--help", "Show this help message.") do
- puts o
- exit
- end
-
- o.parse!(ARGV)
+ "Puppet process is running and the state file is no " +
+ "older than specified interval."
+ o.separator ""
+ o.separator "Mandatory arguments to long options are mandatory for " +
+ "short options too."
+
+
+ o.on(
+ "-s", "--statefile=statefile", String, "The state file",
+
+ "Default: #{OPTIONS[:statefile]}") { |OPTIONS[:statefile]| }
+
+ o.on(
+ "-p", "--process=processname", String, "The process to check",
+
+ "Default: #{OPTIONS[:process]}") { |OPTIONS[:process]| }
+
+ o.on(
+ "-i", "--interval=value", Integer,
+
+ "Default: #{OPTIONS[:interval]} minutes") { |OPTIONS[:interval]| }
+
+ o.separator ""
+ o.on_tail("-h", "--help", "Show this help message.") do
+ puts o
+ exit
+ end
+
+ o.parse!(ARGV)
end
def check_proc
diff --git a/ext/puppetlisten/puppetrun.rb b/ext/puppetlisten/puppetrun.rb
index 600ab1038..192016c8d 100755
--- a/ext/puppetlisten/puppetrun.rb
+++ b/ext/puppetlisten/puppetrun.rb
@@ -31,7 +31,7 @@ s = TCPSocket.new(host, port)
ssl = OpenSSL::SSL::SSLSocket.new(s, ctx)
ssl.connect # start SSL session
ssl.sync_close = true # if true the underlying socket will be
- # closed in SSLSocket#close. (default: false)
+# closed in SSLSocket#close. (default: false)
while (line = ssl.gets)
puts line
end
diff --git a/ext/puppetstoredconfigclean.rb b/ext/puppetstoredconfigclean.rb
index 1b4aabd0f..6f4aa7230 100644
--- a/ext/puppetstoredconfigclean.rb
+++ b/ext/puppetstoredconfigclean.rb
@@ -17,10 +17,13 @@ def printusage(error_code)
exit(error_code)
end
-opts = GetoptLong.new(
+
+ opts = GetoptLong.new(
+
[ "--config", "-c", GetoptLong::REQUIRED_ARGUMENT ],
[ "--help", "-h", GetoptLong::NO_ARGUMENT ],
[ "--usage", "-u", GetoptLong::NO_ARGUMENT ],
+
[ "--version", "-v", GetoptLong::NO_ARGUMENT ]
)
diff --git a/ext/regexp_nodes/regexp_nodes.rb b/ext/regexp_nodes/regexp_nodes.rb
index a9e7ed6a9..377b13053 100644
--- a/ext/regexp_nodes/regexp_nodes.rb
+++ b/ext/regexp_nodes/regexp_nodes.rb
@@ -96,9 +96,9 @@ class ExternalNode
def to_yaml
classes = self.classes.to_a
if self.parameters.empty? # otherwise to_yaml prints "parameters: {}"
- parameters = nil
+ parameters = nil
else
- parameters = self.parameters
+ parameters = self.parameters
end
({ 'classes' => classes, 'parameters' => parameters}).to_yaml
end
@@ -164,7 +164,7 @@ class ExternalNode
next if File.basename(filepath) =~ /^\./ # skip over dotfiles
next unless File.directory?(filepath) and
- File.readable?(filepath) # skip over non-directories
+ File.readable?(filepath) # skip over non-directories
$LOG.debug "Considering contents of #{filepath}"
@@ -175,8 +175,8 @@ class ExternalNode
File.readable?(secondlevel)
$LOG.debug("Attempting to match [#{@hostname}] in [#{secondlevel}]")
if matched_in_patternfile?(secondlevel, @hostname)
- @parameters[ parametername.to_s ] = patternfile.to_s
- $LOG.debug("Set @parameters[#{parametername.to_s}] = #{patternfile.to_s}")
+ @parameters[ parametername.to_s ] = patternfile.to_s
+ $LOG.debug("Set @parameters[#{parametername.to_s}] = #{patternfile.to_s}")
end # if
end # Dir.foreach #{filepath}
end # Dir.foreach #{fullpath}