Skip to content

Commit 146c409

Browse files
authored
Merge pull request Azure#9364 from arolshan/OperationalInsights-DataSources-FixCustomLogModel
Fix DateTimeExtraction model - Bug Fix
2 parents bbb97ea + 753277e commit 146c409

File tree

5 files changed

+216
-18
lines changed

5 files changed

+216
-18
lines changed

src/OperationalInsights/OperationalInsights.Test/ScenarioTests/DataSourceTests.ps1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,14 @@ function Test-CreateAllKindsOfDataSource
132132
# linux performance data source
133133
$linuxPerfDataSource = New-AzOperationalInsightsLinuxPerformanceObjectDataSource -Workspace $workspace -Name "MemoryLinux" -ObjectName "Memory" -InstanceName * -CounterNames "Available bytes" -IntervalSeconds 10
134134

135-
# customlog
136-
$customLogRawJson = '{"customLogName":"Validation_CL","description":"test","inputs":[{"location":{"fileSystemLocations":{"linuxFileTypeLogPaths":null,"windowsFileTypeLogPaths":["C:\\e2e\\Evan\\ArubaSECURITY\\*.log"]}},"recordDelimiter":{"regexDelimiter":{"pattern":"\\n","matchIndex":0}}}],"extractions":[{"extractionName":"TimeGenerated","extractionType":"DateTime","extractionProperties":{"dateTimeExtraction":{"regex":null,"joinStringRegex":null}}}]}'
135+
# customlog, regex string
136+
$customLogRawJson = '{"customLogName":"Validation_CL","description":"test","inputs":[{"location":{"fileSystemLocations":{"linuxFileTypeLogPaths":null,"windowsFileTypeLogPaths":["C:\\e2e\\Evan\\ArubaSECURITY\\*.log"]}},"recordDelimiter":{"regexDelimiter":{"pattern":"\\n","matchIndex":0}}}],"extractions":[{"extractionName":"TimeGenerated","extractionType":"DateTime","extractionProperties":{"dateTimeExtraction":{"regex":"((\\d{2})|(\\d{4}))-([0-1]\\d)-(([0-3]\\d)|(\\d))\\s((\\d)|([0-1]\\d)|(2[0-4])):[0-5][0-9]:[0-5][0-9]","joinStringRegex":null}}}]}'
137137
$customLogDataSource = New-AzOperationalInsightsCustomLogDataSource -Workspace $workspace -CustomLogRawJson $customLogRawJson -Name "MyCustomLog"
138138

139+
# customlog
140+
$customLogRawJson2 = '{"customLogName":"Validation_CL2","description":"test","inputs":[{"location":{"fileSystemLocations":{"linuxFileTypeLogPaths":null,"windowsFileTypeLogPaths":["C:\\e2e\\Evan\\ArubaSECURITY\\*.log"]}},"recordDelimiter":{"regexDelimiter":{"pattern":"\\n","matchIndex":0}}}],"extractions":[{"extractionName":"TimeGenerated","extractionType":"DateTime","extractionProperties":{"dateTimeExtraction":{"regex":[{"matchIndex":0,"numberdGroup":null,"pattern":"((\\d{2})|(\\d{4}))-([0-1]\\d)-(([0-3]\\d)|(\\d))\\s((\\d)|([0-1]\\d)|(2[0-4])):[0-5][0-9]:[0-5][0-9]"}],"joinStringRegex":null}}}]}'
141+
$customLogDataSource2 = New-AzOperationalInsightsCustomLogDataSource -Workspace $workspace -CustomLogRawJson $customLogRawJson2 -Name "MyCustomLog2"
142+
139143
# ApplicationInsights data source
140144
$applicationInsightsDataSource1 = New-AzOperationalInsightsApplicationInsightsDataSource -Workspace $workspace -ApplicationSubscriptionId $subId1 -ApplicationResourceGroupName $rgname -ApplicationName "ai-app"
141145
Assert-NotNull $applicationInsightsDataSource1
@@ -183,4 +187,4 @@ function Test-ToggleSingletonDataSourceState
183187
Enable-AzOperationalInsightsLinuxSyslogCollection -Workspace $workspace
184188
Disable-AzOperationalInsightsLinuxSyslogCollection -Workspace $workspace
185189

186-
}
190+
}

