syslog_generator 1.0.3 → 1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +1 -2
- data/bin/loggen +18 -4
- data/lib/syslog_generator.rb +52 -18
- data/lib/syslog_generator/version.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ea00844536286b7a35920e5fcdb297bd63aa72e
|
4
|
+
data.tar.gz: f7ae016391982ca2c5bcd3f6e26155194d2915e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87b95be36f0cb72f6a7e3c727738e009212ed59528feb5ab148018ad82d0b3d4ba1a9de3378f1999c7e78141c940cae6e732006bf720b65ee445c2031e06b309
|
7
|
+
data.tar.gz: aea3e051459c37d627172ea31cb74f0f8af60635ccd74aba2058beb770a422cfa8033a9f5ce9842dbb1b81b72214ba7c400534a93fbdf8ec8f81afffff19cd76
|
data/Rakefile
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/loggen
CHANGED
@@ -1,12 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'syslog_generator'
|
3
|
-
require 'trollop'
|
4
3
|
require 'syslog_generator/version'
|
4
|
+
require 'syslog_protocol'
|
5
|
+
require 'trollop'
|
6
|
+
|
7
|
+
# Drop the : from the severities hash when presenting it to the user
|
8
|
+
valid_priorities_list = SyslogProtocol::SEVERITIES.keys.each do |k|
|
9
|
+
k.to_s.gsub(':', '')
|
10
|
+
end
|
11
|
+
|
5
12
|
opts = Trollop.options do
|
6
|
-
version "loggen #{SyslogGenerator::VERSION}
|
13
|
+
version "loggen #{SyslogGenerator::VERSION}
|
14
|
+
APL, Michael Parks, TKWare Enteprises <mparks@tkware.info>"
|
7
15
|
banner <<-EOS
|
8
16
|
Generate random syslog lines according to the provided options.
|
9
|
-
Absent any options, 100 lines of nonsense will be sent to the syslog port on
|
17
|
+
Absent any options, 100 lines of nonsense will be sent to the syslog port on
|
18
|
+
the local machine (localhost).
|
10
19
|
|
11
20
|
Usage: loggen [options]
|
12
21
|
|
@@ -14,12 +23,17 @@ Where [options] can be any of the following:
|
|
14
23
|
EOS
|
15
24
|
opt :count, 'Count of lines to generate. Set to -1 for infinite.', type: Integer, default: 100
|
16
25
|
opt :words, 'Words per line', type: Integer, default: 5
|
17
|
-
opt :
|
26
|
+
opt :name, 'Program name attached to each log line', type: String, default: 'log_generator'
|
18
27
|
opt :test, 'Send lines to stdout rather than a remote server'
|
19
28
|
opt :server, 'Send lines to this remote server', type: String, default: 'localhost'
|
20
29
|
opt :facility, 'Syslog facility to use', type: String, default: 'local6'
|
21
30
|
opt :protocol, 'TCP or UDP', type: String, default: 'udp'
|
22
31
|
opt :port, 'Port number to send generated lines to', type: Integer, default: 514
|
32
|
+
opt :priority, "Message priority, must be one of: #{valid_priorities_list}", type: String, default: 'info'
|
33
|
+
end
|
34
|
+
|
35
|
+
if SyslogProtocol::SEVERITIES.keys.grep(opts[:priority]).empty?
|
36
|
+
Trollop.die :priority, "Must be one of #{valid_priorities_list}"
|
23
37
|
end
|
24
38
|
|
25
39
|
logger = SyslogGenerator::Logger.new(opts)
|
data/lib/syslog_generator.rb
CHANGED
@@ -1,38 +1,72 @@
|
|
1
|
-
require
|
1
|
+
require 'syslog_generator/version'
|
2
2
|
require 'random-word'
|
3
3
|
require 'syslog_protocol'
|
4
4
|
require 'socket'
|
5
|
-
|
6
|
-
# Initialize a new logger endpoint, setting up the appropriate socket from
|
5
|
+
require 'pry'
|
6
|
+
# Initialize a new logger endpoint, setting up the appropriate socket from
|
7
|
+
# the provided options.
|
7
8
|
module SyslogGenerator
|
9
|
+
# Implementation of a log formatter/sender
|
8
10
|
class Logger
|
9
11
|
attr_accessor :options
|
10
12
|
|
13
|
+
private
|
14
|
+
|
15
|
+
def initialize_socket(options)
|
16
|
+
case options[:protocol].downcase
|
17
|
+
when 'udp'
|
18
|
+
UDPSocket.new
|
19
|
+
when 'tcp'
|
20
|
+
TCPSocket.new
|
21
|
+
else fail 'Invalid protocol specified.'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def gen_payload(text)
|
26
|
+
# Syslog_protocol uses different methods for each priority
|
27
|
+
# (@formatter.debug, @formatter.emerg, etc) so we use .method to save the
|
28
|
+
# call with the appropriate name, and .call to invoke it with the right
|
29
|
+
# string. This won't be likely to break since we check for valid names
|
30
|
+
# back at options parsing.
|
31
|
+
meta_formatter = @formatter.method(options[:priority])
|
32
|
+
if text.is_a?(Array)
|
33
|
+
@payload = meta_formatter.call(text.join(' '))
|
34
|
+
else
|
35
|
+
@payload = meta_formatter.call(info(text))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def gen_words
|
40
|
+
RandomWord.nouns.take(options[:words])
|
41
|
+
end
|
42
|
+
|
43
|
+
public
|
44
|
+
|
11
45
|
def initialize(options)
|
12
46
|
self.options = options
|
13
|
-
|
14
|
-
@
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
47
|
+
# TODO: Won't work on systems that don't have `hostname`?
|
48
|
+
@formatter = SyslogProtocol::Logger.new(
|
49
|
+
`hostname`.strip,
|
50
|
+
options[:name],
|
51
|
+
options[:facility]
|
52
|
+
)
|
53
|
+
@socket = initialize_socket(options)
|
21
54
|
end
|
22
55
|
|
23
56
|
def send(text)
|
24
|
-
|
25
|
-
|
57
|
+
if options[:test]
|
58
|
+
puts(gen_payload(text))
|
59
|
+
else
|
60
|
+
@socket.send(gen_payload(text), 0, options[:server], options[:port])
|
61
|
+
end
|
26
62
|
end
|
27
63
|
|
28
64
|
def start
|
29
|
-
if
|
30
|
-
|
65
|
+
if options[:count] != -1
|
66
|
+
options[:count].times { send(gen_words) }
|
31
67
|
else
|
32
|
-
loop {
|
68
|
+
loop { send(gen_words) }
|
33
69
|
end
|
34
70
|
end
|
35
|
-
|
36
71
|
end
|
37
72
|
end
|
38
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syslog_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: '1.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Parks
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|