lita-netping 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -4
- data/CONTRIBUTING.md +9 -0
- data/README.md +13 -3
- data/lib/lita-netping.rb +1 -0
- data/lib/lita/handlers/netping.rb +42 -4
- data/lita-netping.gemspec +3 -3
- data/locales/en.yml +3 -2
- data/spec/lita/handlers/netping_spec.rb +20 -0
- data/spec/spec_helper.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8b70c3c276083c25dbe1a73adc20556f6a78e8e
|
4
|
+
data.tar.gz: fb9bf4ea069a8903e733a1b98cb42675a525ce6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e001e199b299409e30e1e1b85c08f1676f3bc159db605cd6b8bf935734a7e28183018d6c3f70e7a1c97c0092321627d1c7084c3c8596074ea33422a32a077d69
|
7
|
+
data.tar.gz: 7d244947a8a562b38a5350bb08240a6261425681ba812ccf08e09099e4694222eb90fd85fca11b29a3d7c49cf9d788bf26a4a7e05ea6fc7d64b23b86f5a6197e
|
data/.travis.yml
CHANGED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
Pull requests are awesome! Pull requests with tests are even more awesome!
|
2
|
+
|
3
|
+
## Quick steps
|
4
|
+
|
5
|
+
1. Fork the repo.
|
6
|
+
2. Run the tests: `bundle && rake`
|
7
|
+
3. Add a test for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, it needs a test!
|
8
|
+
4. Make the test pass.
|
9
|
+
5. Push to your fork and submit a pull request.
|
data/README.md
CHANGED
@@ -26,18 +26,28 @@ none
|
|
26
26
|
Examples:
|
27
27
|
|
28
28
|
```
|
29
|
-
ping google.com - Ping google.com
|
29
|
+
ping google.com - Ping google.com via normal ICMP
|
30
|
+
ping icmp google.com - Ping google.com via normal ICMP (same as above)
|
31
|
+
ping http://www.google.com - Ping google.com via HTTP
|
32
|
+
ping tcp://ldap.server:389 - Ping a TCP service running on ldap.server on port 389
|
33
|
+
ping tcp app.server:8080 - Ping a TCP service running on app.server on port 8080
|
30
34
|
```
|
31
35
|
|
36
|
+
Supported protocols are:
|
37
|
+
|
38
|
+
* `http` - Ping a web service. It is usually simplest to just specify the URI like you would in a web browser.
|
39
|
+
* `icmp` - The default if none is specified. This is your standard ping.
|
40
|
+
* `tcp` - Verify that a TCP service is listening and responding. Note that this doesn't guarantee that the service is not misbehaving, just that it responds on the proper port.
|
41
|
+
|
32
42
|
Syntax:
|
33
43
|
|
34
44
|
```
|
35
|
-
ping <target> - Ping <target> (either DNS
|
45
|
+
ping [protocol] <target> - Ping <target> (either DNS name, IP address, or URI)
|
36
46
|
```
|
37
47
|
|
38
48
|
## Note
|
39
49
|
|
40
|
-
This plugin uses the net-ping library, and the "Net::Ping::External" check,
|
50
|
+
This plugin uses the net-ping library, and the ICMP ping uses the "Net::Ping::External" check,
|
41
51
|
so it will use the "ping" equivalent on whatever host it's running on.
|
42
52
|
|
43
53
|
## License
|
data/lib/lita-netping.rb
CHANGED
@@ -2,7 +2,7 @@ module Lita
|
|
2
2
|
module Handlers
|
3
3
|
class Netping < Handler
|
4
4
|
route(
|
5
|
-
/^ping\s(?<target
|
5
|
+
/^ping(\s+(?<proto>\S+))?\s(?<target>\S+)/,
|
6
6
|
:ping,
|
7
7
|
command: true,
|
8
8
|
help: {
|
@@ -11,13 +11,34 @@ module Lita
|
|
11
11
|
)
|
12
12
|
|
13
13
|
def ping(response)
|
14
|
+
proto = response.match_data['proto'] || 'icmp'
|
14
15
|
target = response.match_data['target']
|
15
16
|
|
16
|
-
|
17
|
+
# Update the protocol based on the target
|
18
|
+
proto = URI(target).scheme if target =~ %r{^(\S+)://\S+}
|
19
|
+
|
20
|
+
if valid_protocol?(proto)
|
21
|
+
response.reply(format(target, ping_target(proto.downcase, target)))
|
22
|
+
else
|
23
|
+
response.reply(t('ping.unsupported', proto: proto))
|
24
|
+
end
|
17
25
|
end
|
18
26
|
|
19
27
|
private
|
20
28
|
|
29
|
+
def extract_host_and_port(target)
|
30
|
+
if target =~ %r{^(\S+)://\S+}
|
31
|
+
host = URI(target).host
|
32
|
+
port = URI(target).port
|
33
|
+
elsif target =~ /:[0-9]+$/
|
34
|
+
host, _, port = target.rpartition(':')
|
35
|
+
else
|
36
|
+
host = target
|
37
|
+
port = nil
|
38
|
+
end
|
39
|
+
[host, port]
|
40
|
+
end
|
41
|
+
|
21
42
|
def format(host, result)
|
22
43
|
if result
|
23
44
|
t('ping.success', host: host)
|
@@ -26,8 +47,25 @@ module Lita
|
|
26
47
|
end
|
27
48
|
end
|
28
49
|
|
29
|
-
def ping_target(
|
30
|
-
|
50
|
+
def ping_target(proto, target)
|
51
|
+
# dissect the target to get the hostname and port
|
52
|
+
host, port = extract_host_and_port(target)
|
53
|
+
|
54
|
+
case proto
|
55
|
+
when 'http'
|
56
|
+
# With HTTP, we can just pass the target
|
57
|
+
p = Net::Ping::HTTP.new(target)
|
58
|
+
when 'icmp'
|
59
|
+
# The default
|
60
|
+
p = Net::Ping::External.new(host)
|
61
|
+
when 'tcp'
|
62
|
+
p = Net::Ping::TCP.new(host, port)
|
63
|
+
end
|
64
|
+
proto == 'icmp' ? p.ping(host, 1, 1, 1) : p.ping
|
65
|
+
end
|
66
|
+
|
67
|
+
def valid_protocol?(proto)
|
68
|
+
%w(http icmp tcp).include?(proto.downcase)
|
31
69
|
end
|
32
70
|
end
|
33
71
|
|
data/lita-netping.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'lita-netping'
|
3
|
-
spec.version = '0.
|
3
|
+
spec.version = '0.6.0'
|
4
4
|
spec.authors = ['Eric Sigler']
|
5
5
|
spec.email = ['me@esigler.com']
|
6
6
|
spec.description = 'An IP ping plugin for Lita'
|
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.metadata = { 'lita_plugin_type' => 'handler' }
|
11
11
|
|
12
12
|
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
13
|
-
spec.executables = spec.files.grep(
|
14
|
-
spec.test_files = spec.files.grep(
|
13
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
15
|
spec.require_paths = ['lib']
|
16
16
|
|
17
17
|
spec.add_runtime_dependency 'lita', '>= 4.0'
|
data/locales/en.yml
CHANGED
@@ -4,8 +4,9 @@ en:
|
|
4
4
|
netping:
|
5
5
|
help:
|
6
6
|
ping:
|
7
|
-
syntax: ping <target>
|
8
|
-
desc: Ping <target> (either DNS or IP address)
|
7
|
+
syntax: ping [protocol] <target>
|
8
|
+
desc: Ping [protocol] <target> (either DNS or IP address)
|
9
9
|
ping:
|
10
10
|
success: "%{host} responded to ping"
|
11
11
|
fail: "%{host} did not respond to ping"
|
12
|
+
unsupported: "%{proto} is not a supported protocol"
|
@@ -11,9 +11,29 @@ describe Lita::Handlers::Netping, lita_handler: true do
|
|
11
11
|
expect(replies.last).to eq('example.com responded to ping')
|
12
12
|
end
|
13
13
|
|
14
|
+
it 'returns a success if the target is pingable via HTTP' do
|
15
|
+
send_command('ping http example.com')
|
16
|
+
expect(replies.last).to eq('example.com responded to ping')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns a success if the target is pingable via TCP' do
|
20
|
+
send_command('ping tcp 127.0.0.1:6379')
|
21
|
+
expect(replies.last).to eq('127.0.0.1:6379 responded to ping')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns a success if the target is pingable via TCP as a URI' do
|
25
|
+
send_command('ping tcp://127.0.0.1:6379')
|
26
|
+
expect(replies.last).to eq('tcp://127.0.0.1:6379 responded to ping')
|
27
|
+
end
|
28
|
+
|
14
29
|
it 'returns a failure if the target is not pingable' do
|
15
30
|
send_command('ping unknownhost.local')
|
16
31
|
expect(replies.last).to eq('unknownhost.local did not respond to ping')
|
17
32
|
end
|
33
|
+
|
34
|
+
it 'returns a failure if the protocol is not supported' do
|
35
|
+
send_command('ping xmpp://jabber.org')
|
36
|
+
expect(replies.last).to eq('xmpp is not a supported protocol')
|
37
|
+
end
|
18
38
|
end
|
19
39
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-netping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Sigler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- ".gitignore"
|
133
133
|
- ".rubocop.yml"
|
134
134
|
- ".travis.yml"
|
135
|
+
- CONTRIBUTING.md
|
135
136
|
- Gemfile
|
136
137
|
- LICENSE
|
137
138
|
- README.md
|
@@ -163,10 +164,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
164
|
version: '0'
|
164
165
|
requirements: []
|
165
166
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.
|
167
|
+
rubygems_version: 2.4.5
|
167
168
|
signing_key:
|
168
169
|
specification_version: 4
|
169
170
|
summary: An IP ping plugin for Lita
|
170
171
|
test_files:
|
171
172
|
- spec/lita/handlers/netping_spec.rb
|
172
173
|
- spec/spec_helper.rb
|
174
|
+
has_rdoc:
|