nsca 0.2.1 → 0.3.0
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 +7 -0
- data/Gemfile.lock +62 -26
- data/README.md +17 -3
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/nsca.rb +53 -0
- data/lib/nsca/check.rb +6 -1
- data/lib/nsca/client.rb +13 -6
- data/lib/nsca/packet.rb +30 -42
- data/lib/nsca/server.rb +24 -10
- data/nsca.gemspec +7 -6
- data/test/test_nsca.rb +29 -19
- metadata +23 -42
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f7bad3776e72736980c1f0bf4c5fcd4a39db232a
|
4
|
+
data.tar.gz: e3d3f7d60fb9912288e99b002dcdeb97f0650164
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e7ea2395529fa34d0afd003423cc4b9dc535b2474ee567514477a0f5a310593e061a462d1672cdcd63742e0ccc04e2693c10d04b12ff2a1703c11d8ba3d56709
|
7
|
+
data.tar.gz: 8df53495e054d1bda4704c86f5bc88aab0bc305ed3856982494536b2b8f4511cda02c1e55707b22b9d26d3431b036600da16328ea58e08782e3c57c26dd49164
|
data/Gemfile.lock
CHANGED
@@ -1,39 +1,75 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activesupport (
|
5
|
-
i18n (
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
activesupport (4.2.3)
|
5
|
+
i18n (~> 0.7)
|
6
|
+
json (~> 1.7, >= 1.7.7)
|
7
|
+
minitest (~> 5.1)
|
8
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
9
|
+
tzinfo (~> 1.1)
|
10
|
+
addressable (2.3.8)
|
11
|
+
builder (3.2.2)
|
12
|
+
descendants_tracker (0.0.4)
|
13
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
14
|
+
docile (1.1.5)
|
9
15
|
enum (1.0.0)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
16
|
+
faraday (0.9.1)
|
17
|
+
multipart-post (>= 1.2, < 3)
|
18
|
+
git (1.2.9.1)
|
19
|
+
github_api (0.12.3)
|
20
|
+
addressable (~> 2.3)
|
21
|
+
descendants_tracker (~> 0.0.4)
|
22
|
+
faraday (~> 0.8, < 0.10)
|
23
|
+
hashie (>= 3.3)
|
24
|
+
multi_json (>= 1.7.5, < 2.0)
|
25
|
+
nokogiri (~> 1.6.3)
|
26
|
+
oauth2
|
27
|
+
hashie (3.4.2)
|
28
|
+
highline (1.7.2)
|
29
|
+
i18n (0.7.0)
|
30
|
+
jeweler (2.0.1)
|
31
|
+
builder
|
32
|
+
bundler (>= 1.0)
|
14
33
|
git (>= 1.2.5)
|
34
|
+
github_api
|
35
|
+
highline (>= 1.6.15)
|
36
|
+
nokogiri (>= 1.5.10)
|
15
37
|
rake
|
16
38
|
rdoc
|
17
|
-
json (1.
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
multi_json (1.
|
22
|
-
|
23
|
-
|
39
|
+
json (1.8.3)
|
40
|
+
jwt (1.5.1)
|
41
|
+
mini_portile (0.6.2)
|
42
|
+
minitest (5.7.0)
|
43
|
+
multi_json (1.11.2)
|
44
|
+
multi_xml (0.5.5)
|
45
|
+
multipart-post (2.0.0)
|
46
|
+
nokogiri (1.6.6.2)
|
47
|
+
mini_portile (~> 0.6.0)
|
48
|
+
oauth2 (1.0.0)
|
49
|
+
faraday (>= 0.8, < 0.10)
|
50
|
+
jwt (~> 1.0)
|
51
|
+
multi_json (~> 1.3)
|
52
|
+
multi_xml (~> 0.5)
|
53
|
+
rack (~> 1.2)
|
54
|
+
rack (1.6.4)
|
55
|
+
rake (10.4.2)
|
56
|
+
rdoc (4.2.0)
|
24
57
|
json (~> 1.4)
|
25
|
-
shoulda (3.
|
58
|
+
shoulda (3.5.0)
|
26
59
|
shoulda-context (~> 1.0, >= 1.0.1)
|
27
|
-
shoulda-matchers (
|
28
|
-
shoulda-context (1.1
|
29
|
-
shoulda-matchers (
|
60
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
61
|
+
shoulda-context (1.2.1)
|
62
|
+
shoulda-matchers (2.8.0)
|
30
63
|
activesupport (>= 3.0.0)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
simplecov-html (~> 0.
|
35
|
-
simplecov-html (0.
|
36
|
-
|
64
|
+
simplecov (0.10.0)
|
65
|
+
docile (~> 1.1.0)
|
66
|
+
json (~> 1.8)
|
67
|
+
simplecov-html (~> 0.10.0)
|
68
|
+
simplecov-html (0.10.0)
|
69
|
+
thread_safe (0.3.5)
|
70
|
+
tzinfo (1.2.2)
|
71
|
+
thread_safe (~> 0.1)
|
72
|
+
yard (0.8.7.6)
|
37
73
|
|
38
74
|
PLATFORMS
|
39
75
|
ruby
|
data/README.md
CHANGED
@@ -8,7 +8,22 @@ This is a ruby-pure implementation.
|
|
8
8
|
|
9
9
|
First it was planed to provide a client-API, but now there is also a full server-API.
|
10
10
|
|
11
|
-
Tested against nsca-2.7.
|
11
|
+
Tested against nsca-2.7, -2.9.
|
12
|
+
|
13
|
+
Usage
|
14
|
+
=====
|
15
|
+
|
16
|
+
Simple sending:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
NSCA.destinations << NSCA::Client.new('localhost')
|
20
|
+
NSCA.send 'serverA', 'serviceA', 1, 'Ok'
|
21
|
+
```
|
22
|
+
|
23
|
+
Checks:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
```
|
12
27
|
|
13
28
|
TO DO AND DONE
|
14
29
|
==============
|
@@ -34,5 +49,4 @@ DONE
|
|
34
49
|
Copyright
|
35
50
|
=========
|
36
51
|
|
37
|
-
Copyright (c) 2013 Denis Knauf. See LICENSE.txt for
|
38
|
-
further details.
|
52
|
+
Copyright (c) 2013-2015 Denis Knauf. See [LICENSE.txt](LICENSE.txt) for further details.
|
data/Rakefile
CHANGED
@@ -15,7 +15,7 @@ require 'jeweler'
|
|
15
15
|
Jeweler::Tasks.new do |gem|
|
16
16
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
17
|
gem.name = "nsca"
|
18
|
-
gem.homepage = "http://github.com/DenisKnauf/nsca"
|
18
|
+
gem.homepage = "http://github.com/DenisKnauf/ruby-nsca"
|
19
19
|
gem.license = "LGPL-3"
|
20
20
|
gem.summary = %Q{Nagios passive alerts with friendly API}
|
21
21
|
gem.description = %Q{Create your alerts easily and send it to Nagios}
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/nsca.rb
CHANGED
@@ -18,6 +18,35 @@ module NSCA
|
|
18
18
|
clname[0] = clname[0].upcase
|
19
19
|
clname.to_sym
|
20
20
|
end
|
21
|
+
|
22
|
+
def xor_stream key
|
23
|
+
key = case key
|
24
|
+
when Array then key
|
25
|
+
when String then key.bytes.to_a
|
26
|
+
when Enumerable then key.to_a
|
27
|
+
end
|
28
|
+
return lambda{|x|x} if [nil, '', []].include? key
|
29
|
+
length = key.length
|
30
|
+
i = 0
|
31
|
+
lambda do |str|
|
32
|
+
r = ''
|
33
|
+
str.bytes.each_with_index do |c, j|
|
34
|
+
r[j] = (c ^ key[i]).chr
|
35
|
+
i = (i + 1) % length
|
36
|
+
end
|
37
|
+
r
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def crc32_stream
|
42
|
+
sum = 0xFFFFFFFF
|
43
|
+
lambda do |str|
|
44
|
+
sum = str.bytes.inject sum do |r, b|
|
45
|
+
8.times.inject( r^b) {|r,_i| (r>>1) ^ (0xEDB88320 * (r&1)) }
|
46
|
+
end if str
|
47
|
+
sum ^ 0xFFFFFFFF
|
48
|
+
end
|
49
|
+
end
|
21
50
|
end
|
22
51
|
end
|
23
52
|
|
@@ -28,6 +57,30 @@ module NSCA
|
|
28
57
|
NSCA.destinations.each {|server| server.send *results }
|
29
58
|
self
|
30
59
|
end
|
60
|
+
|
61
|
+
def xor key, msg = nil, key_a = nil
|
62
|
+
NSCA::Helper.xor_stream( key_a || key)[ msg]
|
63
|
+
end
|
64
|
+
|
65
|
+
def crc32 msg
|
66
|
+
NSCA::Helper.crc32_stream[ msg]
|
67
|
+
end
|
68
|
+
|
69
|
+
# Builds a null terminated, null padded string of length maxlen
|
70
|
+
def str2cstr str, maxlen = nil
|
71
|
+
str = str.to_s
|
72
|
+
str = str.to_s[0..(maxlen-2)] if maxlen
|
73
|
+
"#{str}\x00"
|
74
|
+
end
|
75
|
+
def rand_padding( str, maxlen) str + SecureRandom.random_bytes( maxlen - str.length) end
|
76
|
+
def str2cstr_rand_padding( str, maxlen = nil) rand_padding str2cstr( str, maxlen), maxlen end
|
77
|
+
def str2nstr str, maxlen = nil
|
78
|
+
str = str.to_s.gsub ' ', "\x00"
|
79
|
+
"#{str} "
|
80
|
+
end
|
81
|
+
def str2nstr_rand_padding( str, maxlen = nil) rand_padding str2nstr( str, maxlen), maxlen end
|
82
|
+
def cstr2str( str, maxlen = nil) str[ 0, str.index( ?\0) || ((maxlen||str.length+1)-1)] end
|
83
|
+
def nstr2str( str, maxlen = nil) str[ 0, str.index( ' ') || ((maxlen||str.length+1)-1)].gsub( "\x00", ' ') end
|
31
84
|
end
|
32
85
|
end
|
33
86
|
|
data/lib/nsca/check.rb
CHANGED
@@ -51,7 +51,7 @@ module NSCA
|
|
51
51
|
def min() self.class.min end
|
52
52
|
def max() self.class.max end
|
53
53
|
def to_a() [label, value, unit, warn, crit, min, max] end
|
54
|
-
def to_s() "#{label}=#{value}#{unit},#{warn},#{crit},#{min},#{max}" end
|
54
|
+
def to_s() "'#{label.gsub /[\n'\|]/, ''}'=#{value}#{unit},#{warn},#{crit},#{min},#{max}" end
|
55
55
|
def to_sym() self.class.to_sym end
|
56
56
|
|
57
57
|
def to_h
|
@@ -163,6 +163,11 @@ module NSCA
|
|
163
163
|
{timestamp: timestamp, return_code: retcode, hostname: hostname, server: service, status: text}
|
164
164
|
end
|
165
165
|
|
166
|
+
def to_packet version = nil
|
167
|
+
version ||= PacketV3
|
168
|
+
version.new timestamp, retcode, hostname, service, text
|
169
|
+
end
|
170
|
+
|
166
171
|
class <<self
|
167
172
|
attr_reader :service, :hostname, :perfdatas
|
168
173
|
def init *args
|
data/lib/nsca/client.rb
CHANGED
@@ -61,19 +61,26 @@ module NSCA
|
|
61
61
|
# @param [String(length<512)] status Status-line inclusive optional Performance Data.
|
62
62
|
def build_packet timestamp, return_code, hostname, service, status
|
63
63
|
packet = @packet_version.new timestamp || @timestamp, return_code, hostname, service, status
|
64
|
-
packet.build
|
64
|
+
packet.build
|
65
65
|
end
|
66
66
|
|
67
67
|
# Sends a check-result.
|
68
68
|
# @see #build_packet
|
69
|
-
def send_packet( *a)
|
69
|
+
def send_packet( *a)
|
70
|
+
packet = case a.first
|
71
|
+
when NSCA::Packet then a.first.build
|
72
|
+
when NSCA::Check::Base then a.first.to_packet( @packet_version).build
|
73
|
+
else build_packet( *a)
|
74
|
+
end
|
75
|
+
packet = NSCA::xor @iv_key, packet
|
76
|
+
packet = NSCA::xor @password, packet
|
77
|
+
@socket.write packet
|
78
|
+
end
|
70
79
|
|
71
80
|
# Sends check-results
|
72
81
|
# @param [Array<NSCA::Check::Base>] results
|
73
82
|
def send *results
|
74
|
-
results.flatten.each
|
75
|
-
send_packet r.timestamp, r.retcode, r.hostname, r.service, r.text
|
76
|
-
end
|
83
|
+
results.flatten.each &method(:send_packet)
|
77
84
|
end
|
78
85
|
|
79
86
|
# Closes connection to NSCA.
|
@@ -85,7 +92,7 @@ module NSCA
|
|
85
92
|
@hostname, @port, @password = hostname, port, password
|
86
93
|
end
|
87
94
|
|
88
|
-
def open( &e) Connection.open @hostname, @port, @password, &e end
|
95
|
+
def open( &e) Connection.open hostname: @hostname, port: @port, password: @password, &e end
|
89
96
|
def send( *results) open {|conn| conn.send results } end
|
90
97
|
end
|
91
98
|
end
|
data/lib/nsca/packet.rb
CHANGED
@@ -1,29 +1,4 @@
|
|
1
1
|
module NSCA
|
2
|
-
class <<self
|
3
|
-
def xor key, msg, key_a = nil
|
4
|
-
key_a ||= key.unpack 'C*'
|
5
|
-
l = key_a.length
|
6
|
-
return msg if l < 1
|
7
|
-
# Slice the message in parts of length key_a.length.
|
8
|
-
# XOR each char of a part with char at the same index in key_a.
|
9
|
-
msg.unpack( 'C*').each_with_index.map {|c,i| c^key_a[i%l] }.pack 'C*'
|
10
|
-
end
|
11
|
-
|
12
|
-
def crc32 msg
|
13
|
-
(msg.each_byte.inject 0xFFFFFFFF do |r,b|
|
14
|
-
8.times.inject( r^b) {|r,_i| (r>>1) ^ (0xEDB88320 * (r&1)) }
|
15
|
-
end) ^ 0xFFFFFFFF
|
16
|
-
end
|
17
|
-
|
18
|
-
# Builds a null terminated, null padded string of length maxlen
|
19
|
-
def str2cstr( str, maxlen = nil)
|
20
|
-
str = str.to_s
|
21
|
-
str = str.to_s[0..(maxlen-2)] if maxlen
|
22
|
-
"#{str}\x00"
|
23
|
-
end
|
24
|
-
def cstr2str( str, maxlen = nil) str[ 0, x.index( ?\0) || ((maxlen||0)-1)] end
|
25
|
-
end
|
26
|
-
|
27
2
|
class Packet
|
28
3
|
class CSC32CheckFailed <Exception
|
29
4
|
end
|
@@ -57,7 +32,7 @@ module NSCA
|
|
57
32
|
END_OF_TRANSMISSION = ?\x0a
|
58
33
|
HOSTNAME_LENGTH = 64
|
59
34
|
SERVICE_LENGTH = 128
|
60
|
-
|
35
|
+
PLUGIN_OUTPUT_LENGTH = 512
|
61
36
|
|
62
37
|
# these line describes the data package:
|
63
38
|
# typedef struct data_packet_struct{
|
@@ -71,41 +46,54 @@ module NSCA
|
|
71
46
|
# char plugin_output[MAX_PLUGINOUTPUT_LENGTH];
|
72
47
|
# /* two extra padding-xx, too. */
|
73
48
|
# }data_packet;
|
74
|
-
PACK_STRING = "s> xx L> L> s>
|
75
|
-
PACK_LENGTH = 2+2+4+4+2+HOSTNAME_LENGTH+SERVICE_LENGTH+
|
49
|
+
PACK_STRING = "s> xx L> L> s> A#{HOSTNAME_LENGTH} A#{SERVICE_LENGTH} A#{PLUGIN_OUTPUT_LENGTH} xx"
|
50
|
+
PACK_LENGTH = 2+2+4+4+2+HOSTNAME_LENGTH+SERVICE_LENGTH+PLUGIN_OUTPUT_LENGTH+2
|
76
51
|
register_version PACKET_VERSION, self
|
77
52
|
|
78
53
|
# Builds a check-result-line for NSCA.
|
79
54
|
#
|
80
55
|
# Will be terminated by end-of-terminate.
|
81
|
-
def build
|
56
|
+
def build slf = nil
|
57
|
+
cl = (slf || self).class
|
82
58
|
entry = [
|
83
|
-
PACKET_VERSION,
|
59
|
+
cl::PACKET_VERSION,
|
84
60
|
0, # crc32 (unknown yet)
|
85
61
|
(timestamp || Time.now).to_i,
|
86
62
|
return_code.to_i,
|
87
|
-
NSCA::
|
88
|
-
NSCA::
|
89
|
-
NSCA::
|
63
|
+
NSCA::str2cstr_rand_padding( hostname || `hostname -f`, cl::HOSTNAME_LENGTH),
|
64
|
+
NSCA::str2cstr_rand_padding( service, cl::SERVICE_LENGTH),
|
65
|
+
NSCA::str2cstr_rand_padding( status, cl::PLUGIN_OUTPUT_LENGTH) # incl perfdata
|
90
66
|
]
|
91
67
|
# generate crc32 and put it at entry[2...6]
|
92
|
-
entry[1] = NSCA::crc32 entry.pack( PACK_STRING)
|
93
|
-
entry = entry.pack PACK_STRING
|
94
|
-
entry = NSCA::xor key, entry if key
|
95
|
-
entry = NSCA::xor password, entry if password
|
68
|
+
entry[1] = NSCA::crc32 entry.pack( cl::PACK_STRING)
|
69
|
+
entry = entry.pack cl::PACK_STRING
|
96
70
|
entry
|
97
71
|
end
|
98
72
|
|
99
|
-
def self.parse entry,
|
100
|
-
entry =
|
101
|
-
entry = NSCA::xor password, entry if password
|
73
|
+
def self.parse entry, no_verification_checks = nil
|
74
|
+
entry = entry.to_s.dup
|
102
75
|
ver, crc32sum, *x = entry.unpack( PACK_STRING)
|
76
|
+
x[2] = NSCA::cstr2str x[2]
|
77
|
+
x[3] = NSCA::cstr2str x[3]
|
78
|
+
x[4] = NSCA::cstr2str x[4]
|
103
79
|
raise VersionCheckFailed, "Packet version 3 expected. (recv: #{ver})" \
|
104
80
|
unless no_verification_checks or 3 == ver
|
105
81
|
entry[4..7] = ?\x00*4
|
106
|
-
|
107
|
-
|
82
|
+
crc32 = NSCA::crc32 entry
|
83
|
+
raise CSC32CheckFailed, "crc32-check failed. packet seems to be broken: #{crc32sum.inspect} != #{crc32.inspect}" \
|
84
|
+
unless no_verification_checks or crc32sum == crc32
|
108
85
|
new *x
|
109
86
|
end
|
110
87
|
end
|
88
|
+
|
89
|
+
class PacketV3__2_9 < PacketV3
|
90
|
+
NAGIOS_VERSION = 2.7
|
91
|
+
PACKET_VERSION = 3
|
92
|
+
END_OF_TRANSMISSION = ?\x0a
|
93
|
+
PLUGIN_OUTPUT_LENGTH = 4096
|
94
|
+
HOSTNAME_LENGTH = 64
|
95
|
+
SERVICE_LENGTH = 128
|
96
|
+
PACK_STRING = "s> xx L> L> s> A#{HOSTNAME_LENGTH} A#{SERVICE_LENGTH} A#{PLUGIN_OUTPUT_LENGTH} xx"
|
97
|
+
PACK_LENGTH = 2+2+4+4+2+HOSTNAME_LENGTH+SERVICE_LENGTH+PLUGIN_OUTPUT_LENGTH+2
|
98
|
+
end
|
111
99
|
end
|
data/lib/nsca/server.rb
CHANGED
@@ -2,12 +2,12 @@ module NSCA
|
|
2
2
|
class Server
|
3
3
|
include Enumerable
|
4
4
|
|
5
|
-
attr_reader :iv_key, :server, :packet_version, :password
|
5
|
+
attr_reader :iv_key, :server, :packet_version, :password, :xor_iv_key, :xor_password
|
6
6
|
def initialize *args
|
7
7
|
opts = {}
|
8
8
|
opts = args.pop.dup if args.last.is_a? Hash
|
9
9
|
opts[:host] ||= opts[:hostname]
|
10
|
-
opts[:
|
10
|
+
opts[:serv] ||= opts[:server]
|
11
11
|
opts[:pass] ||= opts[:password]
|
12
12
|
|
13
13
|
case args[0]
|
@@ -15,7 +15,7 @@ module NSCA
|
|
15
15
|
opts[:port] = args[0]
|
16
16
|
opts[:host] ||= args[1]
|
17
17
|
when IO
|
18
|
-
opts[:
|
18
|
+
opts[:serv] = args[0]
|
19
19
|
end
|
20
20
|
|
21
21
|
@packet_version = opts[:packet_version] || PacketV3
|
@@ -25,7 +25,7 @@ module NSCA
|
|
25
25
|
@server = if opts[:serv].is_a?( TCPServer) or opts[:serv].is_a?( UNIXServer)
|
26
26
|
opts[:serv]
|
27
27
|
elsif opts[:port].is_a? Integer
|
28
|
-
TCPServer.new *[opts[:
|
28
|
+
TCPServer.new *[opts[:host], opts[:port]].compact
|
29
29
|
else
|
30
30
|
raise ArgumentError, "Server or port-number expected"
|
31
31
|
end
|
@@ -50,22 +50,36 @@ module NSCA
|
|
50
50
|
@packet_version = server.packet_version
|
51
51
|
@packet_length = @packet_version::PACK_LENGTH
|
52
52
|
@socket.write [@iv_key, Time.now.to_i].pack( 'a* L>')
|
53
|
+
@xor_password = NSCA::Helper.xor_stream @password
|
54
|
+
@xor_iv_key = NSCA::Helper.xor_stream @iv_key
|
53
55
|
end
|
54
56
|
|
55
57
|
def fetch
|
56
|
-
|
57
|
-
|
58
|
+
iv_key = NSCA::Helper.xor_stream @iv_key
|
59
|
+
password = NSCA::Helper.xor_stream @password
|
60
|
+
packet_version = iv_key[ password[ read PacketV3::PACKET_VERSION]]
|
61
|
+
v = packet_version.unpack( 's>').first
|
62
|
+
case v
|
63
|
+
when 3
|
64
|
+
data = packet_version + iv_key[ password[ read( PacketV3::PACK_LENGTH - PacketV3::PACKET_VERSION)]]
|
65
|
+
begin
|
66
|
+
return PacketV3.parse( data)
|
67
|
+
rescue NSCA::Packet::CSC32CheckFailed
|
68
|
+
x = read( PacketV3__2_9::PACK_LENGTH - data.length)
|
69
|
+
raise if x.nil?
|
70
|
+
return PacketV3__2_9.parse( data + iv_key[ password[ x]])
|
71
|
+
end
|
72
|
+
else raise "Unknown Version #{v.inspect}"
|
73
|
+
end
|
58
74
|
end
|
59
75
|
|
60
76
|
def each &block
|
61
77
|
return Enumerator.new( self) unless block_given?
|
62
|
-
|
63
|
-
yield data
|
64
|
-
end
|
78
|
+
yield fetch until eof?
|
65
79
|
end
|
66
80
|
|
67
81
|
def eof?() @socket.eof? end
|
68
|
-
def read()
|
82
|
+
def read( len = nil) @socket.read( len || @packet_length) end
|
69
83
|
def close() @socket.close end
|
70
84
|
end
|
71
85
|
end
|
data/nsca.gemspec
CHANGED
@@ -2,14 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: nsca 0.3.0 ruby lib
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
8
|
s.name = "nsca"
|
8
|
-
s.version = "0.
|
9
|
+
s.version = "0.3.0"
|
9
10
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
11
13
|
s.authors = ["Denis Knauf"]
|
12
|
-
s.date = "
|
14
|
+
s.date = "2015-07-16"
|
13
15
|
s.description = "Create your alerts easily and send it to Nagios"
|
14
16
|
s.email = "Denis.Knauf@gmail.com"
|
15
17
|
s.extra_rdoc_files = [
|
@@ -34,14 +36,13 @@ Gem::Specification.new do |s|
|
|
34
36
|
"test/helper.rb",
|
35
37
|
"test/test_nsca.rb"
|
36
38
|
]
|
37
|
-
s.homepage = "http://github.com/DenisKnauf/nsca"
|
39
|
+
s.homepage = "http://github.com/DenisKnauf/ruby-nsca"
|
38
40
|
s.licenses = ["LGPL-3"]
|
39
|
-
s.
|
40
|
-
s.rubygems_version = "1.8.23"
|
41
|
+
s.rubygems_version = "2.2.2"
|
41
42
|
s.summary = "Nagios passive alerts with friendly API"
|
42
43
|
|
43
44
|
if s.respond_to? :specification_version then
|
44
|
-
s.specification_version =
|
45
|
+
s.specification_version = 4
|
45
46
|
|
46
47
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
48
|
s.add_runtime_dependency(%q<enum>, [">= 0"])
|
data/test/test_nsca.rb
CHANGED
@@ -18,20 +18,34 @@ end
|
|
18
18
|
|
19
19
|
class TestNSCACommunication < Test::Unit::TestCase
|
20
20
|
Port = 5787
|
21
|
+
def dummy_server *args
|
22
|
+
server = Thread.new do
|
23
|
+
begin
|
24
|
+
NSCA.dummy_server *args
|
25
|
+
rescue Object
|
26
|
+
#STDERR.puts "#{$!.class}: #{$!}", $!.backtrace.map{|bt|" #{bt}"}
|
27
|
+
raise
|
28
|
+
ensure
|
29
|
+
#STDERR.puts "Dummy Server Shutdown"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
sleep 1 # server needs time to start...
|
33
|
+
server
|
34
|
+
end
|
21
35
|
|
22
36
|
include NSCA::Checks
|
23
37
|
|
24
38
|
context "our dummy test server on localhost:#{Port} with random password" do
|
25
39
|
should 'receive data' do
|
26
|
-
password = SecureRandom.random_bytes
|
40
|
+
password = 'password' || SecureRandom.random_bytes
|
27
41
|
timestamp = Time.now
|
28
42
|
|
29
43
|
PD1 = perfdata :pd1_in_sec, :s, 10, 20, 0, 30
|
30
44
|
PD2 = perfdata :pd2_in_1, 1, 0.99, 0.98, 0, 1
|
31
45
|
PD3 = perfdata :pd3_count, :c, 3, 5, 0
|
32
|
-
T0 = check 'TestNSCA0', '
|
33
|
-
T1 = check 'TestNSCA1', '
|
34
|
-
T2 = check :TestNSCA2, '
|
46
|
+
T0 = check 'TestNSCA0', 'localhost'
|
47
|
+
T1 = check 'TestNSCA1', 'localhost', [PD1, PD2]
|
48
|
+
T2 = check :TestNSCA2, 'localhost', [PD1, PD2, PD3]
|
35
49
|
|
36
50
|
checks = []
|
37
51
|
t0 = T0.new( 1, "0123456789"*51+"AB", nil, timestamp) # oversized service name
|
@@ -44,10 +58,9 @@ class TestNSCACommunication < Test::Unit::TestCase
|
|
44
58
|
checks << t1
|
45
59
|
|
46
60
|
NSCA::destinations.clear
|
47
|
-
NSCA::destinations << NSCA::Client.new( 'localhost', Port, password
|
61
|
+
NSCA::destinations << NSCA::Client.new( 'localhost', Port, password)
|
48
62
|
|
49
|
-
server =
|
50
|
-
sleep 1 # server needs time to start...
|
63
|
+
server = dummy_server port: Port, password: password
|
51
64
|
NSCA::send *checks
|
52
65
|
pc0, pc1 = server.value
|
53
66
|
|
@@ -57,23 +70,20 @@ class TestNSCACommunication < Test::Unit::TestCase
|
|
57
70
|
assert_equal timestamp.to_i, packet.timestamp.to_i
|
58
71
|
assert_equal test.retcode, packet.return_code
|
59
72
|
end
|
60
|
-
# original with
|
61
|
-
assert_equal
|
62
|
-
assert_equal
|
73
|
+
# original with AB, but B is char 512 and will be replaced by \0
|
74
|
+
assert_equal "0123456789"*51+"A", pc0.status
|
75
|
+
assert_equal "Should be OK | 'pd1_in_sec'=3s,10,20,0,30 'pd2_in_1'=0.99961,0.99,0.98,0,1 'pd3_count'=2c,3,5,0,", pc1.status
|
63
76
|
end
|
64
77
|
|
65
78
|
should 'fail crc32 if wrong password' do
|
66
|
-
password = SecureRandom.random_bytes
|
79
|
+
password = 'password' || SecureRandom.random_bytes
|
67
80
|
timestamp = Time.now
|
68
|
-
T3 = check 'TestNSCA0', '
|
81
|
+
T3 = check 'TestNSCA0', 'localhost'
|
69
82
|
NSCA::destinations.clear
|
70
|
-
NSCA::destinations << NSCA::Client.new( 'localhost', Port, password
|
71
|
-
server =
|
72
|
-
|
73
|
-
NSCA::
|
74
|
-
assert_raise NSCA::Packet::CSC32CheckFailed do
|
75
|
-
server.join
|
76
|
-
end
|
83
|
+
NSCA::destinations << NSCA::Client.new( 'localhost', Port, password+'a')
|
84
|
+
server = dummy_server hostname: 'localhost', port: Port, password: password
|
85
|
+
NSCA::send [T3.new( 1, 'status', nil, timestamp)]
|
86
|
+
assert_raise( NSCA::Packet::CSC32CheckFailed) { server.join }
|
77
87
|
end
|
78
88
|
end
|
79
89
|
end
|
metadata
CHANGED
@@ -1,126 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nsca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Denis Knauf
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-07-16 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: enum
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: shoulda
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: yard
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rdoc
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: bundler
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - ">="
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - ">="
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: jeweler
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - ">="
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '0'
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - ">="
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '0'
|
110
97
|
- !ruby/object:Gem::Dependency
|
111
98
|
name: simplecov
|
112
99
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
100
|
requirements:
|
115
|
-
- -
|
101
|
+
- - ">="
|
116
102
|
- !ruby/object:Gem::Version
|
117
103
|
version: '0'
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
107
|
requirements:
|
123
|
-
- -
|
108
|
+
- - ">="
|
124
109
|
- !ruby/object:Gem::Version
|
125
110
|
version: '0'
|
126
111
|
description: Create your alerts easily and send it to Nagios
|
@@ -131,7 +116,7 @@ extra_rdoc_files:
|
|
131
116
|
- LICENSE.txt
|
132
117
|
- README.md
|
133
118
|
files:
|
134
|
-
- .document
|
119
|
+
- ".document"
|
135
120
|
- Gemfile
|
136
121
|
- Gemfile.lock
|
137
122
|
- LICENSE.txt
|
@@ -147,32 +132,28 @@ files:
|
|
147
132
|
- test/dummy_server.rb
|
148
133
|
- test/helper.rb
|
149
134
|
- test/test_nsca.rb
|
150
|
-
homepage: http://github.com/DenisKnauf/nsca
|
135
|
+
homepage: http://github.com/DenisKnauf/ruby-nsca
|
151
136
|
licenses:
|
152
137
|
- LGPL-3
|
138
|
+
metadata: {}
|
153
139
|
post_install_message:
|
154
140
|
rdoc_options: []
|
155
141
|
require_paths:
|
156
142
|
- lib
|
157
143
|
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
-
none: false
|
159
144
|
requirements:
|
160
|
-
- -
|
145
|
+
- - ">="
|
161
146
|
- !ruby/object:Gem::Version
|
162
147
|
version: '0'
|
163
|
-
segments:
|
164
|
-
- 0
|
165
|
-
hash: -638270063
|
166
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
-
none: false
|
168
149
|
requirements:
|
169
|
-
- -
|
150
|
+
- - ">="
|
170
151
|
- !ruby/object:Gem::Version
|
171
152
|
version: '0'
|
172
153
|
requirements: []
|
173
154
|
rubyforge_project:
|
174
|
-
rubygems_version:
|
155
|
+
rubygems_version: 2.2.2
|
175
156
|
signing_key:
|
176
|
-
specification_version:
|
157
|
+
specification_version: 4
|
177
158
|
summary: Nagios passive alerts with friendly API
|
178
159
|
test_files: []
|