src/OperationalInsights/OperationalInsights.Test/SessionRecords/Microsoft.Azure.Commands.OperationalInsights.Test.DataSourceTests/TestCreateAllKindsOfDataSource.json

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,144 @@
10661066
},
10671067
"StatusCode": 200
10681068
},
1069+
{
1070+
"RequestUri": "/subscriptions/a6383be3-f0e8-4968-93d5-10f2625f5bb5/resourcegroups/onesdk9967/providers/Microsoft.OperationalInsights/workspaces/AzTestonesdk5206/dataSources/MyCustomLog2?api-version=2015-11-01-preview",
1071+
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvYTYzODNiZTMtZjBlOC00OTY4LTkzZDUtMTBmMjYyNWY1YmI1L3Jlc291cmNlZ3JvdXBzL29uZXNkazk5NjcvcHJvdmlkZXJzL01pY3Jvc29mdC5PcGVyYXRpb25hbEluc2lnaHRzL3dvcmtzcGFjZXMvQXpUZXN0b25lc2RrNTIwNi9kYXRhU291cmNlcy9NeUN1c3RvbUxvZzI/YXBpLXZlcnNpb249MjAxNS0xMS0wMS1wcmV2aWV3",
1072+
"RequestMethod": "GET",
1073+
"RequestBody": "",
1074+
"RequestHeaders": {
1075+
"x-ms-client-request-id": [
1076+
"02f6042b-0d04-4d64-a7ae-ef13512cabe3"
1077+
],
1078+
"accept-language": [
1079+
"en-US"
1080+
],
1081+
"User-Agent": [
1082+
"FxVersion/4.7.2046.0",
1083+
"OSName/Windows_10_Enterprise",
1084+
"OSVersion/6.3.15063",
1085+
"Microsoft.Azure.Management.OperationalInsights.OperationalInsightsManagementClient/0.18.0-preview"
1086+
]
1087+
},
1088+
"ResponseBody": "{\r\n \"error\": {\r\n \"code\": \"DataSourceNotFound\",\r\n \"message\": \"DataSource 'MyCustomLog2' could not be found.\"\r\n }\r\n}",
1089+
"ResponseHeaders": {
1090+
"Content-Length": [
1091+
"96"
1092+
],
1093+
"Content-Type": [
1094+
"application/json; charset=utf-8"
1095+
],
1096+
"Expires": [
1097+
"-1"
1098+
],
1099+
"Pragma": [
1100+
"no-cache"
1101+
],
1102+
"Strict-Transport-Security": [
1103+
"max-age=31536000; includeSubDomains"
1104+
],
1105+
"X-Content-Type-Options": [
1106+
"nosniff"
1107+
],
1108+
"x-ms-ratelimit-remaining-subscription-reads": [
1109+
"14823"
1110+
],
1111+
"x-ms-request-id": [
1112+
"c94b019e-bd8a-4546-b433-ddb5aa7635ef"
1113+
],
1114+
"x-ms-correlation-request-id": [
1115+
"c94b019e-bd8a-4546-b433-ddb5aa7635ef"
1116+
],
1117+
"x-ms-routing-request-id": [
1118+
"WESTUS2:20170504T002631Z:c94b019e-bd8a-4546-b433-ddb5aa7635ef"
1119+
],
1120+
"Cache-Control": [
1121+
"no-cache"
1122+
],
1123+
"Date": [
1124+
"Thu, 04 May 2017 00:26:30 GMT"
1125+
],
1126+
"Server": [
1127+
"Microsoft-IIS/8.5"
1128+
],
1129+
"X-Powered-By": [
1130+
"ASP.NET"
1131+
]
1132+
},
1133+
"StatusCode": 404
1134+
},
1135+
{
1136+
"RequestUri": "/subscriptions/a6383be3-f0e8-4968-93d5-10f2625f5bb5/resourcegroups/onesdk9967/providers/Microsoft.OperationalInsights/workspaces/AzTestonesdk5206/dataSources/MyCustomLog2?api-version=2015-11-01-preview",
1137+
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvYTYzODNiZTMtZjBlOC00OTY4LTkzZDUtMTBmMjYyNWY1YmI1L3Jlc291cmNlZ3JvdXBzL29uZXNkazk5NjcvcHJvdmlkZXJzL01pY3Jvc29mdC5PcGVyYXRpb25hbEluc2lnaHRzL3dvcmtzcGFjZXMvQXpUZXN0b25lc2RrNTIwNi9kYXRhU291cmNlcy9NeUN1c3RvbUxvZzI/YXBpLXZlcnNpb249MjAxNS0xMS0wMS1wcmV2aWV3",
1138+
"RequestMethod": "PUT",
1139+
"RequestBody": "{\r\n \"properties\": {\r\n \"customLogName\": \"Validation_CL2\",\r\n \"description\": \"test\",\r\n \"extractions\": [\r\n {\r\n \"extractionName\": \"TimeGenerated\",\r\n \"extractionProperties\": {\r\n \"dateTimeExtraction\": {}\r\n },\r\n \"extractionType\": \"DateTime\"\r\n }\r\n ],\r\n \"inputs\": [\r\n {\r\n \"location\": {\r\n \"fileSystemLocations\": {\r\n \"windowsFileTypeLogPaths\": [\r\n \"C:\\\\e2e\\\\Evan\\\\ArubaSECURITY\\\\*.log\"\r\n ]\r\n }\r\n },\r\n \"recordDelimiter\": {\r\n \"regexDelimiter\": {\r\n \"matchIndex\": 0,\r\n \"pattern\": \"\\\\n\"\r\n }\r\n }\r\n }\r\n ]\r\n },\r\n \"kind\": \"CustomLog\"\r\n}",
1140+
"RequestHeaders": {
1141+
"Content-Type": [
1142+
"application/json; charset=utf-8"
1143+
],
1144+
"Content-Length": [
1145+
"713"
1146+
],
1147+
"x-ms-client-request-id": [
1148+
"3a712d5e-832f-4dd2-8cfe-b39dc4f3b80b"
1149+
],
1150+
"accept-language": [
1151+
"en-US"
1152+
],
1153+
"User-Agent": [
1154+
"FxVersion/4.7.2046.0",
1155+
"OSName/Windows_10_Enterprise",
1156+
"OSVersion/6.3.15063",
1157+
"Microsoft.Azure.Management.OperationalInsights.OperationalInsightsManagementClient/0.18.0-preview"
1158+
]
1159+
},
1160+
"ResponseBody": "{\r\n \"kind\": \"CustomLog\",\r\n \"properties\": {\r\n \"customLogName\": \"Validation_CL2\",\r\n \"description\": \"test\",\r\n \"extractions\": [\r\n {\r\n \"extractionName\": \"TimeGenerated\",\r\n \"extractionProperties\": {\r\n \"dateTimeExtraction\": {\"regex\":[{\"matchIndex\":0,\"numberdGroup\":null,\"pattern\":\"((\\\\d{2})|(\\\\d{4}))-([0-1]\\\\d)-(([0-3]\\\\d)|(\\\\d))\\\\s((\\\\d)|([0-1]\\\\d)|(2[0-4])):[0-5][0-9]:[0-5][0-9]\"}]}\r\n },\r\n \"extractionType\": \"DateTime\"\r\n }\r\n ],\r\n \"inputs\": [\r\n {\r\n \"location\": {\r\n \"fileSystemLocations\": {\r\n \"linuxFileTypeLogPaths\": null,\r\n \"windowsFileTypeLogPaths\": [\r\n \"C:\\\\e2e\\\\Evan\\\\ArubaSECURITY\\\\*.log\"\r\n ]\r\n }\r\n },\r\n \"recordDelimiter\": {\r\n \"regexDelimiter\": {\r\n \"matchIndex\": 0,\r\n \"numberdGroup\": null,\r\n \"pattern\": \"\\\\n\"\r\n }\r\n }\r\n }\r\n ]\r\n },\r\n \"id\": \"/subscriptions/a6383be3-f0e8-4968-93d5-10f2625f5bb5/resourceGroups/onesdk9967/providers/Microsoft.OperationalInsights/workspaces/AzTestonesdk5206/datasources/MyCustomLog2\",\r\n \"etag\": \"W/\\\"datetime'2017-05-04T00%3A26%3A31.2865595Z'\\\"\",\r\n \"name\": \"MyCustomLog\",\r\n \"type\": \"Microsoft.OperationalInsights/workspaces/datasources\"\r\n}",
1161+
"ResponseHeaders": {
1162+
"Content-Length": [
1163+
"769"
1164+
],
1165+
"Content-Type": [
1166+
"application/json; charset=utf-8"
1167+
],
1168+
"Expires": [
1169+
"-1"
1170+
],
1171+
"Pragma": [
1172+
"no-cache"
1173+
],
1174+
"Strict-Transport-Security": [
1175+
"max-age=31536000; includeSubDomains"
1176+
],
1177+
"X-Content-Type-Options": [
1178+
"nosniff"
1179+
],
1180+
"x-ms-ratelimit-remaining-subscription-writes": [
1181+
"1193"
1182+
],
1183+
"x-ms-request-id": [
1184+
"f84325f6-3ea3-4b44-89d8-1fc05971adec"
1185+
],
1186+
"x-ms-correlation-request-id": [
1187+
"f84325f6-3ea3-4b44-89d8-1fc05971adec"
1188+
],
1189+
"x-ms-routing-request-id": [
1190+
"WESTUS2:20170504T002713Z:f84325f6-3ea3-4b44-89d8-1fc05971adec"
1191+
],
1192+
"Cache-Control": [
1193+
"no-cache"
1194+
],
1195+
"Date": [
1196+
"Thu, 04 May 2017 00:27:12 GMT"
1197+
],
1198+
"Server": [
1199+
"Microsoft-IIS/8.5"
1200+
],
1201+
"X-Powered-By": [
1202+
"ASP.NET"
1203+
]
1204+
},
1205+
"StatusCode": 200
1206+
},
10691207
{
10701208
"RequestUri": "/subscriptions/a6383be3-f0e8-4968-93d5-10f2625f5bb5/resourcegroups/onesdk9967/providers/Microsoft.OperationalInsights/workspaces/AzTestonesdk5206/dataSources/ApplicationInsights?api-version=2015-11-01-preview",
10711209
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvYTYzODNiZTMtZjBlOC00OTY4LTkzZDUtMTBmMjYyNWY1YmI1L3Jlc291cmNlZ3JvdXBzL29uZXNkazk5NjcvcHJvdmlkZXJzL01pY3Jvc29mdC5PcGVyYXRpb25hbEluc2lnaHRzL3dvcmtzcGFjZXMvQXpUZXN0b25lc2RrNTIwNi9kYXRhU291cmNlcy9BcHBsaWNhdGlvbkluc2lnaHRzP2FwaS12ZXJzaW9uPTIwMTUtMTEtMDEtcHJldmlldw==",

src/OperationalInsights/OperationalInsights/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed CustomLog datasource model returned in Get-AzOperationalInsightsDataSource
2122

2223
## Version 1.3.0
2324
* Enable **pergb2018** pricing tier in `New-AzureRmOperationalInsightsWorkspace` command

src/OperationalInsights/OperationalInsights/DataSources/NewDataSourceCmdletsPerKind/NewAzureOperationalInsightsCustomLogDataSourceCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System;
2121
using System.Linq;
2222
using System.Management.Automation;
23+
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
2324

2425
namespace Microsoft.Azure.Commands.OperationalInsights
2526
{

src/OperationalInsights/OperationalInsights/Models/DataSourcePropertiesPerKind/PSCustomLogDataSourceProperties.cs

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
using System.Linq;
2020
using System.Text;
2121
using System.Threading.Tasks;
22+
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
23+
using Newtonsoft.Json.Linq;
2224

2325
namespace Microsoft.Azure.Commands.OperationalInsights.Models
2426
{
@@ -63,7 +65,8 @@ public class Location
6365
/// <summary>
6466
/// Gets or sets the file system locations.
6567
/// </summary>
66-
public FileSystemLocations fileSystemLocations { get; set; }
68+
[JsonProperty(PropertyName = "fileSystemLocations")]
69+
public FileSystemLocations FileSystemLocations { get; set; }
6770

6871
#endregion
6972
}
@@ -78,12 +81,14 @@ public class FileSystemLocations
7881
/// <summary>
7982
/// Gets or sets the linux file type log paths.
8083
/// </summary>
81-
public string[] linuxFileTypeLogPaths { get; set; }
84+
[JsonProperty(PropertyName = "linuxFileTypeLogPaths")]
85+
public string[] LinuxFileTypeLogPaths { get; set; }
8286

8387
/// <summary>
8488
/// Gets or sets the windows file type log paths.
8589
/// </summary>
86-
public string[] windowsFileTypeLogPaths { get; set; }
90+
[JsonProperty(PropertyName = "windowsFileTypeLogPaths")]
91+
public string[] WindowsFileTypeLogPaths { get; set; }
8792

8893
#endregion
8994
}
@@ -98,7 +103,8 @@ public class RecordDelimiter
98103
/// <summary>
99104
/// Gets or sets the regex delimiter.
100105
/// </summary>
101-
public RegexDelimiter regexDelimiter { get; set; }
106+
[JsonProperty(PropertyName = "regexDelimiter")]
107+
public RegexDelimiter RegexDelimiter { get; set; }
102108

103109
#endregion
104110
}
@@ -113,17 +119,20 @@ public class RegexDelimiter
113119
/// <summary>
114120
/// Gets or sets the match index.
115121
/// </summary>
116-
public int matchIndex { get; set; }
122+
[JsonProperty(PropertyName = "matchIndex")]
123+
public int MatchIndex { get; set; }
117124

