ihealth 2.2.0
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/lib/ihealth.rb +250 -0
- metadata +46 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 91693c879dadb353501ae445f7372a2e8800a786
|
|
4
|
+
data.tar.gz: 4ae341cd07f176f9f42979051943b210bdc14210
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 004e927687b3848ff4a89550e910e1d42787427ca71f1ce9d1fa80cdec05f3038c6d7d9a26047318f25aace88123ca1160ed92adebb30be534562d04ef47b88b
|
|
7
|
+
data.tar.gz: 0f025cf2579f45aa486f68c79407622f1d2c3001ef9d1190a10296f1f3dec2daf41bbd0db5d4ec4802c0047847e0fddf0af4aa9834c230dafefbd868905b4edc
|
data/lib/ihealth.rb
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# This gem abstracts F5s iHealth API and allows.
|
|
2
|
+
# This gem will allow you to do the following:
|
|
3
|
+
# * Authenticate
|
|
4
|
+
# * Upload a qkview
|
|
5
|
+
# * Get list of IDs of qkviews already uploaded
|
|
6
|
+
# * Get meta data about a particular ID already uploaded
|
|
7
|
+
# * Get the full heuristic report for an ID already uploaded
|
|
8
|
+
#
|
|
9
|
+
# Author:: Dave B. Greene (omniplex@omniplex.net)
|
|
10
|
+
# Copyright:: Copyright (c) 2012 Dave Greene
|
|
11
|
+
# License:: GPL V3
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
require 'net/http'
|
|
16
|
+
require 'net/https'
|
|
17
|
+
require 'uri'
|
|
18
|
+
require 'json'
|
|
19
|
+
|
|
20
|
+
# This class provides the interface to F5s iHealth API system
|
|
21
|
+
# and requires that you have an active account with F5.
|
|
22
|
+
class Ihealth
|
|
23
|
+
|
|
24
|
+
# Sets the default "User Agent" that will be passed to identify the application
|
|
25
|
+
# Please Change the User Agent to be descriptive for your organization.
|
|
26
|
+
USER_AGENT = "Ruby iHealth Gem/2.3.0"
|
|
27
|
+
|
|
28
|
+
# Creates the initial connection by performaing authentication
|
|
29
|
+
def initialize username, password, proxyserver = nil, proxyport = nil, proxyuser = nil, proxypass = nil
|
|
30
|
+
@username = username
|
|
31
|
+
@password = password
|
|
32
|
+
@proxyserver = proxyserver
|
|
33
|
+
@proxyport = proxyport
|
|
34
|
+
@proxyuser = proxyuser
|
|
35
|
+
@proxypass = proxypass
|
|
36
|
+
@authenticated = false
|
|
37
|
+
@IHEALTHBASE= "https://ihealth-api.f5.com/qkview-analyzer/api/"
|
|
38
|
+
|
|
39
|
+
# Try and authenticate
|
|
40
|
+
authenticate
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Uploads a file to iHealth for heuristic processing
|
|
44
|
+
def upload filepath
|
|
45
|
+
authenticate if !@authenticated
|
|
46
|
+
url = URI("#{@IHEALTHBASE}qkviews?retain=true")
|
|
47
|
+
headers = {'User Agent' => USER_AGENT, 'Transfer-Encoding' => 'chunked', 'Cookie' => @cookies }
|
|
48
|
+
@proxyserver.nil? ? (ihealthclient = Net::HTTP::new(url.host, url.port)) : (ihealthclient = Net::HTTP::new(url.host, url.port,@proxyserver, @proxyport, @proxyuser, @proxypass))
|
|
49
|
+
ihealthclient.use_ssl = true
|
|
50
|
+
ihealthclient.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
51
|
+
ihealthrequest = Net::HTTP::Post.new(url.path + "?" + url.query, headers)
|
|
52
|
+
ihealthrequest.content_type = 'application/gzip'
|
|
53
|
+
ihealthrequest.set_form_data('visible_in_gui' => 'true')
|
|
54
|
+
ihealthrequest.body_stream = File.open(filepath, 'rb')
|
|
55
|
+
response = ihealthclient.request(ihealthrequest)
|
|
56
|
+
response.code == "303" ? (return response['location'][/[0-9]*$/,0]) : (return nil)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Gets a list of IDs that are stored in the iHealth system after qkviews have been uploaded.
|
|
60
|
+
def get_list format = "json"
|
|
61
|
+
authenticate if !@authenticated
|
|
62
|
+
url = URI("#{@IHEALTHBASE}qkviews.#{format}")
|
|
63
|
+
headers = {'User Agent' => USER_AGENT, 'Cookie' => @cookies }
|
|
64
|
+
#ihealthclient = Net::HTTP.new(url.host, url.port)
|
|
65
|
+
@proxyserver.nil? ? (ihealthclient = Net::HTTP::new(url.host, url.port)) : (ihealthclient = Net::HTTP::new(url.host, url.port,@proxyserver, @proxyport, @proxyuser, @proxypass))
|
|
66
|
+
ihealthclient.use_ssl = true
|
|
67
|
+
ihealthclient.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
68
|
+
httprequest = Net::HTTP::Get.new(url.path, headers)
|
|
69
|
+
httprequest.content_type = 'application/xml'
|
|
70
|
+
response = ihealthclient.start do |http|
|
|
71
|
+
http.request(httprequest)
|
|
72
|
+
end
|
|
73
|
+
response.code != "200" ? (raise "We received #{response.code}") : (return t_ids = JSON.parse(response.body))
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Gets meta data for a particular ID where a qkview has already been upladed to the iHealth system.
|
|
77
|
+
def get_meta qid, format = "json"
|
|
78
|
+
authenticate if !@authenticated
|
|
79
|
+
url = URI("#{@IHEALTHBASE}qkviews/#{qid}.#{format}")
|
|
80
|
+
headers = {'User Agent' => USER_AGENT, 'Cookie' => @cookies }
|
|
81
|
+
#ihealthclient = Net::HTTP.new(url.host, url.port)
|
|
82
|
+
@proxyserver.nil? ? (ihealthclient = Net::HTTP::new(url.host, url.port)) : (ihealthclient = Net::HTTP::new(url.host, url.port,@proxyserver, @proxyport, @proxyuser, @proxypass))
|
|
83
|
+
ihealthclient.use_ssl = true
|
|
84
|
+
ihealthclient.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
85
|
+
httprequest = Net::HTTP::Get.new(url.path, headers)
|
|
86
|
+
httprequest.content_type = 'application/xml'
|
|
87
|
+
response = ihealthclient.start do |http|
|
|
88
|
+
http.request(httprequest)
|
|
89
|
+
end
|
|
90
|
+
response.code != "200" ? (return nil) : (return t_meta = JSON.parse(response.body))
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Gets the diagnostic data for an ID where a qkview has already been uploaded to the iHealth system.
|
|
94
|
+
# Default output format is JSON.
|
|
95
|
+
def get_diagnostics qid, format = "json"
|
|
96
|
+
authenticate if !@authenticated
|
|
97
|
+
url = URI("#{@IHEALTHBASE}qkviews/#{qid}/diagnostics.#{format}?set=hit&audience=all")
|
|
98
|
+
headers = {'User Agent' => USER_AGENT, 'Cookie' => @cookies }
|
|
99
|
+
#ihealthclient = Net::HTTP.new(url.host, url.port)
|
|
100
|
+
@proxyserver.nil? ? (ihealthclient = Net::HTTP::new(url.host, url.port)) : (ihealthclient = Net::HTTP::new(url.host, url.port,@proxyserver, @proxyport, @proxyuser, @proxypass))
|
|
101
|
+
ihealthclient.use_ssl = true
|
|
102
|
+
ihealthclient.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
103
|
+
httprequest = Net::HTTP::Get.new(url.path + "?" + url.query, headers)
|
|
104
|
+
httprequest.content_type = 'application/xml'
|
|
105
|
+
response = ihealthclient.start do |http|
|
|
106
|
+
http.request(httprequest)
|
|
107
|
+
end
|
|
108
|
+
response.code != "200" ? (return nil) : (return t_diagnostic = JSON.parse(response.body))
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Deletes a qkview from the system.
|
|
112
|
+
def delete qid
|
|
113
|
+
authenticate if !@authenticated
|
|
114
|
+
url = URI("#{@IHEALTHBASE}qkviews/#{qid}")
|
|
115
|
+
headers = {'User Agent' => USER_AGENT, 'Cookie' => @cookies }
|
|
116
|
+
@proxyserver.nil? ? (ihealthclient = Net::HTTP::new(url.host, url.port)) : (ihealthclient = Net::HTTP::new(url.host, url.port, @proxyserver, @proxyport, @proxyuser, @proxypass))
|
|
117
|
+
ihealthclient.use_ssl = true
|
|
118
|
+
ihealthclient.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
119
|
+
httprequest = Net::HTTP::Delete.new(url.path, headers)
|
|
120
|
+
httprequest.content_type = 'application/xml'
|
|
121
|
+
response = ihealthclient.start do |http|
|
|
122
|
+
http.request(httprequest)
|
|
123
|
+
end
|
|
124
|
+
return response.code
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def delete_all
|
|
128
|
+
authenticate if !@authenticated
|
|
129
|
+
url = URI("#{@IHEALTHBASE}qkviews")
|
|
130
|
+
headers = {'User Agent' => USER_AGENT, 'Cookie' => @cookies }
|
|
131
|
+
@proxyserver.nil? ? (ihealthclient = Net::HTTP::new(url.host, url.port)) : (ihealthclient = Net::HTTP::new(url.host, url.port, @proxyserver, @proxyport, @proxyuser, @proxypass))
|
|
132
|
+
ihealthclient.use_ssl = true
|
|
133
|
+
ihealthclient.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
134
|
+
httprequest = Net::HTTP::Delete.new(url.path, headers)
|
|
135
|
+
httprequest.content_type = 'application/xml'
|
|
136
|
+
response = ihealthclient.start do |http|
|
|
137
|
+
http.request(httprequest)
|
|
138
|
+
end
|
|
139
|
+
return response.code
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# This method returns the list of available commands to execute against a given diagnostic
|
|
143
|
+
def get_command_list qid, format = "json"
|
|
144
|
+
authenticate if !@authenticated
|
|
145
|
+
url = URI("#{@IHEALTHBASE}qkviews/#{qid}/commands.#{format}")
|
|
146
|
+
headers = {'User Agent' => USER_AGENT, 'Cookie' => @cookies }
|
|
147
|
+
@proxyserver.nil? ? (ihealthclient = Net::HTTP::new(url.host, url.port)) : (ihealthclient = Net::HTTP::new(url.host, url.port,@proxyserver, @proxyport, @proxyuser, @proxypass))
|
|
148
|
+
ihealthclient.use_ssl = true
|
|
149
|
+
ihealthclient.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
150
|
+
httprequest = Net::HTTP::Get.new(url.path, headers)
|
|
151
|
+
httprequest.content_type = 'application/xml'
|
|
152
|
+
response = ihealthclient.start do |http|
|
|
153
|
+
http.request(httprequest)
|
|
154
|
+
end
|
|
155
|
+
response.code != "200" ? (return nil) : (return t_commands = JSON.parse(response.body))
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# Get the result from a single command
|
|
159
|
+
# Currently there is a bug in iHealth that only allows a single command to work.
|
|
160
|
+
def get_command_output qid, command, format = "json"
|
|
161
|
+
authenticate if !@authenticated
|
|
162
|
+
url = URI("#{@IHEALTHBASE}qkviews/#{qid}/commands/#{command}.#{format}")
|
|
163
|
+
headers = {'User Agent' => USER_AGENT, 'Cookie' => @cookies }
|
|
164
|
+
@proxyserver.nil? ? (ihealthclient = Net::HTTP::new(url.host, url.port)) : (ihealthclient = Net::HTTP::new(url.host, url.port,@proxyserver, @proxyport, @proxyuser, @proxypass))
|
|
165
|
+
ihealthclient.use_ssl = true
|
|
166
|
+
ihealthclient.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
167
|
+
httprequest = Net::HTTP::Get.new(url.path, headers)
|
|
168
|
+
httprequest.content_type = 'application/xml'
|
|
169
|
+
response = ihealthclient.start do |http|
|
|
170
|
+
http.request(httprequest)
|
|
171
|
+
end
|
|
172
|
+
response.code != "200" ? (return nil) : (return t_commands = JSON.parse(response.body))
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
# def get_commands_output qid, commands, format = "json"
|
|
177
|
+
# authenticate if !@authenticated
|
|
178
|
+
# url = URI("#{@IHEALTHBASE}qkviews/#{qid}/command.#{format}")
|
|
179
|
+
# respone = make_request url
|
|
180
|
+
# # headers = {'User Agent' => USER_AGENT, 'Cookie' => @cookies }
|
|
181
|
+
# # @proxyserver.nil? ? (ihealthclient = Net::HTTP::new(url.host, url.port)) : (ihealthclient = Net::HTTP::new(url.host, url.port,@proxyserver, @proxyport, @proxyuser, @proxypass))
|
|
182
|
+
# # ihealthclient.use_ssl = true
|
|
183
|
+
# # ihealthclient.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
184
|
+
# # httprequest = Net::HTTP::Get.new(url.path + "?" + url.query, headers)
|
|
185
|
+
# # httprequest.content_type = 'application/xml'
|
|
186
|
+
# # response = ihealthclient.start do |http|
|
|
187
|
+
# # http.request(httprequest)
|
|
188
|
+
# # end
|
|
189
|
+
# response.code != "200" ? (return nil) : (t_commands = JSON.parse(response.body))
|
|
190
|
+
# return t_commands['qvCommandOutputList']
|
|
191
|
+
# end
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
# no reason to call authenticate directly
|
|
196
|
+
private
|
|
197
|
+
|
|
198
|
+
# Performs authentication and saves the cookie information
|
|
199
|
+
def authenticate
|
|
200
|
+
# probably should abstract this out more.
|
|
201
|
+
url = URI('https://login.f5.com/resource/loginAction.jsp')
|
|
202
|
+
headers = {'User Agent' => USER_AGENT }
|
|
203
|
+
#ihealthclient = Net::HTTP.new(url.host, url.port)
|
|
204
|
+
@proxyserver.nil? ? (ihealthclient = Net::HTTP::new(url.host, url.port)) : (ihealthclient = Net::HTTP::new(url.host, url.port,@proxyserver, @proxyport, @proxyuser, @proxypass))
|
|
205
|
+
ihealthclient.use_ssl = true
|
|
206
|
+
ihealthclient.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
207
|
+
httprequest = Net::HTTP::Post.new(url.path, headers)
|
|
208
|
+
httprequest.set_form_data('userid' => @username, 'passwd' => @password)
|
|
209
|
+
httprequest.content_type = 'application/x-www-form-urlencoded'
|
|
210
|
+
|
|
211
|
+
response = ihealthclient.start do |http|
|
|
212
|
+
http.request(httprequest)
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
# All reponse codes seem to be redirects. Either back to the login page or the account page
|
|
216
|
+
# so we check for the account page.
|
|
217
|
+
if (response['location'] == 'https://login.f5.com/myaccount/index.jsp')
|
|
218
|
+
@authenticated = true
|
|
219
|
+
all_cookies = response.get_fields('set-cookie')
|
|
220
|
+
cookies_array = Array.new
|
|
221
|
+
all_cookies.each { | cookie |
|
|
222
|
+
cookies_array.push(cookie.split('; ')[0])
|
|
223
|
+
}
|
|
224
|
+
@cookies = cookies_array.join('; ')
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
# TODO: Create method to handle web requests and return data so everything isn't repeated
|
|
229
|
+
# Below works if a GET request. Need to modify for all types.
|
|
230
|
+
def make_request url
|
|
231
|
+
authenticate if !@authenticated
|
|
232
|
+
|
|
233
|
+
headers = {'User Agent' => USER_AGENT, 'Cookie' => @cookies }
|
|
234
|
+
@proxyserver.nil? ? (ihealthclient = Net::HTTP::new(url.host, url.port)) : (ihealthclient = Net::HTTP::new(url.host, url.port,@proxyserver, @proxyport, @proxyuser, @proxypass))
|
|
235
|
+
ihealthclient.use_ssl = true
|
|
236
|
+
ihealthclient.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
237
|
+
httprequest = Net::HTTP::Get.new(url.path + "?" + url.query, headers)
|
|
238
|
+
httprequest.content_type = 'application/xml'
|
|
239
|
+
response = ihealthclient.start do |http|
|
|
240
|
+
http.request(httprequest)
|
|
241
|
+
end
|
|
242
|
+
return response
|
|
243
|
+
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
metadata
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ihealth
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 2.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Dave B. Greene
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: An abstraction layer to provide functionality to F5's iHealth reporting
|
|
14
|
+
interface
|
|
15
|
+
email: omniplex@omniplex.net
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/ihealth.rb
|
|
21
|
+
homepage: http://rubygems.org/gems/ihealth
|
|
22
|
+
licenses:
|
|
23
|
+
- GPLv3
|
|
24
|
+
metadata: {}
|
|
25
|
+
post_install_message:
|
|
26
|
+
rdoc_options: []
|
|
27
|
+
require_paths:
|
|
28
|
+
- lib
|
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 1.9.2
|
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - '>='
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements:
|
|
40
|
+
- A valid support account with F5
|
|
41
|
+
rubyforge_project:
|
|
42
|
+
rubygems_version: 2.0.3
|
|
43
|
+
signing_key:
|
|
44
|
+
specification_version: 4
|
|
45
|
+
summary: Interface to F5s iHealth API
|
|
46
|
+
test_files: []
|