Class: AliyunSlsSdk::LogClient

Inherits:
Object
  • Object
show all
Defined in:
lib/aliyun_sls_sdk/log_client.rb

Constant Summary collapse

@@API_VERSION =
"0.6.0"
@@USER_AGENT =
"log-ruby-sdk-v-0.6.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, accessKeyId, accessKeySecret, ssl_verify = false) ⇒ LogClient

Returns a new instance of LogClient.



13
14
15
16
17
18
19
# File 'lib/aliyun_sls_sdk/log_client.rb', line 13

def initialize(endpoint, accessKeyId, accessKeySecret, ssl_verify = false)
  @endpoint = endpoint
  @accessKeyId = accessKeyId
  @accessKeySecret = accessKeySecret
  @ssl_verify = ssl_verify
  @http = Net::HTTP::Persistent.new
end

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



9
10
11
# File 'lib/aliyun_sls_sdk/log_client.rb', line 9

def http
  @http
end

Instance Method Details

#create_logstore(project_name, logstore_name, ttl, shard_count) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/aliyun_sls_sdk/log_client.rb', line 30

def create_logstore(project_name, logstore_name, ttl, shard_count)
  headers = {}
  params = {}
  headers["x-log-bodyrawsize"] = '0'
  headers["Content-Type"] = "application/json"
  resource = "/logstores"
  body = {}
  body["logstoreName"] = logstore_name.encode("utf-8");
  body["ttl"] = ttl;
  body["shardCount"] = shard_count;
  body_str = body.to_json;
  resp, header = send("POST", project_name, body_str, resource, params, headers)
  return CreateLogStoreResponse.new(header)
end

#get_logsObject



46
47
48
# File 'lib/aliyun_sls_sdk/log_client.rb', line 46

def get_logs()

end

#get_logstore(project_name, logstore_name) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/aliyun_sls_sdk/log_client.rb', line 21

def get_logstore(project_name, logstore_name)
  headers = {}
  params = {}
  resource = "/logstores/" + logstore_name
  resp, header = send("GET", project_name, nil, resource, params, headers)
  return GetLogStoreResponse.new(resp, header)
end

#put_logs(request) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/aliyun_sls_sdk/log_client.rb', line 51

def put_logs(request)
  if request.logitems.length > 4096
    raise AliyunSls::PostBodyTooLarge, "log item is larger than 4096"
  end
  logGroup = Protobuf::LogGroup.new(:logs => [])
  logGroup.topic = request.topic
  logGroup.source = request.source
  request.logitems.each { |logitem|
    log = Protobuf::Log.new(:time => logitem.timestamp, :contents => [])
    logGroup.logs << log
    contents = logitem.contents
    contents.each { |k, v|
      content = Protobuf::Log::Content.new(:key => k, :value => v)
      log.contents <<  content
    }
  }
  body = logGroup.encode.to_s
  if body.length > 3 * 1024 * 1024
    raise AliyunSls::PostBodyTooLarge, "content length is larger than 3MB"
  end
  headers = {}
  headers['x-log-bodyrawsize'] = body.length.to_s
  headers['Content-Type'] = 'application/x-protobuf'
  is_compress = request.compress

  compress_data = nil
  if is_compress
      headers['x-log-compresstype'] = 'deflate'
      compress_data = Zlib::Deflate.deflate(body)

  end
  params = {}
  logstore = request.logstore
  project = request.project
  resource = '/logstores/' + logstore
  if request.hashkey
      resource = '/logstores/' + logstore+"/shards/route"
      params["key"] = request.hashkey
  else
      resource = '/logstores/' + logstore+"/shards/lb"
  end

  respHeaders = nil
  if is_compress
      respHeaders = send('POST', project, compress_data, resource, params, headers)
  else
      respHeaders = send('POST', project, body, resource, params, headers)
  end
  return PutLogsResponse.new(respHeaders[1])

end