118125
/// <summary>
119126
/// Gets or sets the numberd group.
120127
/// </summary>
121-
public string numberdGroup { get; set; }
128+
[JsonProperty(PropertyName = "numberdGroup")]
129+
public string NumberdGroup { get; set; }
122130

123131
/// <summary>
124132
/// Gets or sets the pattern.
125133
/// </summary>
126-
public string pattern { get; set; }
134+
[JsonProperty(PropertyName = "pattern")]
135+
public string Pattern { get; set; }
127136

128137
#endregion
129138
}
@@ -138,12 +147,14 @@ public class CustomLogInput
138147
/// <summary>
139148
/// Gets or sets the location.
140149
/// </summary>
141-
public Location location { get; set; }
150+
[JsonProperty(PropertyName = "location")]
151+
public Location Location { get; set; }
142152

143153
/// <summary>
144154
/// Gets or sets the record delimiter.
145155
/// </summary>
146-
public RecordDelimiter recordDelimiter { get; set; }
156+
[JsonProperty(PropertyName = "recordDelimiter")]
157+
public RecordDelimiter RecordDelimiter { get; set; }
147158

148159
#endregion
149160
}
@@ -158,12 +169,28 @@ public class DateTimeExtraction
158169
/// <summary>
159170
/// Gets or sets the join string regex.
160171
/// </summary>
161-
public string joinStringRegex { get; set; }
172+
[JsonProperty("joinStringRegex")]
173+
public string JoinStringRegex { get; set; }
174+
175+
/// <summary>
176+
/// Gets or sets the regex string.
177+
/// </summary>
178+
[JsonIgnore]
179+
public string Regex { get; set; }
162180

