-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fa73666
Showing
15 changed files
with
504 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @opus-codium/core @opus-codium/vittoria-conseil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
rubocop: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: 3.0 | ||
bundler-cache: true | ||
- name: Run static code analysis | ||
run: bundle exec rubocop | ||
unit: | ||
runs-on: ubuntu-latest | ||
needs: rubocop | ||
strategy: | ||
matrix: | ||
ruby: | ||
- "2.6" | ||
- "2.7" | ||
- "3.0" | ||
- "3.1" | ||
- "3.2" | ||
- "3.3" | ||
name: Ruby ${{ matrix.ruby }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby }} | ||
bundler-cache: true | ||
- name: Run tests without uploading code coverage | ||
if: ${{ matrix.ruby != '3.0' }} | ||
run: bundle exec rake | ||
- name: Run tests and upload coverage to Code Climate | ||
if: ${{ matrix.ruby == '3.0' }} | ||
uses: paambaati/[email protected] | ||
env: | ||
CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_TOKEN }} | ||
with: | ||
coverageCommand: bundle exec rake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Gemfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
AllCops: | ||
TargetRubyVersion: '2.6' | ||
AllowSymlinksInCacheRootDirectory: true | ||
NewCops: enable | ||
Exclude: | ||
- vendor/bundle/**/* | ||
require: | ||
- rubocop-rake | ||
- rubocop-rspec | ||
Layout/HashAlignment: | ||
EnforcedHashRocketStyle: table | ||
Layout/LineLength: | ||
Enabled: false | ||
Metrics/AbcSize: | ||
Enabled: false | ||
Metrics/BlockLength: | ||
Enabled: false | ||
Metrics/ClassLength: | ||
Enabled: false | ||
Metrics/CyclomaticComplexity: | ||
Enabled: false | ||
Metrics/MethodLength: | ||
Enabled: false | ||
Metrics/ParameterLists: | ||
Enabled: false | ||
Metrics/PerceivedComplexity: | ||
Enabled: false | ||
RSpec/SubjectStub: | ||
Enabled: false | ||
Style/Documentation: | ||
Enabled: false | ||
Style/NumericLiterals: | ||
Enabled: false | ||
Style/TrailingCommaInArguments: | ||
EnforcedStyleForMultiline: consistent_comma | ||
Style/TrailingCommaInArrayLiteral: | ||
EnforcedStyleForMultiline: consistent_comma | ||
Style/TrailingCommaInHashLiteral: | ||
EnforcedStyleForMultiline: consistent_comma | ||
Layout/FirstArrayElementIndentation: | ||
EnforcedStyle: consistent | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
# vim:set syntax=ruby: | ||
|
||
SimpleCov.start do | ||
add_filter '/spec/' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in riemann-tools.gemspec | ||
gemspec | ||
|
||
gem 'github_changelog_generator' | ||
gem 'rake' | ||
gem 'rspec' | ||
gem 'rubocop' | ||
gem 'rubocop-rake' | ||
gem 'rubocop-rspec' | ||
gem 'simplecov' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# riemann-syslog-ng | ||
|
||
[![CI](https://github.com/opus-codium/riemann-syslog-ng/actions/workflows/ci.yml/badge.svg)](https://github.com/opus-codium/riemann-syslog-ng/actions/workflows/ci.yml) | ||
[![Maintainability](https://api.codeclimate.com/v1/badges/c98331204e2fdc0a7093/maintainability)](https://codeclimate.com/github/opus-codium/riemann-syslog-ng/maintainability) | ||
[![Test Coverage](https://api.codeclimate.com/v1/badges/c98331204e2fdc0a7093/test_coverage)](https://codeclimate.com/github/opus-codium/riemann-syslog-ng/test_coverage) | ||
|
||
Submits syslog-ng information to riemann. | ||
|
||
## Get started | ||
|
||
``` | ||
gem install riemann-syslog-ng | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'riemann/tools/syslog_ng/version' | ||
|
||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
task default: :spec | ||
|
||
require 'github_changelog_generator/task' | ||
|
||
GitHubChangelogGenerator::RakeTask.new :changelog do |config| | ||
config.user = 'opus-codium' | ||
config.project = 'riemann-syslog-ng' | ||
config.exclude_labels = ['skip-changelog'] | ||
config.future_release = "v#{Riemann::Tools::SyslogNg::VERSION}" | ||
config.since_tag = 'v1.0.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
Process.setproctitle($PROGRAM_NAME) | ||
|
||
require 'riemann/tools/syslog_ng' | ||
|
||
Riemann::Tools::SyslogNg.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'strscan' | ||
|
||
require 'riemann/tools' | ||
|
||
module Riemann | ||
module Tools | ||
class SyslogNg | ||
include Riemann::Tools | ||
|
||
opt :socket, 'Path to syslog-ng socket', short: :none, type: :string, default: '/var/lib/syslog-ng/syslog-ng.ctl' | ||
opt :format, 'Format for service name', short: :none, type: :string, default: '%<source_name>s;%<source_id>s;%<source_instance>s;%<state>s;%<type>s' | ||
|
||
opt :source_name, 'Filter on SourceName', short: :none, type: :strings | ||
opt :source_id, 'Filter on SourceId', short: :none, type: :strings | ||
opt :source_instance, 'Filter on SourceInstance', short: :none, type: :strings | ||
opt :state, 'Filter on State', short: :none, type: :strings | ||
opt :type, 'Filter on Type', short: :none, type: :strings | ||
|
||
opt :queued_warning, 'Queued messages warning threshold', short: :none, default: 300 | ||
opt :queued_critical, 'Queued messages critical threshold', short: :none, default: 1000 | ||
|
||
def self.process_stdin | ||
new.process_stdin | ||
end | ||
|
||
def initialize | ||
@socket = UNIXSocket.new(opts[:socket]) | ||
end | ||
|
||
def tick | ||
statistics.each do |statistic| | ||
report({ | ||
service: format(opts[:format], statistic), | ||
metric: statistic[:metric], | ||
state: statistic_state(statistic[:type], statistic[:metric]), | ||
}) | ||
end | ||
end | ||
|
||
def statistics | ||
res = [] | ||
|
||
@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 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) | ||
|
||
res << { | ||
source_name: source_name, | ||
source_id: source_id, | ||
source_instance: source_instance, | ||
state: state, | ||
type: type, | ||
metric: metric.to_f, | ||
} | ||
end | ||
|
||
res | ||
end | ||
|
||
def statistic_state(type, metric) | ||
if type == 'dropped' | ||
metric == 0.0 ? 'ok' : 'critical' | ||
elsif type == 'queued' | ||
if metric >= opts[:queued_critical] | ||
'critical' | ||
elsif metric >= opts[:queued_warning] | ||
'warning' | ||
else | ||
'ok' | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module Riemann | ||
module Tools # :nodoc: | ||
class SyslogNg | ||
VERSION = '1.0.0' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'lib/riemann/tools/syslog_ng/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'riemann-syslog-ng' | ||
spec.version = Riemann::Tools::SyslogNg::VERSION | ||
spec.authors = ['Romain Tartière'] | ||
spec.email = ['[email protected]'] | ||
|
||
spec.summary = 'Submits syslog-ng information to riemann' | ||
spec.homepage = 'https://github.com/opus-codium/riemann-syslog-ng' | ||
spec.license = 'MIT' | ||
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0') | ||
|
||
spec.metadata['allowed_push_host'] = 'https://rubygems.org/' | ||
|
||
spec.metadata['homepage_uri'] = spec.homepage | ||
spec.metadata['source_code_uri'] = spec.homepage | ||
spec.metadata['changelog_uri'] = spec.homepage | ||
|
||
spec.metadata['rubygems_mfa_required'] = 'true' | ||
|
||
# Specify which files should be added to the gem when it is released. | ||
# The `git ls-files -z` loads the files in the RubyGem that have been added into git. | ||
spec.files = Dir.chdir(File.expand_path(__dir__)) do | ||
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } | ||
end | ||
spec.bindir = 'bin' | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.require_paths = ['lib'] | ||
|
||
spec.add_runtime_dependency 'riemann-tools', '~> 1.0' | ||
end |
Oops, something went wrong.