mastodon_healthchecker 0.1.0.pre → 0.1.0.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mastodon_healthchecker.rb +12 -13
- data/lib/mastodon_healthchecker/dns_records.rb +23 -0
- data/lib/mastodon_healthchecker/hash_hosts.rb +101 -0
- data/lib/mastodon_healthchecker/instance_info.rb +90 -0
- data/lib/mastodon_healthchecker/version.rb +1 -1
- data/mastodon_healthchecker.gemspec +5 -0
- metadata +66 -4
- data/lib/mastodon_healthchecker/inspectors/availability.rb +0 -19
- data/lib/mastodon_healthchecker/inspectors/record_existence.rb +0 -26
- data/lib/mastodon_healthchecker/results/network_inspection.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ac4c1e11218f383ffeb7d4e4f93c2f47a103b1a
|
4
|
+
data.tar.gz: 3a07a3424670db0aa6c02d15f6269b8dc151ad4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0638501d22b1a3e2a89c263cef80b0e87eb80ff2d39ecc622b994e18a7a48e855ac5786684ac7b2b9bb7c0e2b6b40784e7ecab3cbfb157f99ca9b0041c5a5848'
|
7
|
+
data.tar.gz: 8ea93661741d70a4db76207740ad131b0cc65298ace25fcffcd5d689a1e08bde2c1ed27f3fac5a6ad8fcb84c67758d35fbefda66d2fa57a2572e0bd62b74c5f2
|
@@ -1,20 +1,19 @@
|
|
1
|
+
require 'mastodon_healthchecker/dns_records'
|
2
|
+
require 'mastodon_healthchecker/instance_info'
|
1
3
|
require 'mastodon_healthchecker/version'
|
2
4
|
|
3
5
|
module MastodonHealthchecker
|
4
|
-
|
5
|
-
'mastodon_healthchecker/inspectors/availability'
|
6
|
-
autoload :RecordExistenceInspector,
|
7
|
-
'mastodon_healthchecker/inspectors/record_existence'
|
6
|
+
Result = Struct.new('Result', :exists_record, :up, :info)
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
def self.perform(host)
|
9
|
+
records = DNSRecords.new(host)
|
10
|
+
info_v4 = InstanceInfo.fetch(host, records.v4_addresses) if records.v4_addresses.any?
|
11
|
+
info_v6 = InstanceInfo.fetch(host, records.v6_addresses) if records.v6_addresses.any?
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
Result.new(
|
14
|
+
{ v4: records.v4_addresses.any?, v6: records.v6_addresses.any? },
|
15
|
+
{ v4: !info_v4.nil?, v6: !info_v6.nil? },
|
16
|
+
info_v4 || info_v6 || nil
|
17
|
+
)
|
19
18
|
end
|
20
19
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'resolv'
|
2
|
+
|
3
|
+
module MastodonHealthchecker
|
4
|
+
class DNSRecords
|
5
|
+
def initialize(host)
|
6
|
+
@v4_addresses = []
|
7
|
+
@v6_addresses = []
|
8
|
+
Resolv::DNS.new.each_address(host) do |addr|
|
9
|
+
case addr
|
10
|
+
when Resolv::IPv4
|
11
|
+
v4_addresses << addr
|
12
|
+
when Resolv::IPv6
|
13
|
+
v6_addresses << addr
|
14
|
+
else
|
15
|
+
raise "Resolver returns an address which is neither IPv4 nor IPv6."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :v4_addresses, :v6_addresses
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
# Copyright (C) 2017 nullkal.
|
5
|
+
#
|
6
|
+
# This program is a derived work from Resolv::Hosts of Ruby 2.4
|
7
|
+
# (https://github.com/ruby/ruby/).
|
8
|
+
#
|
9
|
+
# ----
|
10
|
+
#
|
11
|
+
# Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
|
12
|
+
#
|
13
|
+
# Redistribution and use in source and binary forms, with or without
|
14
|
+
# modification, are permitted provided that the following conditions
|
15
|
+
# are met:
|
16
|
+
# 1. Redistributions of source code must retain the above copyright
|
17
|
+
# notice, this list of conditions and the following disclaimer.
|
18
|
+
# 2. Redistributions in binary form must reproduce the above copyright
|
19
|
+
# notice, this list of conditions and the following disclaimer in the
|
20
|
+
# documentation and/or other materials provided with the distribution.
|
21
|
+
#
|
22
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
23
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
26
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
27
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
28
|
+
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
29
|
+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
30
|
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
31
|
+
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
32
|
+
# SUCH DAMAGE.
|
33
|
+
#
|
34
|
+
|
35
|
+
require 'resolv'
|
36
|
+
|
37
|
+
module MastodonHealthchecker
|
38
|
+
class HashHosts
|
39
|
+
def initialize(hosts)
|
40
|
+
@name2addr = hosts
|
41
|
+
|
42
|
+
@addr2name = {}
|
43
|
+
hosts.each do |name, addrs|
|
44
|
+
addrs.each do |addr|
|
45
|
+
@addr2name[addr] ||= []
|
46
|
+
@addr2name[addr] << name
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Gets the IP address of +name+ from the hosts file.
|
53
|
+
|
54
|
+
def getaddress(name)
|
55
|
+
each_address(name) {|address| return address}
|
56
|
+
raise ResolvError.new("#{@filename} has no name: #{name}")
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# Gets all IP addresses for +name+ from the hosts file.
|
61
|
+
|
62
|
+
def getaddresses(name)
|
63
|
+
ret = []
|
64
|
+
each_address(name) {|address| ret << address}
|
65
|
+
return ret
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# Iterates over all IP addresses for +name+ retrieved from the hosts file.
|
70
|
+
|
71
|
+
def each_address(name, &proc)
|
72
|
+
if @name2addr.include?(name)
|
73
|
+
@name2addr[name].each(&proc)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# Gets the hostname of +address+ from the hosts file.
|
79
|
+
|
80
|
+
def getname(address)
|
81
|
+
each_name(address) {|name| return name}
|
82
|
+
raise ResolvError.new("#{@filename} has no address: #{address}")
|
83
|
+
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# Gets all hostnames for +address+ from the hosts file.
|
87
|
+
|
88
|
+
def getnames(address)
|
89
|
+
ret = []
|
90
|
+
each_name(address) {|name| ret << name}
|
91
|
+
return ret
|
92
|
+
end
|
93
|
+
|
94
|
+
##
|
95
|
+
# Iterates over all hostnames for +address+ retrieved from the hosts file.
|
96
|
+
|
97
|
+
def each_name(address, &proc)
|
98
|
+
@addr2name[address]&.each(&proc)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'mastodon_healthchecker/hash_hosts'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'faraday'
|
5
|
+
require 'faraday_middleware'
|
6
|
+
require 'faraday/encoding'
|
7
|
+
require 'resolv'
|
8
|
+
require 'resolv-replace'
|
9
|
+
|
10
|
+
module MastodonHealthchecker
|
11
|
+
class InstanceInfo
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def fetch(host, addresses)
|
15
|
+
default_resolver = Resolv::DefaultResolver
|
16
|
+
|
17
|
+
hash_hosts = HashHosts.new({ "#{host}" => addresses })
|
18
|
+
Resolv::DefaultResolver.replace_resolvers([hash_hosts, Resolv::DNS.new])
|
19
|
+
|
20
|
+
result = nil
|
21
|
+
begin
|
22
|
+
info = InstanceInfo.new
|
23
|
+
info.parse_about(get(host, '/about'))
|
24
|
+
info.parse_about_more(get(host, '/about/more'))
|
25
|
+
info.parse_instance(get(host, '/api/v1/instance'))
|
26
|
+
result = info
|
27
|
+
rescue Faraday::ClientError
|
28
|
+
rescue Nokogiri::SyntaxError
|
29
|
+
rescue JSON::ParseError
|
30
|
+
end
|
31
|
+
|
32
|
+
Resolv::DefaultResolver.replace_resolvers(default_resolver)
|
33
|
+
result
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def get(host, path)
|
39
|
+
conn = Faraday.new("http://#{host}") do |faraday|
|
40
|
+
faraday.use FaradayMiddleware::FollowRedirects
|
41
|
+
faraday.response :encoding
|
42
|
+
faraday.response :raise_error
|
43
|
+
faraday.adapter :net_http
|
44
|
+
end
|
45
|
+
conn.get(path)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def initialize
|
50
|
+
@version = nil
|
51
|
+
|
52
|
+
@users = nil
|
53
|
+
@statuses = nil
|
54
|
+
@connections = nil
|
55
|
+
|
56
|
+
@description = nil
|
57
|
+
@extended_description = nil
|
58
|
+
@email = nil
|
59
|
+
@opened = nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def parse_about(response)
|
63
|
+
doc = Nokogiri::HTML.parse(response.body)
|
64
|
+
@opened = doc.xpath("//*[@class='closed-registrations-message']").empty?
|
65
|
+
end
|
66
|
+
|
67
|
+
def parse_about_more(response)
|
68
|
+
doc = Nokogiri::HTML.parse(response.body)
|
69
|
+
|
70
|
+
info = doc.xpath("//*[@class='main']/*[@class='information-board']/*[@class='section']/strong")
|
71
|
+
if 3 <= info.length
|
72
|
+
@users = info[0].text.tr(',', '').to_i
|
73
|
+
@statuses = info[1].text.tr(',', '').to_i
|
74
|
+
@connections = info[2].text.tr(',', '').to_i
|
75
|
+
end
|
76
|
+
|
77
|
+
@extended_description = doc.xpath("//*[@class='main']/*[@class='panel'][2]").inner_html
|
78
|
+
end
|
79
|
+
|
80
|
+
def parse_instance(response)
|
81
|
+
instance = JSON.parse(response.body)
|
82
|
+
@version = instance['version']
|
83
|
+
@description = instance['description']
|
84
|
+
@email = instance['email']
|
85
|
+
end
|
86
|
+
|
87
|
+
attr_reader :version, :users, :statuses, :connections,
|
88
|
+
:description, :extended_description, :email, :opened
|
89
|
+
end
|
90
|
+
end
|
@@ -29,4 +29,9 @@ and other statuses of a mastodon instance.
|
|
29
29
|
spec.add_development_dependency 'rake', '~> 10.0'
|
30
30
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
31
31
|
spec.add_development_dependency 'rubocop', '~> 0.49.1'
|
32
|
+
|
33
|
+
spec.add_runtime_dependency 'faraday', '~> 0.9.2'
|
34
|
+
spec.add_runtime_dependency 'faraday-encoding', '~> 0.0.4'
|
35
|
+
spec.add_runtime_dependency 'faraday_middleware', '~> 0.10.0'
|
36
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.6', '>= 1.6.7.2'
|
32
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mastodon_healthchecker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre
|
4
|
+
version: 0.1.0.pre.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nullkal
|
@@ -66,6 +66,68 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.49.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.9.2
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.9.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday-encoding
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.0.4
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.0.4
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: faraday_middleware
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.10.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.10.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: nokogiri
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.6'
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 1.6.7.2
|
121
|
+
type: :runtime
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - "~>"
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '1.6'
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 1.6.7.2
|
69
131
|
description: |
|
70
132
|
mastodon_healthchecker provides a function which checks the connectability,
|
71
133
|
and other statuses of a mastodon instance.
|
@@ -87,9 +149,9 @@ files:
|
|
87
149
|
- bin/console
|
88
150
|
- bin/setup
|
89
151
|
- lib/mastodon_healthchecker.rb
|
90
|
-
- lib/mastodon_healthchecker/
|
91
|
-
- lib/mastodon_healthchecker/
|
92
|
-
- lib/mastodon_healthchecker/
|
152
|
+
- lib/mastodon_healthchecker/dns_records.rb
|
153
|
+
- lib/mastodon_healthchecker/hash_hosts.rb
|
154
|
+
- lib/mastodon_healthchecker/instance_info.rb
|
93
155
|
- lib/mastodon_healthchecker/version.rb
|
94
156
|
- mastodon_healthchecker.gemspec
|
95
157
|
homepage: https://github.com/nullkal/mastodon_healthchecker
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'mastodon_healthchecker/results/network_inspection.rb'
|
2
|
-
|
3
|
-
module MastodonHealthchecker
|
4
|
-
module AvailabilityInspector
|
5
|
-
def self.call(host)
|
6
|
-
NetworkInspectionResult.new(v4: inspect_v4, v6: inspect_v6)
|
7
|
-
end
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
def self.inspect_v4
|
12
|
-
# TODO: Implement here
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.inspect_v6
|
16
|
-
# TODO: Implement here
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module MastodonHealthchecker
|
2
|
-
module RecordExistenceInspector
|
3
|
-
class Result
|
4
|
-
def initialize(v4: false, v6: false)
|
5
|
-
@v4 = v4
|
6
|
-
@v6 = v6
|
7
|
-
end
|
8
|
-
|
9
|
-
attr_accessor :v4, :v6
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.call(host)
|
13
|
-
Result.new(v4: inspect_v4, v6: inspect_v6)
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def self.inspect_v4
|
19
|
-
# TODO: Implement here
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.inspect_v6
|
23
|
-
# TODO: Implement here
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|