Skip to content

Commit d2b38d7

Browse files
authored
Merge pull request #293 from riemann/raise-error-on-stray-arguments
Detect and report stray arguments
2 parents 206f27c + 73a7230 commit d2b38d7

File tree

27 files changed

+61
-6
lines changed

27 files changed

+61
-6
lines changed

lib/riemann/tools.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ def options
4444
end
4545
end
4646

47+
attr_reader :argv
48+
49+
def initialize(allow_arguments: false)
50+
options
51+
@argv = ARGV.dup
52+
abort "Error: stray arguments: #{ARGV.map(&:inspect).join(', ')}" if ARGV.any? && !allow_arguments
53+
end
54+
4755
# Returns parsed options (cached) from command line.
4856
def options
4957
@options ||= self.class.options
@@ -58,10 +66,7 @@ def attributes
5866
end
5967

6068
def report(event)
61-
if options[:tag]
62-
# Work around a bug with beefcake which can't take frozen strings.
63-
event[:tags] = [*event.fetch(:tags, [])] + options[:tag].map(&:dup)
64-
end
69+
event[:tags] = event.fetch(:tags, []) + options[:tag]
6570

6671
event[:ttl] ||= options[:ttl] || (options[:interval] * 2)
6772

lib/riemann/tools/apache_status.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class ApacheStatus
1818
opt :user_agent, 'User-Agent header for HTTP requests', short: :none, default: "#{File.basename($PROGRAM_NAME)}/#{Riemann::Tools::VERSION} (+https://github.com/riemann/riemann-tools)"
1919

2020
def initialize
21+
super
22+
2123
@uri = URI.parse("#{opts[:uri]}?auto")
2224
# Sample Response with ExtendedStatus On
2325
# Total Accesses: 20643

lib/riemann/tools/bench.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class Bench
1111
attr_accessor :client, :hosts, :services, :states
1212

1313
def initialize
14+
super
15+
1416
@hosts = [nil] + (0...10).map { |i| "host#{i}" }
1517
@hosts = %w[a b c d e f g h i j]
1618
@services = %w[test1 test2 test3 foo bar baz xyzzy attack cat treat]

lib/riemann/tools/consul_health.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class ConsulHealth
2020
opt :user_agent, 'User-Agent header for HTTP requests', short: :none, default: "#{File.basename($PROGRAM_NAME)}/#{Riemann::Tools::VERSION} (+https://github.com/riemann/riemann-tools)"
2121

2222
def initialize
23+
super
24+
2325
@hostname = opts[:consul_host]
2426
@prefix = opts[:prefix]
2527
@minimum_services_per_node = opts[:minimum_services_per_node]

lib/riemann/tools/dir_files_count.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class DirFilesCount
1515
opt :alert_on_missing, 'Send a critical metric if the directory is missing?', default: true
1616

1717
def initialize
18+
super
19+
1820
@dir = opts.fetch(:directory)
1921
@service_prefix = opts.fetch(:service_prefix)
2022
@warning = opts.fetch(:warning, nil)

lib/riemann/tools/dir_space.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class DirSpace
1515
opt :alert_on_missing, 'Send a critical metric if the directory is missing?', default: true
1616

1717
def initialize
18+
super
19+
1820
@dir = opts.fetch(:directory)
1921
@service_prefix = opts.fetch(:service_prefix)
2022
@warning = opts.fetch(:warning, nil)

lib/riemann/tools/diskstats.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class Diskstats
1111
opt :ignore_devices, 'Devices to ignore', type: :strings, default: nil
1212

1313
def initialize
14+
super
15+
1416
@old_state = nil
1517
end
1618

lib/riemann/tools/fd.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class Fd
1616
opt :processes, 'list of processes to measure fd usage in addition to system total', type: :ints
1717

1818
def initialize
19+
super
20+
1921
@limits = {
2022
fd: { critical: opts[:fd_sys_critical], warning: opts[:fd_sys_warning] },
2123
process: { critical: opts[:fd_proc_critical], warning: opts[:fd_proc_warning] },

lib/riemann/tools/freeswitch.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class Freeswitch
1313
opt :pid_file, 'FreeSWITCH daemon pidfile', type: String, default: '/var/run/freeswitch/freeswitch.pid'
1414

1515
def initialize
16+
super
17+
1618
@limits = {
1719
calls: { critical: opts[:calls_critical], warning: opts[:calls_warning] },
1820
}

lib/riemann/tools/haproxy.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class Haproxy
1616
opt :user_agent, 'User-Agent header for HTTP requests', short: :none, default: "#{File.basename($PROGRAM_NAME)}/#{Riemann::Tools::VERSION} (+https://github.com/riemann/riemann-tools)"
1717

1818
def initialize
19+
super
20+
1921
@uri = URI("#{opts[:stats_url]};csv")
2022
end
2123

0 commit comments

Comments
 (0)