Skip to content

Commit

Permalink
Merge pull request #4 from opus-codium/dependabot
Browse files Browse the repository at this point in the history
Setup dependabot
  • Loading branch information
smortex authored Jan 12, 2024
2 parents f4e6bee + e52e91e commit dd4198e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
time: "13:00"
open-pull-requests-limit: 10
17 changes: 12 additions & 5 deletions lib/riemann/tools/syslog_ng.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ class SyslogNg
opt :queued_warning, 'Queued messages warning threshold', short: :none, default: 300
opt :queued_critical, 'Queued messages critical threshold', short: :none, default: 1000

def initialize
@socket = UNIXSocket.new(opts[:socket])
def socket
@socket ||= UNIXSocket.new(opts[:socket])
end

def force_reconnect
@socket = nil
end

def tick
Expand All @@ -33,14 +37,17 @@ def tick
state: statistic_state(statistic[:type], statistic[:metric]),
})
end
rescue Errno::EPIPE
force_reconnect
retry
end

def statistics
res = []

@socket.puts 'STATS CSV'
@socket.gets # discard header
while (line = @socket.gets.chomp) != '.'
socket.puts 'STATS CSV'
socket.gets # discard header
while (line = socket.gets.chomp) != '.'
source_name, source_id, source_instance, state, type, metric = line.split(';')

next if rejected_source_name?(source_name)
Expand Down
43 changes: 43 additions & 0 deletions spec/riemann/tools/syslog_ng_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,49 @@
end
end

context 'with metrics above threshold' do
let(:statistics) do
<<~STATISTICS
dst.riemann;d_riemann#0;riemann,riemann.example.com,5555;a;queued;204
dst.riemann;d_riemann#0;riemann,riemann.example.com,5555;a;dropped;0
dst.riemann;d_riemann#1;riemann,riemann.example.com,5555;a;queued;404
dst.riemann;d_riemann#1;riemann,riemann.example.com,5555;a;dropped;1
dst.riemann;d_riemann#2;riemann,riemann.example.com,5555;a;queued;4040
dst.riemann;d_riemann#2;riemann,riemann.example.com,5555;a;dropped;1000
.
STATISTICS
end

before do
allow(tool).to receive(:report)
tool.tick
end

it 'report correct state with few queued events' do
expect(tool).to have_received(:report).with({ metric: 204, service: 'dst.riemann;d_riemann#0;riemann,riemann.example.com,5555;a;queued', state: 'ok' })
end

it 'report correct state with some queued events' do
expect(tool).to have_received(:report).with({ metric: 404, service: 'dst.riemann;d_riemann#1;riemann,riemann.example.com,5555;a;queued', state: 'warning' })
end

it 'report correct state with a lot of queued events' do
expect(tool).to have_received(:report).with({ metric: 4040, service: 'dst.riemann;d_riemann#2;riemann,riemann.example.com,5555;a;queued', state: 'critical' })
end

it 'report correct state with no dropped events' do
expect(tool).to have_received(:report).with({ metric: 0, service: 'dst.riemann;d_riemann#0;riemann,riemann.example.com,5555;a;dropped', state: 'ok' })
end

it 'report correct state with some dropped events' do
expect(tool).to have_received(:report).with({ metric: 1, service: 'dst.riemann;d_riemann#1;riemann,riemann.example.com,5555;a;dropped', state: 'critical' })
end

it 'report correct state with a lot of dropped events' do
expect(tool).to have_received(:report).with({ metric: 1000, service: 'dst.riemann;d_riemann#2;riemann,riemann.example.com,5555;a;dropped', state: 'critical' })
end
end

context 'with custom formatting' do
before do
ARGV.replace(['--format', '%<source_name>s %<type>s'])
Expand Down

0 comments on commit dd4198e

Please sign in to comment.