logicmonitor_simple 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/LICENSE +7 -0
  2. data/lib/logicmonitor_simple.rb +57 -0
  3. metadata +95 -0
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2013 Get Satisfaction, Michael Mittelstadt
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Simple LogicMonitor API library - a spartan wrapper around the LogicMonitor API
4
+ #
5
+ # Author: Michael Mittelstadt (<meek@getsatisfaction.com>)
6
+ # Version: 0.1.0
7
+ #
8
+ # Usage:
9
+ #
10
+ # lm = Logicmonitor::Simple.new("yourdomain", "username", "password")
11
+ #
12
+ # hg = lm.get_host_groups()
13
+ # web_hosts = lm.get_hosts("host_group_id" => 123)
14
+ #
15
+ # all arguments and names are taken from the LogicMonitor API (http://help.logicmonitor.com/developers-guide/),
16
+ # with camelCase changed to snake_case for both method and argument names
17
+
18
+ require 'awrence'
19
+ require 'curb'
20
+ require 'multi_json'
21
+
22
+ module Logicmonitor
23
+ class Simple
24
+ def initialize(domain, username, password)
25
+ @domain = domain
26
+ @username = username
27
+ @password = password
28
+ @cookies = []
29
+ self.sign_in({ 'c' => @domain, 'u' => @username, 'p' => @password })
30
+ end
31
+
32
+ def method_missing(method, *args)
33
+ method = method.to_s.split('_').each_with_index.map { |e,i| i>0 ? e.capitalize : e }.join
34
+ http_args = args[0].to_camelback_keys.map do |k,v|
35
+ if v.is_a? Array
36
+ v = v.join(',')
37
+ end
38
+ "#{k}=#{v}"
39
+ end.join('&') rescue []
40
+ g = Curl.get("https://#{@domain}.logicmonitor.com/santaba/rpc/#{method}?#{http_args}") do |http|
41
+ if @cookies.size > 0
42
+ http.headers['Cookie'] = @cookies.join('; ')
43
+ end
44
+ end
45
+
46
+ if @cookies.empty?
47
+ @cookies = g.header_str.scan(/^Set-Cookie: ([^\r]+)?\r/m)
48
+ end
49
+
50
+ if g.status.to_i > 399
51
+ raise "Received unexpected HTTP status #{g.status} Response Body: #{g.body_str}"
52
+ end
53
+
54
+ MultiJson.decode(g.body_str) or raise Logicmonitor::Simple::Error "Received invalid JSON from LogicMonitor"
55
+ end
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logicmonitor_simple
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Mittelstadt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: curb
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: multi_json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: awrence
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Simple API client for LogicMonitor
63
+ email: meek@getsatisfaction.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - LICENSE
69
+ - lib/logicmonitor_simple.rb
70
+ homepage: https://github.com/meekmichael/logicmonitor_simple
71
+ licenses:
72
+ - MIT
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 1.8.25
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Simple API client for LogicMonitor
95
+ test_files: []