mmonit-client 0.0.4
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/.gitignore +1 -0
- data/README.md +35 -0
- data/lib/mmonit.rb +2 -0
- data/lib/mmonit/connection.rb +108 -0
- data/lib/mmonit/version.rb +3 -0
- data/mmonit.gemspec +15 -0
- metadata +49 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: d763b946f016249a9b2c81fcc3b91c9176a97347
|
|
4
|
+
data.tar.gz: 28e09524be8e954e564a6af6a297f0877839421d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 7f9d9341ce720885aefed54045fee40b5e3bbb8f779d4f169a83629f1cfcc8251016fb2c54e39181547da7a33ccb2f1b7787c0867986cedd37bdb297e90eae35
|
|
7
|
+
data.tar.gz: 3da21f644c91400da1ede18052cb197d0538e2ca67f2d145aea249dc9e53d110b8edde27cb9b8c805e570374c2a6801c2485ec37a09eb04b38883145d324c1bc
|
data/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*.deb
|
data/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
mmonit-ruby
|
|
2
|
+
===========
|
|
3
|
+
|
|
4
|
+
Ruby interface for M/Monit
|
|
5
|
+
|
|
6
|
+
All the commands listed here are currently available:
|
|
7
|
+
|
|
8
|
+
http://mmonit.com/wiki/MMonit/HTTP-API
|
|
9
|
+
|
|
10
|
+
Requests are read-only until I find a way to do more.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
mmonit = MMonit::Connection.new({
|
|
16
|
+
:ssl => true,
|
|
17
|
+
:username => 'USERNAME',
|
|
18
|
+
:password => 'PASSWORD',
|
|
19
|
+
:address => 'example.com',
|
|
20
|
+
:port => '443'
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
mmonit.connect
|
|
24
|
+
|
|
25
|
+
hosts = mmonit.hosts
|
|
26
|
+
|
|
27
|
+
p hosts
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Custom requests can be made like:
|
|
32
|
+
|
|
33
|
+
mmonit.request(path, [body])
|
|
34
|
+
|
|
35
|
+
body is optional
|
data/lib/mmonit.rb
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'net/https'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
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
|
|
43
|
+
|
|
44
|
+
# TODO: filter arguments
|
|
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
|
+
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))
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
data/mmonit.gemspec
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "mmonit/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |gem|
|
|
6
|
+
gem.authors = ['hSATAC']
|
|
7
|
+
gem.email = ['hsatac@gmail.com']
|
|
8
|
+
gem.homepage = 'http://github.com/hSATAC/mmonit-ruby'
|
|
9
|
+
gem.summary = 'Ruby interface to M/Monit, support mmonit v3'
|
|
10
|
+
gem.description = gem.summary
|
|
11
|
+
gem.name = 'mmonit-client'
|
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
|
13
|
+
gem.require_paths = ['lib']
|
|
14
|
+
gem.version = MMonit::VERSION
|
|
15
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mmonit-client
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.4
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- hSATAC
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-12-11 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Ruby interface to M/Monit, support mmonit v3
|
|
14
|
+
email:
|
|
15
|
+
- hsatac@gmail.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- .gitignore
|
|
21
|
+
- README.md
|
|
22
|
+
- lib/mmonit.rb
|
|
23
|
+
- lib/mmonit/connection.rb
|
|
24
|
+
- lib/mmonit/version.rb
|
|
25
|
+
- mmonit.gemspec
|
|
26
|
+
homepage: http://github.com/hSATAC/mmonit-ruby
|
|
27
|
+
licenses: []
|
|
28
|
+
metadata: {}
|
|
29
|
+
post_install_message:
|
|
30
|
+
rdoc_options: []
|
|
31
|
+
require_paths:
|
|
32
|
+
- lib
|
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - '>='
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '0'
|
|
43
|
+
requirements: []
|
|
44
|
+
rubyforge_project:
|
|
45
|
+
rubygems_version: 2.2.2
|
|
46
|
+
signing_key:
|
|
47
|
+
specification_version: 4
|
|
48
|
+
summary: Ruby interface to M/Monit, support mmonit v3
|
|
49
|
+
test_files: []
|