aliyun_sls_ruby3_sdk 0.10.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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +122 -0
- data/aliyun_sls_sdk.gemspec +27 -0
- data/lib/aliyun_sls_sdk/create_log_store_response.rb +15 -0
- data/lib/aliyun_sls_sdk/get_log_request.rb +18 -0
- data/lib/aliyun_sls_sdk/get_log_store_response.rb +13 -0
- data/lib/aliyun_sls_sdk/log_client.rb +196 -0
- data/lib/aliyun_sls_sdk/log_exception.rb +15 -0
- data/lib/aliyun_sls_sdk/log_item.rb +16 -0
- data/lib/aliyun_sls_sdk/log_request.rb +8 -0
- data/lib/aliyun_sls_sdk/log_response.rb +17 -0
- data/lib/aliyun_sls_sdk/protobuf.rb +50 -0
- data/lib/aliyun_sls_sdk/put_logs_request.rb +15 -0
- data/lib/aliyun_sls_sdk/put_logs_response.rb +5 -0
- data/lib/aliyun_sls_sdk/util.rb +67 -0
- data/lib/aliyun_sls_sdk/version.rb +3 -0
- data/lib/aliyun_sls_sdk.rb +30 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0ec561524a7d40e85027eec5ffe0fed7610fd67c37e1751404431e65b7509040
|
4
|
+
data.tar.gz: bfc24e733a4033c6c03971d901011f964c54da52e75c8f16b81799f9102bc0f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b51baf927d0b6e6f1f7a0d89bb96818768f5587ac8f65ba4a6d3efb586712433a19e4966ebc596a218429cdcc6ac5eec1c4c8c5e3ecb7ec12d34e5b67511d17e
|
7
|
+
data.tar.gz: f45b887e4e13664d96e3ecd00429db8f5eb20e6f89718e55bbe5638ef571734bb547d6ffbfe90ef6a98923569f5efdf0ed83e24c54a17ef0a66555f9abcab557
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 cuizheng
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
# AliyunSls
|
2
|
+
|
3
|
+
## 阿里云SLS服务Ruby SDK
|
4
|
+
|
5
|
+
|
6
|
+
https://cn.aliyun.com/product/sls
|
7
|
+
|
8
|
+
------------
|
9
|
+
## 库用法
|
10
|
+
|
11
|
+
### [查询Store清单](http://docs.aliyun.com/#/pub/sls/api/apilist&ListLogstores)
|
12
|
+
|
13
|
+
```
|
14
|
+
endpoint = ''
|
15
|
+
project = ''
|
16
|
+
access_key_secret = ''
|
17
|
+
aliyun_access_key = ''
|
18
|
+
logstore = ''
|
19
|
+
conn = AliyunSlsSdk::LogClient.new(endpoint, access_key_secret, aliyun_access_key)
|
20
|
+
conn.get_logstore(project, logstore)
|
21
|
+
```
|
22
|
+
|
23
|
+
### [上传日志](http://docs.aliyun.com/#/pub/sls/api/apilist&PutLogs)
|
24
|
+
```
|
25
|
+
endpoint = ''
|
26
|
+
project = ''
|
27
|
+
access_key_secret = ''
|
28
|
+
aliyun_access_key = ''
|
29
|
+
logstore = ''
|
30
|
+
conn = AliyunSlsSdk::LogClient.new(endpoint, access_key_secret, aliyun_access_key)
|
31
|
+
|
32
|
+
|
33
|
+
topic=nil
|
34
|
+
source=nil
|
35
|
+
logitems = [{timestamp: Time.now.to_i, contents: [['aaa', '111'], ['ccc', 222]]}]
|
36
|
+
hashKey = nil
|
37
|
+
compress = false
|
38
|
+
|
39
|
+
logs = AliyunSlsSdk::PutLogsRequest.new(project, logstore, topic, source, logitems, hashKey, compress)
|
40
|
+
|
41
|
+
conn.put_logs(logs)
|
42
|
+
```
|
43
|
+
|
44
|
+
### [列出日志主题](http://docs.aliyun.com/#/pub/sls/api/apilist&ListTopics)
|
45
|
+
|
46
|
+
con.list_topics("store")
|
47
|
+
|
48
|
+
|名称| 类型| 必选| 描述|
|
49
|
+
|-----|-----|----|-----|
|
50
|
+
|logstorename| 字符串| 是| 需要查询的Logstore名称。|
|
51
|
+
|type| 字符串| 是| 查询Logstore数据的类型,在ListTopics接口中该参数必须为"topic"。|
|
52
|
+
|line| 整型| 否| 请求一次返回的Topic最大数目。取值范围为0~100,默认值为100。|
|
53
|
+
|token| 字符串| 否| 请求返回Topic的起始点(按字典序)。默认值为空字符串,表示从头开始查询 |Logstore中的日志Topic。
|
54
|
+
|
55
|
+
### [查询Logstore中的日志在时间轴上的分布](http://docs.aliyun.com/#/pub/sls/api/apilist&GetHistograms)
|
56
|
+
|
57
|
+
con.get_histograms("store")
|
58
|
+
|
59
|
+
|名称| 类型| 必选| 描述|
|
60
|
+
|----|----|------|------|
|
61
|
+
|logstorename| 字符串| 是| 需要查询日志的Logstore名称。|
|
62
|
+
|type| 字符串| 是| 查询Logstore数据的类型,在GetHistograms接口中该参数必须为"histogram"。|
|
63
|
+
|from| 整型| 是| 查询开始时间点(精度为秒,从1970-1-1 00:00:00 UTC计算起的秒数)。|
|
64
|
+
|to| 整型| 是| 查询结束时间点(精度为秒,从1970-1-1 00:00:00 UTC计算起的秒数)。|
|
65
|
+
|topic| 字符串| 否| 查询日志主题。|
|
66
|
+
|query| 字符串| 否| 查询表达式。关于查询表达式的详细语法请参考查询语法。|
|
67
|
+
|
68
|
+
### [查询Logstore中的日志数据](http://docs.aliyun.com/#/pub/sls/api/apilist&GetLogs)
|
69
|
+
|
70
|
+
con.get_logs("store", :topic => "xxx")
|
71
|
+
|
72
|
+
|名称 | 类型| 必选| 描述|
|
73
|
+
|---|---|---|------------|
|
74
|
+
|logstorename | 字符串| 是| 需要查询日志的Logstore名称。|
|
75
|
+
|type | 字符串| 是| 查询Logstore数据的类型,在GetLogs接口中该参数必须为"log"。|
|
76
|
+
|from | 整型| 是| 查询开始时间点(精度为秒,从1970-1-1 00:00:00 UTC计算起的秒数)。|
|
77
|
+
|to | 整型| 是| 查询结束时间点(精度为秒,从1970-1-1 00:00:00 UTC计算起的秒数)。|
|
78
|
+
|topic | 字符串| 否| 查询日志主题。|
|
79
|
+
|query | 字符串| 否| 查询表达式。关于查询表达式的详细语法请参考查询语法。|
|
80
|
+
|line | 整型| 否| 请求返回的最大日志条数。取值范围0~100,默认值为100。|
|
81
|
+
|offset | 整型| 否| 请求返回日志的起始点。取值范围0或正整数,默认值0。|
|
82
|
+
|reverse | 布尔型| 否| 是否按日志时间戳逆序返回日志。true表示逆序,false表示顺序,默认值为false。|
|
83
|
+
|
84
|
+
## 命令行用法
|
85
|
+
|
86
|
+
1. 生成配置文件
|
87
|
+
2. `PROJECT=[PROJECT] REGION=[REGION] SECRET=[SECRET] KEY=[KEY] sls setup`
|
88
|
+
1. 执行上传日志操作
|
89
|
+
2. `[PROJECT=[PROJECT]] sls put log_path store [topic]`
|
90
|
+
2. 上传日志操作是使用Tail方式执行,有增量日志产生的时候,会自动收集增量部分上传到阿里云
|
91
|
+
|
92
|
+
## fluentd-plugin-sls
|
93
|
+
|
94
|
+
可以结合fluentd,将日志解析好之后上传到阿里云上,实现日志的统一存储。
|
95
|
+
|
96
|
+
`gist`地址:`https://gist.github.com/charlescui/d2a231dbc85b11586fa0`
|
97
|
+
|
98
|
+
## Installation
|
99
|
+
|
100
|
+
Add this line to your application's Gemfile:
|
101
|
+
|
102
|
+
gem 'aliyun_sls_sdk'
|
103
|
+
|
104
|
+
And then execute:
|
105
|
+
|
106
|
+
$ bundle
|
107
|
+
|
108
|
+
Or install it yourself as:
|
109
|
+
|
110
|
+
$ gem install aliyun_sls_sdk
|
111
|
+
|
112
|
+
## Usage
|
113
|
+
|
114
|
+
TODO: Write usage instructions here
|
115
|
+
|
116
|
+
## Contributing
|
117
|
+
|
118
|
+
1. Fork it
|
119
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
120
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
121
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
122
|
+
5. Create new Pull Request
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'aliyun_sls_sdk/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "aliyun_sls_ruby3_sdk"
|
8
|
+
spec.version = AliyunSlsSdk::VERSION
|
9
|
+
spec.authors = ["langyong135"]
|
10
|
+
spec.email = ["langyong135@gmail.com"]
|
11
|
+
spec.description = %q{Gem for SDK of SLS of Aliyun}
|
12
|
+
spec.summary = %q{Gem for SDK of SLS of Aliyun, use it at your own risk}
|
13
|
+
spec.homepage = "https://help.aliyun.com/product/28958.html"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake", "~> 0"
|
22
|
+
spec.add_dependency "beefcake", "~> 1.2"
|
23
|
+
spec.add_dependency "file-tail", "~> 0"
|
24
|
+
spec.add_dependency "ruby-hmac", "~> 0"
|
25
|
+
spec.add_dependency "addressable", "~> 2.5"
|
26
|
+
spec.add_dependency "net-http-persistent", "~> 4.0.2"
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module AliyunSlsSdk
|
4
|
+
class CreateLogStoreResponse < LogResponse
|
5
|
+
|
6
|
+
def initialize(header)
|
7
|
+
super(header)
|
8
|
+
end
|
9
|
+
|
10
|
+
def log_print()
|
11
|
+
puts 'CreateLogStoreResponse:'
|
12
|
+
puts 'headers:' + self.all_headers.to_json
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module AliyunSlsSdk
|
2
|
+
class GetLogRequest < LogRequest
|
3
|
+
attr_accessor :project, :logstore, :fromTime, :toTime, :topic, :query, :line, :offset, :reverse
|
4
|
+
def initialize(project=nil, logstore=nil, fromTime=nil, toTime=nil, topic=nil,
|
5
|
+
query=nil, line=nil, offset=nil, reverse=nil)
|
6
|
+
@project = project
|
7
|
+
@logstore = logstore
|
8
|
+
@fromTime = fromTime
|
9
|
+
@toTime = toTime
|
10
|
+
@topic = topic
|
11
|
+
@query = query
|
12
|
+
@line = line
|
13
|
+
@offset = offset
|
14
|
+
@reverse = reverse
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module AliyunSlsSdk
|
2
|
+
class GetLogStoreResponse < LogResponse
|
3
|
+
|
4
|
+
attr_accessor :ttl, :shard_count, :logstore_name
|
5
|
+
def initialize(resp, header)
|
6
|
+
super(header)
|
7
|
+
puts resp
|
8
|
+
@logstore_name = resp["logstoreName"]
|
9
|
+
@ttl = resp["ttl"] ? resp["ttl"].to_i : 0
|
10
|
+
@shard_count = resp["shardCount"] ? resp["shardCount"].to_i : 0
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,196 @@
|
|
1
|
+
require "time"
|
2
|
+
require "addressable/uri"
|
3
|
+
require "net/http/persistent"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module AliyunSlsSdk
|
7
|
+
class LogClient
|
8
|
+
|
9
|
+
attr_reader :http
|
10
|
+
|
11
|
+
@@API_VERSION = "0.6.0"
|
12
|
+
@@USER_AGENT = "log-ruby-sdk-v-0.6.1"
|
13
|
+
def initialize(endpoint, accessKeyId, accessKeySecret, ssl_verify = false)
|
14
|
+
@endpoint = endpoint
|
15
|
+
@accessKeyId = accessKeyId
|
16
|
+
@accessKeySecret = accessKeySecret
|
17
|
+
@ssl_verify = ssl_verify
|
18
|
+
@http = Net::HTTP::Persistent.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_logstore(project_name, logstore_name)
|
22
|
+
headers = {}
|
23
|
+
params = {}
|
24
|
+
resource = "/logstores/" + logstore_name
|
25
|
+
resp, header = send("GET", project_name, nil, resource, params, headers)
|
26
|
+
return GetLogStoreResponse.new(resp, header)
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def create_logstore(project_name, logstore_name, ttl, shard_count)
|
31
|
+
headers = {}
|
32
|
+
params = {}
|
33
|
+
headers["x-log-bodyrawsize"] = '0'
|
34
|
+
headers["Content-Type"] = "application/json"
|
35
|
+
resource = "/logstores"
|
36
|
+
body = {}
|
37
|
+
body["logstoreName"] = logstore_name.encode("utf-8");
|
38
|
+
body["ttl"] = ttl;
|
39
|
+
body["shardCount"] = shard_count;
|
40
|
+
body_str = body.to_json;
|
41
|
+
resp, header = send("POST", project_name, body_str, resource, params, headers)
|
42
|
+
return CreateLogStoreResponse.new(header)
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def get_logs()
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
# 这里接受参数
|
51
|
+
# (project=nil, logstore=nil, topic=nil, source=nil, logitems=nil, hashKey = nil, compress = false)
|
52
|
+
# 其中 logitems = [{timestamp: Time.now.to_i, contents: [['aaa', '111'], ['ccc', 222]]}]
|
53
|
+
#
|
54
|
+
def put_logs(request)
|
55
|
+
if request.logitems.length > 4096
|
56
|
+
raise AliyunSlsSdk::PostBodyTooLarge, "log item is larger than 4096"
|
57
|
+
end
|
58
|
+
logGroup = Protobuf::LogGroup.new(:logs => [])
|
59
|
+
logGroup.topic = request.topic
|
60
|
+
logGroup.source = request.source
|
61
|
+
request.logitems.each { |logitem|
|
62
|
+
# log = Protobuf::Log.new(:time => logitem.timestamp, :contents => [])
|
63
|
+
# logGroup.logs << log
|
64
|
+
# contents = logitem.contents
|
65
|
+
# contents.each { |k, v|
|
66
|
+
# content = Protobuf::Log::Content.new(:key => k, :value => v)
|
67
|
+
# log.contents << content
|
68
|
+
# }
|
69
|
+
log = Protobuf::Log.new(:time => logitem.timestamp, :contents => [])
|
70
|
+
|
71
|
+
contents = logitem.contents
|
72
|
+
contents.each { |detail|
|
73
|
+
content = Protobuf::Log::Content.new(:key => detail[0], :value => detail[1])
|
74
|
+
log.contents << content
|
75
|
+
}
|
76
|
+
logGroup.logs << log
|
77
|
+
|
78
|
+
}
|
79
|
+
body = logGroup.encode.to_s
|
80
|
+
if body.length > 3 * 1024 * 1024
|
81
|
+
raise AliyunSlsSdk::PostBodyTooLarge, "content length is larger than 3MB"
|
82
|
+
end
|
83
|
+
headers = {}
|
84
|
+
headers['x-log-bodyrawsize'] = body.length.to_s
|
85
|
+
headers['Content-Type'] = 'application/x-protobuf'
|
86
|
+
is_compress = request.compress
|
87
|
+
|
88
|
+
compress_data = nil
|
89
|
+
if is_compress
|
90
|
+
headers['x-log-compresstype'] = 'deflate'
|
91
|
+
compress_data = Zlib::Deflate.deflate(body)
|
92
|
+
|
93
|
+
end
|
94
|
+
params = {}
|
95
|
+
logstore = request.logstore
|
96
|
+
project = request.project
|
97
|
+
resource = '/logstores/' + logstore
|
98
|
+
if request.hashkey
|
99
|
+
resource = '/logstores/' + logstore+"/shards/route"
|
100
|
+
params["key"] = request.hashkey
|
101
|
+
else
|
102
|
+
resource = '/logstores/' + logstore+"/shards/lb"
|
103
|
+
end
|
104
|
+
|
105
|
+
respHeaders = nil
|
106
|
+
if is_compress
|
107
|
+
respHeaders = send('POST', project, compress_data, resource, params, headers)
|
108
|
+
else
|
109
|
+
respHeaders = send('POST', project, body, resource, params, headers)
|
110
|
+
end
|
111
|
+
return PutLogsResponse.new(respHeaders[1])
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
private
|
118
|
+
def send(method, project, body, resource, params, headers, respons_body_type ='json')
|
119
|
+
if body
|
120
|
+
headers['Content-Length'] = body.bytesize.to_s
|
121
|
+
headers['Content-MD5'] = Util.cal_md5(body)
|
122
|
+
else
|
123
|
+
headers['Content-Length'] = '0'
|
124
|
+
headers["x-log-bodyrawsize"] = '0'
|
125
|
+
end
|
126
|
+
headers['x-log-apiversion'] = @@API_VERSION
|
127
|
+
headers['x-log-signaturemethod'] = 'hmac-sha1'
|
128
|
+
scheme = @ssl_verify ? "https" : "http"
|
129
|
+
url = "#{scheme}://" + project + "." + @endpoint
|
130
|
+
headers['Host'] = project + "." + @endpoint
|
131
|
+
headers['Date'] = headers["Date"] = DateTime.now.httpdate
|
132
|
+
signature = Util.get_request_authorization(method, resource,
|
133
|
+
@accessKeySecret, params, headers)
|
134
|
+
headers['Authorization'] = "LOG " + @accessKeyId + ':' + signature
|
135
|
+
url = url + resource
|
136
|
+
return sendRequest(method, url, params, body, headers, respons_body_type)
|
137
|
+
end
|
138
|
+
|
139
|
+
def loadJson(respText, requestId)
|
140
|
+
if respText.empty?
|
141
|
+
return nil
|
142
|
+
else
|
143
|
+
begin
|
144
|
+
return JSON.parse(respText)
|
145
|
+
rescue JSON::ParserError => e
|
146
|
+
raise LogException.new("BadResponse", "Bad json format:\n#{respText}", requestId)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def sendRequest(method, url, params, body, headers, respons_body_type = 'json')
|
152
|
+
statusCode, respBody, respHeaders = getHttpResponse(method, url, params, body, headers)
|
153
|
+
if respHeaders['x-log-requestid']
|
154
|
+
requestId = respHeaders['x-log-requestid']
|
155
|
+
else
|
156
|
+
requestId = ''
|
157
|
+
end
|
158
|
+
|
159
|
+
if statusCode == '200'
|
160
|
+
if respons_body_type == 'json'
|
161
|
+
return loadJson(respBody, requestId), respHeaders
|
162
|
+
else
|
163
|
+
return respBody, respHeaders
|
164
|
+
end
|
165
|
+
end
|
166
|
+
respJson = loadJson(respBody, requestId)
|
167
|
+
if respJson["errorCode"] and respJson["errorMessage"]
|
168
|
+
raise LogException.new(respJson["errorCode"], respJson["errorMessage"], requestId)
|
169
|
+
else
|
170
|
+
exStr = ""
|
171
|
+
if respBody
|
172
|
+
exStr = ". Return Json is #{respBody}"
|
173
|
+
else
|
174
|
+
exStr = "."
|
175
|
+
end
|
176
|
+
raise LogException.new("LogRequestError", "Request is failed. Http code is #{statusCode} #{exStr}", requestId)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def getHttpResponse(method, url, params, body, headers)
|
181
|
+
headers['User-Agent'] = @@USER_AGENT
|
182
|
+
r = nil
|
183
|
+
uri = Addressable::URI.parse(url)
|
184
|
+
uri.query_values = params
|
185
|
+
methodRequest = nil
|
186
|
+
if method.downcase == 'get'
|
187
|
+
methodRequest = Net::HTTP::Get.new(uri.request_uri, headers)
|
188
|
+
elsif method.downcase == 'post'
|
189
|
+
methodRequest = Net::HTTP::Post.new(uri.request_uri, headers)
|
190
|
+
methodRequest.body = body
|
191
|
+
end
|
192
|
+
response = @http.request uri, methodRequest
|
193
|
+
return response.code, response.body, response.to_hash
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
module AliyunSlsSdk
|
3
|
+
class LogException < StandardError
|
4
|
+
attr_accessor :errorCode, :errorMessage, :requestId
|
5
|
+
def initialize(errorCode, errorMessage, requestId)
|
6
|
+
@errorCode = errorCode
|
7
|
+
@errorMessage = errorMessage
|
8
|
+
@requestId = requestId
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s()
|
12
|
+
"LogException: \n{\n ErrorCode: #{@errorCode}\n ErrorMessage: #{@errorMessage}\n RequestId: #{@requestId}\n}\n"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "time"
|
2
|
+
|
3
|
+
module AliyunSlsSdk
|
4
|
+
class LogItem
|
5
|
+
|
6
|
+
attr_accessor :timestamp, :contents
|
7
|
+
# contents is a hash
|
8
|
+
def initialize(timestamp, contents)
|
9
|
+
if not timestamp
|
10
|
+
@timestamp = Time.now.to_i
|
11
|
+
end
|
12
|
+
@contents = contents
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module AliyunSlsSdk
|
2
|
+
class LogResponse
|
3
|
+
attr_accessor :request_id,:all_headers
|
4
|
+
|
5
|
+
def initialize(headers)
|
6
|
+
@all_headers = headers
|
7
|
+
if headers['x-log-requestid']
|
8
|
+
@request_id = headers['x-log-requestid']
|
9
|
+
end
|
10
|
+
@request_id = ''
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_header(key)
|
14
|
+
return @all_headers[key]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'beefcake'
|
2
|
+
|
3
|
+
module AliyunSlsSdk
|
4
|
+
module Protobuf
|
5
|
+
|
6
|
+
# message Log
|
7
|
+
# {
|
8
|
+
# required uint32 time = 1; // UNIX Time Format
|
9
|
+
# message Content
|
10
|
+
# {
|
11
|
+
# required string key = 1;
|
12
|
+
# required string value = 2;
|
13
|
+
# }
|
14
|
+
# repeated Content contents= 2;
|
15
|
+
# }
|
16
|
+
|
17
|
+
# message LogGroup
|
18
|
+
# {
|
19
|
+
# repeated Log logs= 1;
|
20
|
+
# optional string reserved =2; // 内部字段,不需要填写
|
21
|
+
# optional string topic = 3;
|
22
|
+
# optional string source = 4;
|
23
|
+
# }
|
24
|
+
|
25
|
+
class Log
|
26
|
+
include Beefcake::Message
|
27
|
+
|
28
|
+
required :time, :uint32, 1
|
29
|
+
|
30
|
+
class Content
|
31
|
+
include Beefcake::Message
|
32
|
+
|
33
|
+
required :key, :string, 1
|
34
|
+
required :value, :string, 2
|
35
|
+
end
|
36
|
+
|
37
|
+
repeated :contents, Content, 2
|
38
|
+
end
|
39
|
+
|
40
|
+
class LogGroup
|
41
|
+
include Beefcake::Message
|
42
|
+
|
43
|
+
repeated :logs, Log, 1
|
44
|
+
optional :reserved, :string, 2
|
45
|
+
optional :topic, :string, 3
|
46
|
+
optional :source, :string, 4
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
module AliyunSlsSdk
|
3
|
+
class PutLogsRequest < LogRequest
|
4
|
+
attr_accessor :project, :logstore, :topic, :source, :logitems, :hashkey, :compress
|
5
|
+
def initialize(project=nil, logstore=nil, topic=nil, source=nil, logitems=nil, hashKey = nil, compress = false)
|
6
|
+
@project = project
|
7
|
+
@logstore = logstore
|
8
|
+
@topic = topic
|
9
|
+
@source = source
|
10
|
+
@logitems = logitems
|
11
|
+
@hashkey = hashKey
|
12
|
+
@compress = compress
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "uri"
|
2
|
+
require "base64"
|
3
|
+
require "zlib"
|
4
|
+
require "hmac-sha1"
|
5
|
+
|
6
|
+
|
7
|
+
module AliyunSlsSdk
|
8
|
+
class Util
|
9
|
+
def self.compress_data(data)
|
10
|
+
Zlib::Deflate.deflate(data, 6)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.cal_md5(content)
|
14
|
+
Digest::MD5.hexdigest(content).upcase
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.hmac_sha1(content, key)
|
18
|
+
Base64.encode64((HMAC::SHA1.new(key) << content).digest).rstrip()
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.canonicalized_log_headers(headers)
|
22
|
+
h = {}
|
23
|
+
headers.each { |k, v|
|
24
|
+
if k =~ /x-log-.*/ or k =~ /x-acs-.*/
|
25
|
+
h[k.downcase] = v
|
26
|
+
end
|
27
|
+
}
|
28
|
+
h.keys.sort.map { |e|
|
29
|
+
"#{e}:#{h[e].gsub(/^\s+/, '')}"
|
30
|
+
}.join($/) + $/
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.url_encode(params)
|
34
|
+
# todo
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.canonicalized_resource(resource, params)
|
38
|
+
if not params.empty?
|
39
|
+
urlString = params.keys.sort.map { |k|
|
40
|
+
"#{k}=#{params[k]}"
|
41
|
+
}.join('&')
|
42
|
+
return resource+"?"+urlString
|
43
|
+
else
|
44
|
+
return resource
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.get_request_authorization(method, resource, key, params, headers)
|
49
|
+
if not key
|
50
|
+
return ''
|
51
|
+
end
|
52
|
+
content = method + "\n"
|
53
|
+
if headers['Content-MD5']
|
54
|
+
content += headers['Content-MD5']
|
55
|
+
end
|
56
|
+
content += "\n"
|
57
|
+
if headers['Content-Type']
|
58
|
+
content += headers['Content-Type']
|
59
|
+
end
|
60
|
+
content += "\n"
|
61
|
+
content += headers['Date']+"\n"
|
62
|
+
content += Util.canonicalized_log_headers(headers)
|
63
|
+
content += Util.canonicalized_resource(resource, params)
|
64
|
+
return Util.hmac_sha1(content, key)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'aliyun_sls_sdk', 'version.rb')
|
2
|
+
require File.join(File.dirname(__FILE__), 'aliyun_sls_sdk', 'protobuf.rb')
|
3
|
+
require File.join(File.dirname(__FILE__), 'aliyun_sls_sdk', 'log_request.rb')
|
4
|
+
require File.join(File.dirname(__FILE__), 'aliyun_sls_sdk', 'get_log_request.rb')
|
5
|
+
require File.join(File.dirname(__FILE__), 'aliyun_sls_sdk', 'put_logs_request.rb')
|
6
|
+
require File.join(File.dirname(__FILE__), 'aliyun_sls_sdk', 'log_response.rb')
|
7
|
+
require File.join(File.dirname(__FILE__), 'aliyun_sls_sdk', 'put_logs_response.rb')
|
8
|
+
require File.join(File.dirname(__FILE__), 'aliyun_sls_sdk', 'util.rb')
|
9
|
+
require File.join(File.dirname(__FILE__), 'aliyun_sls_sdk', 'log_client.rb')
|
10
|
+
require File.join(File.dirname(__FILE__), 'aliyun_sls_sdk', 'log_item.rb')
|
11
|
+
require File.join(File.dirname(__FILE__), 'aliyun_sls_sdk', 'create_log_store_response.rb')
|
12
|
+
require File.join(File.dirname(__FILE__), 'aliyun_sls_sdk', 'get_log_store_response.rb')
|
13
|
+
require File.join(File.dirname(__FILE__), 'aliyun_sls_sdk', 'log_exception.rb')
|
14
|
+
|
15
|
+
module AliyunSlsSdk
|
16
|
+
class PostBodyInvalid < RuntimeError;
|
17
|
+
end
|
18
|
+
class SLSInvalidTimestamp < RuntimeError;
|
19
|
+
end
|
20
|
+
class SLSInvalidEncoding < RuntimeError;
|
21
|
+
end
|
22
|
+
class SLSInvalidKey < RuntimeError;
|
23
|
+
end
|
24
|
+
class PostBodyTooLarge < RuntimeError;
|
25
|
+
end
|
26
|
+
class PostBodyUncompressError < RuntimeError;
|
27
|
+
end
|
28
|
+
class SLSLogStoreNotExist < RuntimeError;
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aliyun_sls_ruby3_sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.10.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- langyong135
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-04-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: beefcake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: file-tail
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: ruby-hmac
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: addressable
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.5'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.5'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: net-http-persistent
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 4.0.2
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 4.0.2
|
111
|
+
description: Gem for SDK of SLS of Aliyun
|
112
|
+
email:
|
113
|
+
- langyong135@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- aliyun_sls_sdk.gemspec
|
123
|
+
- lib/aliyun_sls_sdk.rb
|
124
|
+
- lib/aliyun_sls_sdk/create_log_store_response.rb
|
125
|
+
- lib/aliyun_sls_sdk/get_log_request.rb
|
126
|
+
- lib/aliyun_sls_sdk/get_log_store_response.rb
|
127
|
+
- lib/aliyun_sls_sdk/log_client.rb
|
128
|
+
- lib/aliyun_sls_sdk/log_exception.rb
|
129
|
+
- lib/aliyun_sls_sdk/log_item.rb
|
130
|
+
- lib/aliyun_sls_sdk/log_request.rb
|
131
|
+
- lib/aliyun_sls_sdk/log_response.rb
|
132
|
+
- lib/aliyun_sls_sdk/protobuf.rb
|
133
|
+
- lib/aliyun_sls_sdk/put_logs_request.rb
|
134
|
+
- lib/aliyun_sls_sdk/put_logs_response.rb
|
135
|
+
- lib/aliyun_sls_sdk/util.rb
|
136
|
+
- lib/aliyun_sls_sdk/version.rb
|
137
|
+
homepage: https://help.aliyun.com/product/28958.html
|
138
|
+
licenses:
|
139
|
+
- MIT
|
140
|
+
metadata: {}
|
141
|
+
post_install_message:
|
142
|
+
rdoc_options: []
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
requirements: []
|
156
|
+
rubygems_version: 3.3.26
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Gem for SDK of SLS of Aliyun, use it at your own risk
|
160
|
+
test_files: []
|