mmonit-client 0.0.4 → 0.0.5
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/lib/mmonit/connection.rb +101 -96
- data/lib/mmonit/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d72688d408a77e7dae6bbaf62df4e2a86a44587c
|
|
4
|
+
data.tar.gz: dc729baff00331101cc5bf25c3cc38f93c4d431d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cb90206f48cd6ca903d9063a0f12130169839115f3cb9caac3f729a7721f8606b78ed8ce88699506f3bb86a2c2bcc905b0f4f2df89e4703d98de8b230c81ce25
|
|
7
|
+
data.tar.gz: 330a088028ea4f97e64e36db7c9f7297662caf730847391f5352ec6c82663b3743b4b002def9608177d8eb0fc835a9fa29316aeee0668e1926d6a9b9a373388a
|
data/lib/mmonit/connection.rb
CHANGED
|
@@ -3,106 +3,111 @@ require 'net/https'
|
|
|
3
3
|
require 'json'
|
|
4
4
|
|
|
5
5
|
module MMonit
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
6
|
+
class Connection
|
|
7
|
+
attr_reader :http, :address, :port, :ssl, :username, :useragent, :headers
|
|
8
|
+
attr_writer :password
|
|
9
|
+
|
|
10
|
+
def initialize(options = {})
|
|
11
|
+
@ssl = options[:ssl] || false
|
|
12
|
+
@address = options[:address]
|
|
13
|
+
options[:port] ||= @ssl ? '8443' : '8080'
|
|
14
|
+
@port = options[:port]
|
|
15
|
+
@username = options[:username]
|
|
16
|
+
@password = options[:password]
|
|
17
|
+
options[:useragent] ||= "MMonit-Ruby/#{MMonit::VERSION}"
|
|
18
|
+
@useragent = options[:useragent]
|
|
19
|
+
@headers = {
|
|
20
|
+
'Host' => @address,
|
|
21
|
+
'Referer' => "#{@url}/index.csp",
|
|
22
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
|
23
|
+
'User-Agent' => @useragent,
|
|
24
|
+
'Connection' => 'keepalive'
|
|
25
|
+
}
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def connect
|
|
29
|
+
@http = Net::HTTP.new(@address, @port)
|
|
30
|
+
|
|
31
|
+
if @ssl
|
|
32
|
+
@http.use_ssl = true
|
|
33
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
@headers['Cookie'] = @http.get('/index.csp').response['set-cookie'].split(';').first
|
|
37
|
+
self.login
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def login
|
|
41
|
+
self.request('/z_security_check', "z_username=#{@username}&z_password=#{@password}").code.to_i == 302
|
|
42
|
+
end
|
|
43
43
|
|
|
44
44
|
# TODO: filter arguments
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
def status_overview
|
|
46
|
+
JSON.parse(self.get('/status/hosts/list').body)['records']
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# TODO: get by id
|
|
50
|
+
def status(id)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def status_summary
|
|
54
|
+
JSON.parse(self.get('/status/hosts/summary').body)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def hosts
|
|
58
|
+
JSON.parse(self.get('/admin/hosts/list').body)['records']
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
#def users
|
|
62
|
+
#JSON.parse(self.request('/json/admin/users/list').body)
|
|
63
|
+
#end
|
|
64
|
+
|
|
65
|
+
#def alerts
|
|
66
|
+
#JSON.parse(self.request('/json/admin/alerts/list').body)
|
|
67
|
+
#end
|
|
68
|
+
|
|
69
|
+
#def events
|
|
70
|
+
#JSON.parse(self.request('/json/events/list').body)['records']
|
|
71
|
+
#end
|
|
72
|
+
|
|
73
|
+
#### topography and reports are disabled until I figure out their new equivalent in M/Monit
|
|
74
|
+
# def topography
|
|
75
|
+
# JSON.parse(self.request('/json/status/topography').body)
|
|
76
|
+
# end
|
|
77
|
+
|
|
78
|
+
# def reports(hostid=nil)
|
|
79
|
+
# body = String.new
|
|
80
|
+
# body = "hostid=#{hostid.to_s}" if hostid
|
|
81
|
+
# JSON.parse(self.request('/json/reports/overview', body).body)
|
|
82
|
+
# end
|
|
83
|
+
|
|
84
|
+
def find_host_by_hostname(fqdn)
|
|
85
|
+
host = self.hosts.select{ |h| h['hostname'] == fqdn }
|
|
86
|
+
host.empty? ? nil : host.first
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# another option: /admin/hosts/json/get?id=####
|
|
90
|
+
def get_host_details(id)
|
|
91
|
+
JSON.parse(self.get("/admin/hosts/get?id=#{id}").body) rescue nil
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Now mmonit requires csrf_token for some actions
|
|
95
|
+
def get_csrf_token
|
|
96
|
+
JSON.parse(mmonit.get("/session/get?key=CSRFToken").body)["CSRFToken"]
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def delete_host(id)
|
|
100
|
+
self.request("/admin/hosts/delete?id=#{id}","",{ "CSRFToken" => csrf_token})
|
|
101
|
+
end
|
|
48
102
|
|
|
49
|
-
|
|
50
|
-
|
|
103
|
+
def request(path, body="", headers = {})
|
|
104
|
+
self.connect unless @http.is_a?(Net::HTTP)
|
|
105
|
+
@http.post(path, body, @headers.merge(headers))
|
|
51
106
|
end
|
|
52
107
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def hosts
|
|
58
|
-
JSON.parse(self.get('/admin/hosts/list').body)['records']
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
#def users
|
|
62
|
-
#JSON.parse(self.request('/json/admin/users/list').body)
|
|
63
|
-
#end
|
|
64
|
-
|
|
65
|
-
#def alerts
|
|
66
|
-
#JSON.parse(self.request('/json/admin/alerts/list').body)
|
|
67
|
-
#end
|
|
68
|
-
|
|
69
|
-
#def events
|
|
70
|
-
#JSON.parse(self.request('/json/events/list').body)['records']
|
|
71
|
-
#end
|
|
72
|
-
|
|
73
|
-
#### topography and reports are disabled until I figure out their new equivalent in M/Monit
|
|
74
|
-
# def topography
|
|
75
|
-
# JSON.parse(self.request('/json/status/topography').body)
|
|
76
|
-
# end
|
|
77
|
-
|
|
78
|
-
# def reports(hostid=nil)
|
|
79
|
-
# body = String.new
|
|
80
|
-
# body = "hostid=#{hostid.to_s}" if hostid
|
|
81
|
-
# JSON.parse(self.request('/json/reports/overview', body).body)
|
|
82
|
-
# end
|
|
83
|
-
|
|
84
|
-
def find_host_by_hostname(fqdn)
|
|
85
|
-
host = self.hosts.select{ |h| h['hostname'] == fqdn }
|
|
86
|
-
host.empty? ? nil : host.first
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
# another option: /admin/hosts/json/get?id=####
|
|
90
|
-
def get_host_details(id)
|
|
91
|
-
JSON.parse(self.get("/admin/hosts/get?id=#{id}").body) rescue nil
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def delete_host(id)
|
|
95
|
-
self.request("/admin/hosts/delete?id=#{id}")
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def request(path, body="", headers = {})
|
|
99
|
-
self.connect unless @http.is_a?(Net::HTTP)
|
|
100
|
-
@http.post(path, body, @headers.merge(headers))
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def get(path, headers = {})
|
|
104
|
-
self.connect unless @http.is_a?(Net::HTTP)
|
|
105
|
-
@http.get(path, @headers.merge(headers))
|
|
108
|
+
def get(path, headers = {})
|
|
109
|
+
self.connect unless @http.is_a?(Net::HTTP)
|
|
110
|
+
@http.get(path, @headers.merge(headers))
|
|
106
111
|
end
|
|
107
|
-
|
|
112
|
+
end
|
|
108
113
|
end
|
data/lib/mmonit/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mmonit-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- hSATAC
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2017-11-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Ruby interface to M/Monit, support mmonit v3
|
|
14
14
|
email:
|
|
@@ -17,7 +17,7 @@ executables: []
|
|
|
17
17
|
extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
|
19
19
|
files:
|
|
20
|
-
- .gitignore
|
|
20
|
+
- ".gitignore"
|
|
21
21
|
- README.md
|
|
22
22
|
- lib/mmonit.rb
|
|
23
23
|
- lib/mmonit/connection.rb
|
|
@@ -32,17 +32,17 @@ require_paths:
|
|
|
32
32
|
- lib
|
|
33
33
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
34
|
requirements:
|
|
35
|
-
- -
|
|
35
|
+
- - ">="
|
|
36
36
|
- !ruby/object:Gem::Version
|
|
37
37
|
version: '0'
|
|
38
38
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
39
|
requirements:
|
|
40
|
-
- -
|
|
40
|
+
- - ">="
|
|
41
41
|
- !ruby/object:Gem::Version
|
|
42
42
|
version: '0'
|
|
43
43
|
requirements: []
|
|
44
44
|
rubyforge_project:
|
|
45
|
-
rubygems_version: 2.
|
|
45
|
+
rubygems_version: 2.6.10
|
|
46
46
|
signing_key:
|
|
47
47
|
specification_version: 4
|
|
48
48
|
summary: Ruby interface to M/Monit, support mmonit v3
|