163181
/// <summary>
164182
/// Gets or sets the regex.
165183
/// </summary>
166-
public string regex { get; set; }
184+
[CmdletParameterBreakingChange(nameof(Regex), OldParamaterType = typeof(string), NewParameterTypeName = nameof(RegexDelimiter))]
185+
[JsonConverter(typeof(RegexDelimiterJsonConverter))]
186+
[JsonProperty("regex")]
187+
public RegexDelimiter[] RegexDelimiters { get; set; }
188+
189+
///<summary>
190+
/// Gets or sets the FormatString
191+
/// </summary>
192+
[JsonProperty("formatString")]
193+
public string FormatString { get; set; }
167194

168195
#endregion
169196
}
@@ -178,7 +205,8 @@ public class ExtractionProperties
178205
/// <summary>
179206
/// Gets or sets the date time extraction.
180207
/// </summary>
181-
public DateTimeExtraction dateTimeExtraction { get; set; }
208+
[JsonProperty(PropertyName = "dateTimeExtraction")]
209+
public DateTimeExtraction DateTimeExtraction { get; set; }
182210

183211
#endregion
184212
}
@@ -193,18 +221,44 @@ public class CustomLogExtraction
193221
/// <summary>
194222
/// Gets or sets the extraction name.
195223
/// </summary>
196-
public string extractionName { get; set; }
224+
[JsonProperty(PropertyName = "extractionName")]
225+
public string ExtractionName { get; set; }
197226

