Skip to content

Commit

Permalink
Merge pull request #1 from opus-codium/simplify
Browse files Browse the repository at this point in the history
Split complex functions in smaller parts
  • Loading branch information
neomilium authored Jan 11, 2024
2 parents 2dd67af + aace364 commit f4e6bee
Showing 1 changed file with 41 additions and 13 deletions.
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

0 comments on commit f4e6bee

Please sign in to comment.