azure-loganalytics-datacollector-api 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6b8a3ab05139f664f5b86e7a9f08b7e5cb2f2adb6b638df9a9cef9328b23aed
4
- data.tar.gz: eb5623f23e94faf5a79f7b595f3b9f5fe1b2dccacf75eb19e59c1c2a4b846800
3
+ metadata.gz: c4cec423d59632c9e791ddcc953fc3cfc9b6a22886d1a0fa32ff24611b7ee107
4
+ data.tar.gz: c8dcf1beb62710c24ef30d0b52f44b316c218efd1668999d0eb077707a2f9f6d
5
5
  SHA512:
6
- metadata.gz: dad33a98f56baee3a6e16ed74683678168bafe62f55aef976c0818159be20affc99126aa1ef1c9369f935cc56342c43d19817f51b74e4f74c37475f5405c2ca1
7
- data.tar.gz: 6d166eca78143d143cf3a4875dd9eeb5e4e7742ab8e889800e1f6501f17f21a9a3a5308c1b438f50557cd28f742f6b211fc36fd92c6d6b25a18606e9de8e3699
6
+ metadata.gz: 2a4343fa994ff46da725a6c03ef00c4973cddd5275d1afe93a8152e92026284e649b553002968d9c9e6d690ccbe06016a165eb42aeb7701d102aaa97e3ac00e8
7
+ data.tar.gz: 2adfe7e4cebe468be3c6bb548fec657ef6ed292a068376ca46a3b2cc27fa504ae3fd62d4a7c1acd64be801dc8da12ea107f4c394ad232246378fcca7b682c786
@@ -1,3 +1,6 @@
1
+ ## 0.2.0
2
+ * Support setting the x-ms-AzureResourceId Header - [issue #8](https://github.com/yokawasa/azure-log-analytics-data-collector/issues/8)
3
+
1
4
  ## 0.1.6
2
5
  * fix CVE-2020-8130 - [issue #7](https://github.com/yokawasa/azure-log-analytics-data-collector/issues/7)
3
6
 
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # azure-log-analytics-data-collector Ruby Client
2
- Azure Log Analytics Data Collector API Ruby Client
2
+
3
+ [Azure Log Analytics Data Collector API](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/data-collector-api) Client Libraries for Ruby. The repository was originally created for multiple programming languages, but it was refactored as a dedicated one for Ruby client. Python and PHP client libraries were moved to [azure-log-analytics-data-colloector-python](https://github.com/yokawasa/azure-log-analytics-data-collector-python) and [azure-log-analytics-data-colloector-php](https://github.com/yokawasa/azure-log-analytics-data-collector-php) respectively.
4
+
3
5
 
4
6
  ## Installation
5
7
  ```bash
@@ -78,7 +80,51 @@ else
78
80
  end
79
81
  ```
80
82
 
81
- ### Sample3 - use proxy to access the API
83
+ ### Sample3 - With time_generated_field and azure_resource_id option
84
+ Supported setting azure_resource_id option from version [0.2.0](https://github.com/yokawasa/azure-log-analytics-data-collector/releases/tag/v0.2.0)
85
+ ```ruby
86
+ require "azure/loganalytics/datacollectorapi/client"
87
+
88
+ customer_id = '<Customer ID aka WorkspaceID String>'
89
+ shared_key = '<The primary or the secondary Connected Sources client authentication key>'
90
+ log_type = "MyCustomLog"
91
+
92
+ posting_records = []
93
+ record1= {
94
+ :string => "MyText1",
95
+ :boolean => true,
96
+ :number => 100,
97
+ :timegen => "2017-11-23T11:13:35.576Z" # YYYY-MM-DDThh:mm:ssZ
98
+ }
99
+ record2= {
100
+ :string => "MyText2",
101
+ :boolean => false,
102
+ :number => 200,
103
+ :timegen => "2017-11-23T12:13:35.576Z" # YYYY-MM-DDThh:mm:ssZ
104
+ }
105
+ posting_records.push(record1)
106
+ posting_records.push(record2)
107
+
108
+ time_generated_field = "timegen"
109
+
110
+ # Azure Resource ID
111
+ # [Azure Resource ID Format]
112
+ # /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}
113
+ azure_resource_id ="/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/otherResourceGroup/providers/Microsoft.Storage/storageAccounts/examplestorage"
114
+
115
+ client=Azure::Loganalytics::Datacollectorapi::Client::new( customer_id, shared_key)
116
+ res = client.post_data(log_type, posting_records, time_generated_field, azure_resource_id)
117
+ puts res
118
+ puts "res code=#{res.code}"
119
+
120
+ if Azure::Loganalytics::Datacollectorapi::Client.is_success(res)
121
+ puts "operation was succeeded!"
122
+ else
123
+ puts "operation was failured!"
124
+ end
125
+ ```
126
+
127
+ ### Sample4 - use proxy to access the API
82
128
  ```ruby
83
129
  require "azure/loganalytics/datacollectorapi/client"
84
130
 
@@ -114,4 +160,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/yokawa
114
160
  ## License
115
161
 
116
162
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
117
-
@@ -0,0 +1,12 @@
1
+ # Sample codes for azure-log-analytics-data-collector
2
+ [Azure Log Analytics HTTP Data Collecotr API](https://docs.microsoft.com/en-us/azure/log-analytics/log-analytics-data-collector-api) Client libraries
3
+
4
+ ## Client libraries and Sample code
5
+
6
+ | Language | Source Code | Project URL |
7
+ | ------------- | ------------- |------------- |
8
+ | Ruby | This repository | [Rubygem Package](https://rubygems.org/gems/azure-loganalytics-datacollector-api) |
9
+ | Python | [Source code](https://github.com/yokawasa/azure-log-analytics-data-collector-python) | [Python Package](https://pypi.python.org/pypi/azure-log-analytics-data-collector-api) |
10
+ | PHP | [Source code](https://github.com/yokawasa/azure-log-analytics-data-collector-php) | NONE |
11
+ | CSharp | [Sample Code](https://docs.microsoft.com/en-us/azure/log-analytics/log-analytics-data-collector-api#sample-requests) | NONE |
12
+ | PowerShell | [Sample Code](https://docs.microsoft.com/en-us/azure/log-analytics/log-analytics-data-collector-api#sample-requests) | NONE |
@@ -8,7 +8,7 @@ module Azure
8
8
 
9
9
  class Client
10
10
 
11
- def initialize (customer_id, shared_key,endpoint ='ods.opinsights.azure.com')
11
+ def initialize (customer_id, shared_key, endpoint ='ods.opinsights.azure.com')
12
12
  require 'rest-client'
13
13
  require 'json'
14
14
  require 'openssl'
@@ -18,9 +18,10 @@ module Azure
18
18
  @customer_id = customer_id
19
19
  @shared_key = shared_key
20
20
  @endpoint = endpoint
21
+ @default_azure_resource_id = ''
21
22
  end
22
23
 
23
- def post_data(log_type, json_records, record_timestamp ='')
24
+ def post_data(log_type, json_records, record_timestamp ='', azure_resource_id ='' )
24
25
  raise ConfigError, 'no log_type' if log_type.empty?
25
26
  raise ConfigError, 'log_type must be only alpha characters' if not is_alpha(log_type)
26
27
  raise ConfigError, 'no json_records' if json_records.empty?
@@ -35,6 +36,7 @@ module Azure
35
36
  'Authorization' => sig,
36
37
  'Log-Type' => log_type,
37
38
  'x-ms-date' => date,
39
+ 'x-ms-AzureResourceId' => azure_resource_id.empty? ? @default_azure_resource_id : azure_resource_id,
38
40
  'time-generated-field' => record_timestamp
39
41
  }
40
42
 
@@ -45,6 +47,10 @@ module Azure
45
47
  def set_proxy(proxy='')
46
48
  RestClient.proxy = proxy.empty? ? ENV['http_proxy'] : proxy
47
49
  end
50
+
51
+ def set_default_azure_resoruce_id(azure_resource_id)
52
+ @default_azure_resource_id = azure_resource_id
53
+ end
48
54
 
49
55
  def self.is_success(res)
50
56
  return (res.code == 200) ? true : false
@@ -1,7 +1,7 @@
1
1
  module Azure
2
2
  module Loganalytics
3
3
  module Datacollectorapi
4
- VERSION = "0.1.6"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
@@ -9,11 +9,11 @@ describe Azure::Loganalytics::Datacollectorapi::Client do
9
9
  # expect(false).to eq(true)
10
10
  #end
11
11
 
12
- it "posting data to datacollector api" do
13
- customer_id = '<Customer ID aka WorkspaceID String>'
14
- shared_key = '<Primary Key String>'
15
- log_type = "MyCustomLog"
12
+ customer_id = '<Customer ID aka WorkspaceID String>'
13
+ shared_key = '<Primary Key String>'
14
+ log_type = "MyCustomLog"
16
15
 
16
+ it "posting data to datacollector api" do
17
17
  json_records = []
18
18
  record1= {
19
19
  :string => "MyText1",
@@ -33,4 +33,53 @@ describe Azure::Loganalytics::Datacollectorapi::Client do
33
33
  expect(Azure::Loganalytics::Datacollectorapi::Client.is_success(res)).to eq(true)
34
34
  end
35
35
 
36
+ it "posting data to datacollector api with time-generated-field" do
37
+ json_records = []
38
+ record1= {
39
+ :string => "MyText1",
40
+ :boolean => true,
41
+ :number => 100,
42
+ :timegen => "2020-05-05T11:13:35.576Z" # YYYY-MM-DDThh:mm:ssZ
43
+ }
44
+ record2= {
45
+ :string => "MyText2",
46
+ :boolean => false,
47
+ :number => 200,
48
+ :timegen => "2020-05-05T12:13:35.576Z" # YYYY-MM-DDThh:mm:ssZ
49
+ }
50
+ json_records.push(record1)
51
+ json_records.push(record2)
52
+
53
+ time_generated_field = "timegen"
54
+ client=Azure::Loganalytics::Datacollectorapi::Client::new( customer_id, shared_key)
55
+ res = client.post_data(log_type, json_records, time_generated_field)
56
+ expect(Azure::Loganalytics::Datacollectorapi::Client.is_success(res)).to eq(true)
57
+ end
58
+
59
+ it "posting data to datacollector api with azure-resource-id" do
60
+ json_records = []
61
+ record1= {
62
+ :string => "MyText1",
63
+ :boolean => true,
64
+ :number => 100
65
+ }
66
+ record2= {
67
+ :string => "MyText2",
68
+ :boolean => false,
69
+ :number => 200
70
+ }
71
+ json_records.push(record1)
72
+ json_records.push(record2)
73
+
74
+ time_generated_field = ""
75
+ # Azure Resource ID
76
+ # https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-resource#resourceid
77
+ # /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}
78
+ azure_resource_id ="/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/otherResourceGroup/providers/Microsoft.Storage/storageAccounts/examplestorage"
79
+
80
+ client=Azure::Loganalytics::Datacollectorapi::Client::new( customer_id, shared_key)
81
+ res = client.post_data(log_type, json_records, time_generated_field, azure_resource_id)
82
+ expect(Azure::Loganalytics::Datacollectorapi::Client.is_success(res)).to eq(true)
83
+ end
84
+
36
85
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: azure-loganalytics-datacollector-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoichi Kawasaki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-18 00:00:00.000000000 Z
11
+ date: 2020-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -68,6 +68,7 @@ files:
68
68
  - LICENSE.txt
69
69
  - README.md
70
70
  - Rakefile
71
+ - SampleCodes.md
71
72
  - azure-loganalytics-datacollector-api.gemspec
72
73
  - bin/console
73
74
  - bin/setup
@@ -94,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  - !ruby/object:Gem::Version
95
96
  version: '0'
96
97
  requirements: []
97
- rubygems_version: 3.0.6
98
+ rubygems_version: 3.1.3
98
99
  signing_key:
99
100
  specification_version: 4
100
101
  summary: Azure Log Analytics Data Collector API Ruby Client