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

Split complex functions in smaller parts #1

Merged
merged 1 commit into from
Jan 11, 2024
Merged
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
54 changes: 41 additions & 13 deletions lib/riemann/tools/syslog_ng.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ def statistics
while (line = @socket.gets.chomp) != '.'
source_name, source_id, source_instance, state, type, metric = line.split(';')

next if opts[:source_name] && !opts[:source_name].include?(source_name)
next if opts[:source_id] && !opts[:source_id].include?(source_id)
next if opts[:source_instance] && !opts[:source_instance].include?(source_instance)
next if opts[:state] && !opts[:state].include?(state)
next if opts[:type] && !opts[:type].include?(type)
next if rejected_source_name?(source_name)
next if rejected_source_id?(source_id)
next if rejected_source_instance?(source_instance)
next if rejected_state?(state)
next if rejected_type?(type)

res << {
source_name: source_name,
Expand All @@ -62,17 +62,45 @@ def statistics
res
end

def rejected_source_name?(source_name)
opts[:source_name] && !opts[:source_name].include?(source_name)
end

def rejected_source_id?(source_id)
opts[:source_id] && !opts[:source_id].include?(source_id)
end

def rejected_source_instance?(source_instance)
opts[:source_instance] && !opts[:source_instance].include?(source_instance)
end

def rejected_state?(state)
opts[:state] && !opts[:state].include?(state)
end

def rejected_type?(type)
opts[:type] && !opts[:type].include?(type)
end

def statistic_state(type, metric)
if type == 'dropped'
metric == 0.0 ? 'ok' : 'critical'
dropped_statistic_state(metric)
elsif type == 'queued'
if metric >= opts[:queued_critical]
'critical'
elsif metric >= opts[:queued_warning]
'warning'
else
'ok'
end
queued_statistic_state(metric)
end
end

def dropped_statistic_state(metric)
metric == 0.0 ? 'ok' : 'critical'
end

def queued_statistic_state(metric)
if metric >= opts[:queued_critical]
'critical'
elsif metric >= opts[:queued_warning]
'warning'
else
'ok'
end
end
end
Expand Down