198227
/// <summary>
199228
/// Gets or sets the extraction properties.
200229
/// </summary>
201-
public ExtractionProperties extractionProperties { get; set; }
230+
[JsonProperty(PropertyName = "extractionProperties")]
231+
public ExtractionProperties ExtractionProperties { get; set; }
202232

203233
/// <summary>
204234
/// Gets or sets the extraction type.
205235
/// </summary>
206-
public string extractionType { get; set; }
236+
[JsonProperty(PropertyName = "extractionType")]
237+
public string ExtractionType { get; set; }
207238

208239
#endregion
209240
}
241+
242+
// This converter allows backward compatibility
243+
public class RegexDelimiterJsonConverter : JsonConverter
244+
{
245+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
246+
{
247+
switch (reader.TokenType)
248+
{
249+
case JsonToken.StartArray:
250+
JToken token = JToken.Load(reader);
251+
return token.ToObject<RegexDelimiter[]>();
252+
case JsonToken.String:
253+
// Satisfy case in which user uses the old regex property in input
254+
return new[] {new RegexDelimiter {MatchIndex = 0, Pattern = (string) reader.Value}};
255+
default:
256+
throw new JsonSerializationException();
257+
}
258+
}
259+
260+
public override bool CanWrite => false;
261+
public override bool CanConvert(Type objectType) => throw new NotImplementedException();
262+
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException();
263+
}
210264
}

0 commit comments

Comments
 (0)