Skip to content

Commit 02293f9

Browse files
committed
Release 0.2.0
1 parent 11900ab commit 02293f9

File tree

5 files changed

+110
-8
lines changed

5 files changed

+110
-8
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
14
## 0.1.6
25
* fix CVE-2020-8130 - [issue #7](https://github.com/yokawasa/azure-log-analytics-data-collector/issues/7)
36

README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,51 @@ else
8080
end
8181
```
8282

83-
### 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
84128
```ruby
85129
require "azure/loganalytics/datacollectorapi/client"
86130

lib/azure/loganalytics/datacollectorapi/client.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Datacollectorapi
88

99
class Client
1010

11-
def initialize (customer_id, shared_key,endpoint ='ods.opinsights.azure.com')
11+
def initialize (customer_id, shared_key, endpoint ='ods.opinsights.azure.com')
1212
require 'rest-client'
1313
require 'json'
1414
require 'openssl'
@@ -18,9 +18,10 @@ def initialize (customer_id, shared_key,endpoint ='ods.opinsights.azure.com')
1818
@customer_id = customer_id
1919
@shared_key = shared_key
2020
@endpoint = endpoint
21+
@default_azure_resource_id = ''
2122
end
2223

23-
def post_data(log_type, json_records, record_timestamp ='')
24+
def post_data(log_type, json_records, record_timestamp ='', azure_resource_id ='' )
2425
raise ConfigError, 'no log_type' if log_type.empty?
2526
raise ConfigError, 'log_type must be only alpha characters' if not is_alpha(log_type)
2627
raise ConfigError, 'no json_records' if json_records.empty?
@@ -35,6 +36,7 @@ def post_data(log_type, json_records, record_timestamp ='')
3536
'Authorization' => sig,
3637
'Log-Type' => log_type,
3738
'x-ms-date' => date,
39+
'x-ms-AzureResourceId' => azure_resource_id.empty? ? @default_azure_resource_id : azure_resource_id,
3840
'time-generated-field' => record_timestamp
3941
}
4042

@@ -45,6 +47,10 @@ def post_data(log_type, json_records, record_timestamp ='')
4547
def set_proxy(proxy='')
4648
RestClient.proxy = proxy.empty? ? ENV['http_proxy'] : proxy
4749
end
50+
51+
def set_default_azure_resoruce_id(azure_resource_id)
52+
@default_azure_resource_id = azure_resource_id
53+
end
4854

4955
def self.is_success(res)
5056
return (res.code == 200) ? true : false
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Azure
22
module Loganalytics
33
module Datacollectorapi
4-
VERSION = "0.1.6"
4+
VERSION = "0.2.0"
55
end
66
end
77
end

spec/azure/loganalytics/datacollectorapi/client_spec.rb

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
# expect(false).to eq(true)
1010
#end
1111

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"
1615

16+
it "posting data to datacollector api" do
1717
json_records = []
1818
record1= {
1919
:string => "MyText1",
@@ -33,4 +33,53 @@
3333
expect(Azure::Loganalytics::Datacollectorapi::Client.is_success(res)).to eq(true)
3434
end
3535

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+
3685
end

0 commit comments

Comments
 (0)