Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect and report stray arguments #293

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/riemann/tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def options
end
end

attr_reader :argv

def initialize(allow_arguments: false)
options
@argv = ARGV.dup
abort "Error: stray arguments: #{ARGV.map(&:inspect).join(', ')}" if ARGV.any? && !allow_arguments
end

# Returns parsed options (cached) from command line.
def options
@options ||= self.class.options
Expand All @@ -58,10 +66,7 @@ def attributes
end

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

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

Expand Down
2 changes: 2 additions & 0 deletions lib/riemann/tools/apache_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ApacheStatus
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)"

def initialize
super

@uri = URI.parse("#{opts[:uri]}?auto")
# Sample Response with ExtendedStatus On
# Total Accesses: 20643
Expand Down
2 changes: 2 additions & 0 deletions lib/riemann/tools/bench.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Bench
attr_accessor :client, :hosts, :services, :states

def initialize
super

@hosts = [nil] + (0...10).map { |i| "host#{i}" }
@hosts = %w[a b c d e f g h i j]
@services = %w[test1 test2 test3 foo bar baz xyzzy attack cat treat]
Expand Down
2 changes: 2 additions & 0 deletions lib/riemann/tools/consul_health.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class ConsulHealth
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)"

def initialize
super

@hostname = opts[:consul_host]
@prefix = opts[:prefix]
@minimum_services_per_node = opts[:minimum_services_per_node]
Expand Down
2 changes: 2 additions & 0 deletions lib/riemann/tools/dir_files_count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class DirFilesCount
opt :alert_on_missing, 'Send a critical metric if the directory is missing?', default: true

def initialize
super

@dir = opts.fetch(:directory)
@service_prefix = opts.fetch(:service_prefix)
@warning = opts.fetch(:warning, nil)
Expand Down
2 changes: 2 additions & 0 deletions lib/riemann/tools/dir_space.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class DirSpace
opt :alert_on_missing, 'Send a critical metric if the directory is missing?', default: true

def initialize
super

@dir = opts.fetch(:directory)
@service_prefix = opts.fetch(:service_prefix)
@warning = opts.fetch(:warning, nil)
Expand Down
2 changes: 2 additions & 0 deletions lib/riemann/tools/diskstats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Diskstats
opt :ignore_devices, 'Devices to ignore', type: :strings, default: nil

def initialize
super

@old_state = nil
end

Expand Down
2 changes: 2 additions & 0 deletions lib/riemann/tools/fd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Fd
opt :processes, 'list of processes to measure fd usage in addition to system total', type: :ints

def initialize
super

@limits = {
fd: { critical: opts[:fd_sys_critical], warning: opts[:fd_sys_warning] },
process: { critical: opts[:fd_proc_critical], warning: opts[:fd_proc_warning] },
Expand Down
2 changes: 2 additions & 0 deletions lib/riemann/tools/freeswitch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Freeswitch
opt :pid_file, 'FreeSWITCH daemon pidfile', type: String, default: '/var/run/freeswitch/freeswitch.pid'

def initialize
super

@limits = {
calls: { critical: opts[:calls_critical], warning: opts[:calls_warning] },
}
Expand Down
2 changes: 2 additions & 0 deletions lib/riemann/tools/haproxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Haproxy
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)"

def initialize
super

@uri = URI("#{opts[:stats_url]};csv")
end

Expand Down
2 changes: 2 additions & 0 deletions lib/riemann/tools/health.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Health
opt :checks, 'A list of checks to run.', type: :strings, default: %w[cpu load memory disk swap]

def initialize
super

@limits = {
cpu: { critical: opts[:cpu_critical], warning: opts[:cpu_warning] },
disk: { critical: opts[:disk_critical], warning: opts[:disk_warning], critical_leniency_kb: human_size_to_number(opts[:disk_critical_leniency]) / 1024, warning_leniency_kb: human_size_to_number(opts[:disk_warning_leniency]) / 1024 },
Expand Down
4 changes: 2 additions & 2 deletions lib/riemann/tools/http_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class HttpCheck
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)"

def initialize
super

@resolve_queue = Queue.new
@work_queue = Queue.new

Expand Down Expand Up @@ -73,8 +75,6 @@ def initialize
end
end
end

super
end

# Under normal operation, we have a single instance of this class for the
Expand Down
2 changes: 2 additions & 0 deletions lib/riemann/tools/net.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Net
opt :ignore_interfaces, 'Interfaces to ignore', type: :strings, default: ['\Alo\d*\z']

def initialize
super

