mmonit-client 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d763b946f016249a9b2c81fcc3b91c9176a97347
4
- data.tar.gz: 28e09524be8e954e564a6af6a297f0877839421d
3
+ metadata.gz: d72688d408a77e7dae6bbaf62df4e2a86a44587c
4
+ data.tar.gz: dc729baff00331101cc5bf25c3cc38f93c4d431d
5
5
  SHA512:
6
- metadata.gz: 7f9d9341ce720885aefed54045fee40b5e3bbb8f779d4f169a83629f1cfcc8251016fb2c54e39181547da7a33ccb2f1b7787c0867986cedd37bdb297e90eae35
7
- data.tar.gz: 3da21f644c91400da1ede18052cb197d0538e2ca67f2d145aea249dc9e53d110b8edde27cb9b8c805e570374c2a6801c2485ec37a09eb04b38883145d324c1bc
6
+ metadata.gz: cb90206f48cd6ca903d9063a0f12130169839115f3cb9caac3f729a7721f8606b78ed8ce88699506f3bb86a2c2bcc905b0f4f2df89e4703d98de8b230c81ce25
7
+ data.tar.gz: 330a088028ea4f97e64e36db7c9f7297662caf730847391f5352ec6c82663b3743b4b002def9608177d8eb0fc835a9fa29316aeee0668e1926d6a9b9a373388a
@@ -3,106 +3,111 @@ require 'net/https'
3
3
  require 'json'
4
4
 
5
5
  module MMonit
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
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
- def status_overview
46
- JSON.parse(self.get('/status/hosts/list').body)['records']
47
- end
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
- # TODO: get by id
50
- def status(id)
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
- 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
- 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
- end
112
+ end
108
113
  end
@@ -1,3 +1,3 @@
1
1
  module MMonit
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
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
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: 2014-12-11 00:00:00.000000000 Z
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.2.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