riemann-syslog-ng 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f8296216cfac86bd15e8a9e7c432f515e23baa06bd20120fd589adb5bef0fbff
4
+ data.tar.gz: e8f8021b906ceb2192b33c42f1412031271efe1c486cbca40eef0413cce8f537
5
+ SHA512:
6
+ metadata.gz: e5864d1c7796df2aa8defd106231de7ccc016a58c8f6d527935bed9a760d2bd27cf4d0079357637f13093d83f58487564c50bfdb94451dccb3209f45b7622f53
7
+ data.tar.gz: bf368924284180e7f2d9c134b7d8d50a577e3890203b88638e8d63cdf5f8e905104cc0fa65debf90fc84338d4a47a026f4412103ebe87d4b38f9789dfda30a86
@@ -0,0 +1 @@
1
+ * @opus-codium/core @opus-codium/vittoria-conseil
@@ -0,0 +1,53 @@
1
+ ---
2
+ name: CI
3
+
4
+ on:
5
+ push:
6
+ branches:
7
+ - main
8
+ pull_request:
9
+ branches:
10
+ - main
11
+
12
+ jobs:
13
+ rubocop:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v3
17
+ - name: Setup ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: 3.0
21
+ bundler-cache: true
22
+ - name: Run static code analysis
23
+ run: bundle exec rubocop
24
+ unit:
25
+ runs-on: ubuntu-latest
26
+ needs: rubocop
27
+ strategy:
28
+ matrix:
29
+ ruby:
30
+ - "2.6"
31
+ - "2.7"
32
+ - "3.0"
33
+ - "3.1"
34
+ - "3.2"
35
+ - "3.3"
36
+ name: Ruby ${{ matrix.ruby }}
37
+ steps:
38
+ - uses: actions/checkout@v3
39
+ - name: Setup ruby
40
+ uses: ruby/setup-ruby@v1
41
+ with:
42
+ ruby-version: ${{ matrix.ruby }}
43
+ bundler-cache: true
44
+ - name: Run tests without uploading code coverage
45
+ if: ${{ matrix.ruby != '3.0' }}
46
+ run: bundle exec rake
47
+ - name: Run tests and upload coverage to Code Climate
48
+ if: ${{ matrix.ruby == '3.0' }}
49
+ uses: paambaati/codeclimate-action@v3.1.1
50
+ env:
51
+ CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_TOKEN }}
52
+ with:
53
+ coverageCommand: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,43 @@
1
+ ---
2
+ AllCops:
3
+ TargetRubyVersion: '2.6'
4
+ AllowSymlinksInCacheRootDirectory: true
5
+ NewCops: enable
6
+ Exclude:
7
+ - vendor/bundle/**/*
8
+ require:
9
+ - rubocop-rake
10
+ - rubocop-rspec
11
+ Layout/HashAlignment:
12
+ EnforcedHashRocketStyle: table
13
+ Layout/LineLength:
14
+ Enabled: false
15
+ Metrics/AbcSize:
16
+ Enabled: false
17
+ Metrics/BlockLength:
18
+ Enabled: false
19
+ Metrics/ClassLength:
20
+ Enabled: false
21
+ Metrics/CyclomaticComplexity:
22
+ Enabled: false
23
+ Metrics/MethodLength:
24
+ Enabled: false
25
+ Metrics/ParameterLists:
26
+ Enabled: false
27
+ Metrics/PerceivedComplexity:
28
+ Enabled: false
29
+ RSpec/SubjectStub:
30
+ Enabled: false
31
+ Style/Documentation:
32
+ Enabled: false
33
+ Style/NumericLiterals:
34
+ Enabled: false
35
+ Style/TrailingCommaInArguments:
36
+ EnforcedStyleForMultiline: consistent_comma
37
+ Style/TrailingCommaInArrayLiteral:
38
+ EnforcedStyleForMultiline: consistent_comma
39
+ Style/TrailingCommaInHashLiteral:
40
+ EnforcedStyleForMultiline: consistent_comma
41
+ Layout/FirstArrayElementIndentation:
42
+ EnforcedStyle: consistent
43
+
data/.simplecov ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # vim:set syntax=ruby:
4
+
5
+ SimpleCov.start do
6
+ add_filter '/spec/'
7
+ end
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in riemann-tools.gemspec
6
+ gemspec
7
+
8
+ gem 'github_changelog_generator'
9
+ gem 'rake'
10
+ gem 'rspec'
11
+ gem 'rubocop'
12
+ gem 'rubocop-rake'
13
+ gem 'rubocop-rspec'
14
+ gem 'simplecov'
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # riemann-syslog-ng
2
+
3
+ [![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)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/c98331204e2fdc0a7093/maintainability)](https://codeclimate.com/github/opus-codium/riemann-syslog-ng/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/c98331204e2fdc0a7093/test_coverage)](https://codeclimate.com/github/opus-codium/riemann-syslog-ng/test_coverage)
6
+
7
+ Submits syslog-ng information to riemann.
8
+
9
+ ## Get started
10
+
11
+ ```
12
+ gem install riemann-syslog-ng
13
+ ```
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'riemann/tools/syslog_ng/version'
4
+
5
+ require 'bundler/gem_tasks'
6
+ require 'rspec/core/rake_task'
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task default: :spec
11
+
12
+ require 'github_changelog_generator/task'
13
+
14
+ GitHubChangelogGenerator::RakeTask.new :changelog do |config|
15
+ config.user = 'opus-codium'
16
+ config.project = 'riemann-syslog-ng'
17
+ config.exclude_labels = ['skip-changelog']
18
+ config.future_release = "v#{Riemann::Tools::SyslogNg::VERSION}"
19
+ config.since_tag = 'v1.0.0'
20
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ Process.setproctitle($PROGRAM_NAME)
5
+
6
+ require 'riemann/tools/syslog_ng'
7
+
8
+ Riemann::Tools::SyslogNg.run
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Riemann
4
+ module Tools # :nodoc:
5
+ class SyslogNg
6
+ VERSION = '1.0.0'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'strscan'
4
+
5
+ require 'riemann/tools'
6
+
7
+ module Riemann
8
+ module Tools
9
+ class SyslogNg
10
+ include Riemann::Tools
11
+
12
+ opt :socket, 'Path to syslog-ng socket', short: :none, type: :string, default: '/var/lib/syslog-ng/syslog-ng.ctl'
13
+ opt :format, 'Format for service name', short: :none, type: :string, default: '%<source_name>s;%<source_id>s;%<source_instance>s;%<state>s;%<type>s'
14
+
15
+ opt :source_name, 'Filter on SourceName', short: :none, type: :strings
16
+ opt :source_id, 'Filter on SourceId', short: :none, type: :strings
17
+ opt :source_instance, 'Filter on SourceInstance', short: :none, type: :strings
18
+ opt :state, 'Filter on State', short: :none, type: :strings
19
+ opt :type, 'Filter on Type', short: :none, type: :strings
20
+
21
+ opt :queued_warning, 'Queued messages warning threshold', short: :none, default: 300
22
+ opt :queued_critical, 'Queued messages critical threshold', short: :none, default: 1000
23
+
24
+ def self.process_stdin
25
+ new.process_stdin
26
+ end
27
+
28
+ def initialize
29
+ @socket = UNIXSocket.new(opts[:socket])
30
+ end
31
+
32
+ def tick
33
+ statistics.each do |statistic|
34
+ report({
35
+ service: format(opts[:format], statistic),
36
+ metric: statistic[:metric],
37
+ state: statistic_state(statistic[:type], statistic[:metric]),
38
+ })
39
+ end
40
+ end
41
+
42
+ def statistics
43
+ res = []
44
+
45
+ @socket.puts 'STATS CSV'
46
+ @socket.gets # discard header
47
+ while (line = @socket.gets.chomp) != '.'
48
+ source_name, source_id, source_instance, state, type, metric = line.split(';')
49
+
50
+ next if opts[:source_name] && !opts[:source_name].include?(source_name)
51
+ next if opts[:source_id] && !opts[:source_id].include?(source_id)
52
+ next if opts[:source_instance] && !opts[:source_instance].include?(source_instance)
53
+ next if opts[:state] && !opts[:state].include?(state)
54
+ next if opts[:type] && !opts[:type].include?(type)
55
+
56
+ res << {
57
+ source_name: source_name,
58
+ source_id: source_id,
59
+ source_instance: source_instance,
60
+ state: state,
61
+ type: type,
62
+ metric: metric.to_f,
63
+ }
64
+ end
65
+
66
+ res
67
+ end
68
+
69
+ def statistic_state(type, metric)
70
+ if type == 'dropped'
71
+ metric == 0.0 ? 'ok' : 'critical'
72
+ elsif type == 'queued'
73
+ if metric >= opts[:queued_critical]
74
+ 'critical'
75
+ elsif metric >= opts[:queued_warning]
76
+ 'warning'
77
+ else
78
+ 'ok'
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/riemann/tools/syslog_ng/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'riemann-syslog-ng'
7
+ spec.version = Riemann::Tools::SyslogNg::VERSION
8
+ spec.authors = ['Romain Tartière']
9
+ spec.email = ['romain@blogreen.org']
10
+
11
+ spec.summary = 'Submits syslog-ng information to riemann'
12
+ spec.homepage = 'https://github.com/opus-codium/riemann-syslog-ng'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
15
+
16
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = spec.homepage
20
+ spec.metadata['changelog_uri'] = spec.homepage
21
+
22
+ spec.metadata['rubygems_mfa_required'] = 'true'
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = 'bin'
30
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_runtime_dependency 'riemann-tools', '~> 1.0'
34
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: riemann-syslog-ng
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Romain Tartière
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-01-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: riemann-tools
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description:
28
+ email:
29
+ - romain@blogreen.org
30
+ executables:
31
+ - riemann-syslog-ng
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".github/CODEOWNERS"
36
+ - ".github/workflows/ci.yml"
37
+ - ".gitignore"
38
+ - ".rspec"
39
+ - ".rubocop.yml"
40
+ - ".simplecov"
41
+ - Gemfile
42
+ - README.md
43
+ - Rakefile
44
+ - bin/riemann-syslog-ng
45
+ - lib/riemann/tools/syslog_ng.rb
46
+ - lib/riemann/tools/syslog_ng/version.rb
47
+ - riemann-syslog-ng.gemspec
48
+ homepage: https://github.com/opus-codium/riemann-syslog-ng
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ allowed_push_host: https://rubygems.org/
53
+ homepage_uri: https://github.com/opus-codium/riemann-syslog-ng
54
+ source_code_uri: https://github.com/opus-codium/riemann-syslog-ng
55
+ changelog_uri: https://github.com/opus-codium/riemann-syslog-ng
56
+ rubygems_mfa_required: 'true'
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 2.6.0
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.3.15
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Submits syslog-ng information to riemann
76
+ test_files: []