@old_state = nil
@interfaces = if opts[:interfaces]
opts[:interfaces].reject(&:empty?).map(&:dup)
Expand Down
2 changes: 2 additions & 0 deletions lib/riemann/tools/nginx_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class NginxStatus
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)"

def initialize
super

@uri = URI.parse(opts[:uri])

# sample response:
Expand Down
2 changes: 2 additions & 0 deletions lib/riemann/tools/ntp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Ntp
include Riemann::Tools

def initialize
super

@hostname = `hostname`.chomp
@ostype = `uname -s`.chomp.downcase
abort 'WARNING: macOS not explicitly supported. Exiting.' if @ostype == 'darwin'
Expand Down
2 changes: 2 additions & 0 deletions lib/riemann/tools/portcheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Portcheck
opt :ports, "List of ports to check, e.g. '-r 80 443'", type: :ints

def initialize
super

@hostname = opts.fetch(:hostname)
@ports = opts.fetch(:ports)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/riemann/tools/proc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Proc
opt :proc_max_critical, 'running process count maximum', default: 65_536

def initialize
super

@limits = { critical: { min: opts[:proc_min_critical], max: opts[:proc_max_critical] } }

abort 'FATAL: specify a process regular expression, see --help for usage' unless opts[:proc_regex]
Expand Down
2 changes: 2 additions & 0 deletions lib/riemann/tools/varnish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Varnish
opt :varnish_host, 'Varnish hostname', default: `hostname`.chomp

def initialize
super

cmd = 'varnishstat -V'
Open3.popen3(cmd) do |_stdin, _stdout, stderr, _wait_thr|
@ver = /varnishstat \(varnish-(\d+)/.match(stderr.read)[1].to_i
Expand Down
2 changes: 2 additions & 0 deletions tools/riemann-aws/lib/riemann/tools/aws/billing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Billing
opt :time_end, 'End time in seconds of the metrics period ', type: Integer, default: 60

def initialize
super

if opts[:fog_credentials_file]
Fog.credentials_path = opts[:fog_credentials_file]
Fog.credential = opts[:fog_credential].to_sym
Expand Down
2 changes: 2 additions & 0 deletions tools/riemann-aws/lib/riemann/tools/aws/rds_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class RdsStatus
opt :region, 'AWS region', type: String, default: 'eu-west-1'
opt :dbinstance_identifier, 'DBInstanceIdentifier', type: String
def initialize
super

abort 'FATAL: specify a DB instance name, see --help for usage' unless opts[:dbinstance_identifier]
creds = if opts[:access_key] && opts[:secret_key]
{
Expand Down
2 changes: 2 additions & 0 deletions tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class SqsStatus
opt :region, 'AWS region', type: String, default: 'us-east-1'
opt :queue, 'SQS Queue name', type: String
def initialize
super

creds = if opts.key?('access_key') && opts.key?('secret_key')
{
aws_access_key_id: opts[:access_key],
Expand Down
2 changes: 2 additions & 0 deletions tools/riemann-aws/lib/riemann/tools/aws/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Status
opt :event_warning, 'Number of days before event. Defaults to nil (i.e. when the event appears)', default: nil

def initialize
super

if opts[:fog_credentials_file]
Fog.credentials_path = opts[:fog_credentials_file]
Fog.credential = opts[:fog_credential].to_sym
Expand Down
2 changes: 2 additions & 0 deletions tools/riemann-chronos/lib/riemann/tools/chronos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Chronos
def initialize
options[:interval] = 60
options[:ttl] = 120

super
end

# Handles HTTP connections and GET requests safely
Expand Down
2 changes: 2 additions & 0 deletions tools/riemann-docker/lib/riemann/tools/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def get_container_name(container)
end

def initialize
super

Docker.url = opts[:docker_host] unless opts[:docker_host].nil?

@hostname = opts[:host_hostname]
Expand Down
2 changes: 2 additions & 0 deletions tools/riemann-marathon/lib/riemann/tools/marathon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Marathon
def initialize
options[:interval] = 60
options[:ttl] = 120

super
end

# Handles HTTP connections and GET requests safely
Expand Down
2 changes: 2 additions & 0 deletions tools/riemann-munin/lib/riemann/tools/munin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Munin
require 'munin-ruby'

def initialize
super

@munin = ::Munin::Node.new
end

Expand Down
2 changes: 2 additions & 0 deletions tools/riemann-riak/lib/riemann/tools/riak.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Riak
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)"

def initialize
super

detect_features

@httpstatus = true
Expand Down