ip21 0.0.7 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/ip21.gemspec +1 -3
- data/lib/ip21.rb +79 -39
- metadata +2 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dd35382e2131fbd28394514ad75654306db5c1b82ab25020582e66cc68c70aa
|
4
|
+
data.tar.gz: 50a792351ef0bd99c769cd4375234a0ca308d2c3c0f137faeca3ee1ddc090471
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c551cb26ae0f39eea73adda7585a4f886c6db379e815e8de8565e50450f76c2c84b59310c9101ad1505baf3d7d45faef584be583c0a0aba82b9187806964614
|
7
|
+
data.tar.gz: cdc1dc78116e7ce6b5f4ac2915ae64c9be5e3bbdc7130065ccdff4623d253c5be9462e7683c28f9b28dfb348f43d8b35fa3251048d0555d8822ecb8759c73eb1
|
data/README.md
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/ip21@2x.png)](https://badge.fury.io/rb/ip21)
|
4
4
|
|
5
|
-
With this gem you will be able to connect to IP21 and execute queries against the database using SQL statements.
|
5
|
+
With this gem you will be able to connect to IP21 and execute queries against the database using SQL statements or fetching from history or KPI table definitions.
|
6
|
+
|
7
|
+
Full documentation on https://rubydoc.info/gems/ip21
|
6
8
|
|
7
9
|
## Installing
|
8
10
|
|
@@ -38,11 +40,11 @@ IP21.new(
|
|
38
40
|
## Prerequisites
|
39
41
|
|
40
42
|
- IP21 Database
|
41
|
-
- SQLPlus with REST
|
43
|
+
- SQLPlus with REST installed
|
42
44
|
|
43
45
|
## Authentication
|
44
46
|
|
45
|
-
This gem uses Windows authentication to connect to SQLPlus, so don't forget to set your credentials correctly.
|
47
|
+
This gem uses Windows authentication (NTLM) to connect to SQLPlus, so don't forget to set your credentials correctly.
|
46
48
|
|
47
49
|
On domain you can use the NETBIOS name (CONTOSO) or the normal domain name (contoso.com)
|
48
50
|
|
data/ip21.gemspec
CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.summary = 'Aspentech IP21 Adapter for Ruby'
|
6
6
|
s.description = 'Aspentech IP21 Adapter for executing queries using SQLPlus' \
|
7
7
|
'WebService or REST API'
|
8
|
-
s.version = '0.0
|
8
|
+
s.version = '1.0.0'
|
9
9
|
s.date = Time.now.strftime('%Y-%m-%d')
|
10
10
|
s.author = 'Rhuan Barreto'
|
11
11
|
s.email = 'rhuan@rhuan.com.br'
|
@@ -13,9 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.platform = Gem::Platform::RUBY
|
14
14
|
s.license = 'MIT'
|
15
15
|
s.add_dependency 'activesupport', '~>6.0.1'
|
16
|
-
s.add_dependency 'ruby-ntlm', '~>0.0'
|
17
16
|
s.add_dependency 'rubyntlm', '~>0.6'
|
18
|
-
s.add_dependency 'savon', '~>2.12'
|
19
17
|
s.files = Dir.glob('{docs,bin,lib,spec,templates,benchmarks}/**/*') +
|
20
18
|
['LICENSE', 'README.md', '.yardopts', __FILE__]
|
21
19
|
s.require_path = 'lib'
|
data/lib/ip21.rb
CHANGED
@@ -25,8 +25,6 @@ class IP21
|
|
25
25
|
# to SQLPlus
|
26
26
|
# @param [String] ip21_address The hostname or IP address for connecting to
|
27
27
|
# the IP21 Database
|
28
|
-
# @param [Boolean] soap Set this parameter to true for connecting to SQLPlus
|
29
|
-
# using the SOAP Web Service
|
30
28
|
# @param [Boolean] debug Set this parameter to true for enabling debug
|
31
29
|
# information
|
32
30
|
def initialize(
|
@@ -37,7 +35,6 @@ class IP21
|
|
37
35
|
},
|
38
36
|
sqlplus_address: '127.0.0.1',
|
39
37
|
ip21_address: '127.0.0.1',
|
40
|
-
soap: false,
|
41
38
|
debug: false
|
42
39
|
)
|
43
40
|
@account = auth[:account]
|
@@ -45,7 +42,6 @@ class IP21
|
|
45
42
|
@password = auth[:password]
|
46
43
|
@sqlplus_address = sqlplus_address
|
47
44
|
@ip21_address = ip21_address
|
48
|
-
@soap = soap
|
49
45
|
@debug = debug
|
50
46
|
end
|
51
47
|
|
@@ -55,40 +51,77 @@ class IP21
|
|
55
51
|
# @param [Integer] limit The maximum number of rows that the query will output
|
56
52
|
#
|
57
53
|
# @return [Hash] Response from the query
|
58
|
-
def query(sql, limit = 100
|
59
|
-
|
54
|
+
def query(sql, limit = 100)
|
55
|
+
parse_rest(
|
56
|
+
rest_request('SQL', sql_query_body(sql, limit))
|
57
|
+
)
|
60
58
|
end
|
61
59
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
60
|
+
# Fetch data from IP21 History
|
61
|
+
#
|
62
|
+
# @param [String] tag The tag to be queried
|
63
|
+
# @param [Integer] start_time The unix timestamp in miliseconds for the start
|
64
|
+
# of the query period
|
65
|
+
# @param [Integer] end_time The unix timestamp in miliseconds for the end of
|
66
|
+
# the query period
|
67
|
+
# @param [Hash] opts Optional extra values
|
68
|
+
# @option opts [Integer] limit The maximum number of items to be retrieved
|
69
|
+
# @option opts [Integer] outsiders The maximum number of items to be retrieved
|
70
|
+
# @option opts [Integer] history_format The value format during retrieval.
|
71
|
+
# Possible values are:
|
72
|
+
# - 0: Raw
|
73
|
+
# - 1: Record as String
|
74
|
+
# @option opts [Integer] retrieval_type The retrieval type of the query.
|
75
|
+
# Possible values are:
|
76
|
+
# 0 - Actual
|
77
|
+
# 1 - Interpolated
|
78
|
+
# 2 - Best Fit
|
79
|
+
# 3 - Manual
|
80
|
+
# 10 - Not Good
|
81
|
+
# 11 - Good
|
82
|
+
# 12 - Average
|
83
|
+
# 13 - Maximum
|
84
|
+
# 14 - Minimum
|
85
|
+
# 15 - Range
|
86
|
+
# 16 - Sum
|
87
|
+
# 17 - Standard Deviation
|
88
|
+
# 18 - Variance
|
89
|
+
# 19 - Good Only
|
90
|
+
# 20 - Suspect Only
|
91
|
+
# 21 - First
|
92
|
+
# 22 - Last
|
93
|
+
# @option opts [Integer] outsiders Whether or not to include outsiders
|
94
|
+
# 0 - False
|
95
|
+
# 1 - True
|
96
|
+
#
|
97
|
+
# @return [Hash] Response from IP21
|
98
|
+
def history(tag, start_time, end_time, opts = {
|
99
|
+
limit: 1000, outsiders: 1, history_format: 0, retrieval_type: 0
|
100
|
+
})
|
101
|
+
parse_rest(
|
102
|
+
rest_request(
|
103
|
+
'History',
|
104
|
+
history_query_body(tag, start_time, end_time, opts)
|
105
|
+
)
|
71
106
|
)
|
72
|
-
client.call(:execute_sql, message: { command: sql }).body
|
73
107
|
end
|
74
108
|
|
75
|
-
def
|
76
|
-
|
77
|
-
rest_address(type), query_body(sql, limit, type)
|
78
|
-
)
|
79
|
-
parse_rest(response)
|
109
|
+
def kpi(tag)
|
110
|
+
parse_rest(rest_request('KPI', kpi_query_body(tag)))
|
80
111
|
end
|
81
112
|
|
82
|
-
|
113
|
+
private
|
114
|
+
|
115
|
+
def rest_request(type, body)
|
83
116
|
require 'net/http'
|
84
117
|
require 'ntlm/http'
|
85
|
-
uri = URI(
|
118
|
+
uri = URI(rest_address(type))
|
86
119
|
http = Net::HTTP.new(uri.host)
|
87
120
|
request = Net::HTTP::Post.new(uri)
|
88
121
|
request.body = body
|
89
122
|
request.ntlm_auth(@account, @domain, @password)
|
90
123
|
response = http.request(request)
|
91
|
-
debug_info(
|
124
|
+
debug_info(uri, request.body, response) if @debug
|
92
125
|
response
|
93
126
|
end
|
94
127
|
|
@@ -110,25 +143,32 @@ class IP21
|
|
110
143
|
end
|
111
144
|
end
|
112
145
|
|
113
|
-
def soap_address
|
114
|
-
"http://#{@sqlplus_address}/SQLplusWebService/SQLplusWebService.asmx?WSDL"
|
115
|
-
end
|
116
|
-
|
117
146
|
def rest_address(type)
|
118
147
|
"http://#{@sqlplus_address}/ProcessData/AtProcessDataREST.dll/#{type}"
|
119
148
|
end
|
120
149
|
|
121
|
-
def
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
150
|
+
def sql_query_body(sql, limit = 1000)
|
151
|
+
"<SQL c=\"DRIVER={AspenTech SQLplus};HOST=#{@ip21_address};Port=10014;" \
|
152
|
+
"CHARINT=N;CHARFLOAT=N;CHARTIME=N;CONVERTERRORS=N;\" m=\"#{limit}\" " \
|
153
|
+
"to=\"30\" s=\"#{select?(sql) ? 1 : 0}\"><![CDATA[#{sql}]]></SQL>"
|
154
|
+
end
|
155
|
+
|
156
|
+
def kpi_query_body(tag)
|
157
|
+
require 'active_support'
|
158
|
+
require 'active_support/core_ext/object/to_query'
|
159
|
+
{
|
160
|
+
dataSource: @ip21_address,
|
161
|
+
tag: tag,
|
162
|
+
allQuotes: 1
|
163
|
+
}.to_query
|
164
|
+
end
|
165
|
+
|
166
|
+
def history_query_body(tag, start_time, end_time, opts)
|
167
|
+
'<Q f="D" allQuotes="1"><Tag>' + "<N><![CDATA[#{tag}]]></N>" \
|
168
|
+
"<D><![CDATA[#{@ip21_address}]]></D>" + "<HF>#{opts[:history_format]}</HF>" \
|
169
|
+
"<St>#{start_time}</St>" + "<Et>#{end_time}</Et>" \
|
170
|
+
"<RT>#{opts[:retrieval_type]}</RT>" + "<X>#{opts[:limit]}</X>" \
|
171
|
+
"<O>#{opts[:outsiders]}</O>" + '</Tag></Q>'
|
132
172
|
end
|
133
173
|
|
134
174
|
def select?(query)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ip21
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rhuan Barreto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 6.0.1
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: ruby-ntlm
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rubyntlm
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,20 +38,6 @@ dependencies:
|
|
52
38
|
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '0.6'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: savon
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '2.12'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '2.12'
|
69
41
|
description: Aspentech IP21 Adapter for executing queries using SQLPlusWebService
|
70
42
|
or REST API
|
71
43
|
email: rhuan@rhuan.com.br
|