Skip to content

Commit 3a8026e

Browse files
authored
Merge pull request #78 from logicmonitor/gov-cloud-support-log-integrations-2
Gov cloud support log integrations
2 parents 05bec75 + 6601f4a commit 3a8026e

File tree

7 files changed

+81
-76
lines changed

7 files changed

+81
-76
lines changed

arm-template-deployment/deployRGParent.json

+37-32
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,50 @@
22
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
33
"contentVersion": "1.0.0.0",
44
"variables": {
5-
"sourceCodeBranch" : "master",
5+
"sourceCodeBranch": "master",
66
"templateBaseUri": "[concat('https://raw.githubusercontent.com/logicmonitor/lm-logs-azure/',variables('sourceCodeBranch'),'/arm-template-deployment/')]",
7-
"deploymentResourceGroupName": "[concat('lm-logs','-',parameters('LM_Company_name'), '-', replace(parameters('resource_group_region'),' ',''),'-group')]",
8-
"eventhubNamespace": "[concat('lm-logs','-',parameters('LM_Company_name'), '-', replace(parameters('resource_group_region'),' ',''))]",
7+
"deploymentResourceGroupName": "[concat('lm-logs','-',parameters('LM_Company_Name'), '-', replace(parameters('Resource_Group_Region'),' ',''),'-group')]",
8+
"eventhubNamespace": "[concat('lm-logs','-',parameters('LM_Company_Name'), '-', replace(parameters('Resource_Group_Region'),' ',''))]",
99
"eventhubLogsName": "log-hub",
1010
"subscriptionId": "[subscription().subscriptionId]",
1111
"eventHubAuthorizationRuleId": "[concat('/subscriptions/', variables('subscriptionId'), '/resourceGroups/', variables('deploymentResourceGroupName'), '/providers/Microsoft.EventHub/namespaces/', variables('eventhubNamespace'), '/authorizationRules/RootManageSharedAccessKey')]"
1212
},
1313
"parameters": {
14-
"resource_group_region": {
14+
"Resource_Group_Region": {
1515
"type": "String"
1616
},
17-
"LM_Company_name": {
17+
"LM_Company_Name": {
1818
"type": "String"
1919
},
20+
"LM_Domain_Name": {
21+
"type": "string",
22+
"defaultValue": "logicmonitor.com",
23+
"allowedValues": [
24+
"logicmonitor.com",
25+
"lmgov.us",
26+
"qa-lmgov.us"
27+
],
28+
"metadata": {
29+
"description": "Domain of LM Platform where logs are to be sent."
30+
}
31+
},
2032
"LM_Access_Id": {
2133
"type": "String",
22-
"defaultValue":"",
34+
"defaultValue": "",
2335
"metadata": {
2436
"description": "LogicMonitor API Token access ID."
2537
}
2638
},
2739
"LM_Access_Key": {
2840
"type": "String",
29-
"defaultValue":"",
41+
"defaultValue": "",
3042
"metadata": {
3143
"description": "LogicMonitor API Token access Key."
3244
}
3345
},
3446
"LM_Bearer_Token": {
3547
"type": "String",
36-
"defaultValue":"",
48+
"defaultValue": "",
3749
"metadata": {
3850
"description": "LM API Bearer Token.\nEither specify access_id and access_key both or bearer_token. If all specified, LMv1 token(access_id and access_key) will be used for authentication with LogicMonitor."
3951
}
@@ -46,33 +58,26 @@
4658
},
4759
"Azure_Account_Name": {
4860
"type": "string",
49-
"defaultValue":"",
61+
"defaultValue": "",
5062
"metadata": {
5163
"description": "Azure Account Name created during the creation of azure account in LM"
5264
}
5365
},
5466
"Include_Metadata_keys": {
5567
"type": "string",
56-
"defaultValue":"resourceId",
68+
"defaultValue": "resourceId",
5769
"metadata": {
5870
"description": "comma separated keys to add as event metadata in a lm-log event. for nested json specify '.' eg - properties.functionName,properties.message "
5971
}
6072
},
61-
"LMTenantId": {
73+
"LM_Tenant_Id": {
6274
"type": "string",
63-
"defaultValue":"",
75+
"defaultValue": "",
6476
"metadata": {
6577
"description": "LogicMonitor Tenant Identifier sent as event metadata to LogicMonitor"
6678
}
6779
},
68-
"Resource_Type": {
69-
"type": "string",
70-
"defaultValue": "Azure",
71-
"metadata": {
72-
"description": "Type of platform from where logs are coming."
73-
}
74-
},
75-
"enableActivityLogs": {
80+
"Enable_Activity_Logs": {
7681
"type": "String",
7782
"allowedValues": [
7883
"Yes",
@@ -105,7 +110,7 @@
105110
"condition": "[or(and(not(empty(parameters('LM_Access_Id'))), not(empty(parameters('LM_Access_Key')))), not(empty(parameters('LM_Bearer_Token'))))]",
106111
"type": "Microsoft.Resources/resourceGroups",
107112
"apiVersion": "2018-05-01",
108-
"location": "[parameters('resource_group_region')]",
113+
"location": "[parameters('Resource_Group_Region')]",
109114
"name": "[variables('deploymentResourceGroupName')]",
110115
"properties": {}
111116
},
@@ -122,11 +127,14 @@
122127
"contentVersion": "1.0.0.0"
123128
},
124129
"parameters": {
125-
"azure_region": {
126-
"value": "[parameters('resource_group_region')]"
130+
"Azure_Region": {
131+
"value": "[parameters('Resource_Group_Region')]"
132+
},
133+
"LM_Company_Name": {
134+
"value": "[parameters('LM_Company_Name')]"
127135
},
128-
"LM_Company_name": {
129-
"value": "[parameters('LM_Company_name')]"
136+
"LM_Domain_Name": {
137+
"value": "[parameters('LM_Domain_Name')]"
130138
},
131139
"LM_Access_Id": {
132140
"value": "[parameters('LM_Access_Id')]"
@@ -149,11 +157,8 @@
149157
"Include_Metadata_keys": {
150158
"value": "[parameters('Include_Metadata_keys')]"
151159
},
152-
"LMTenantId" : {
153-
"value": "[parameters('LMTenantId')]"
154-
},
155-
"Resource_Type": {
156-
"value": "[parameters('Resource_Type')]"
160+
"LM_Tenant_Id" : {
161+
"value": "[parameters('LM_Tenant_Id')]"
157162
},
158163
"TLSVersionStorageAccount": {
159164
"value": "[parameters('TLSVersionStorageAccount')]"
@@ -168,7 +173,7 @@
168173
]
169174
},
170175
{
171-
"condition": "[equals(parameters('enableActivityLogs'), 'Yes')]",
176+
"condition": "[equals(parameters('Enable_Activity_Logs'), 'Yes')]",
172177
"type": "Microsoft.Insights/diagnosticSettings",
173178
"apiVersion": "2017-05-01-preview",
174179
"name": "[variables('deploymentResourceGroupName')]",
@@ -217,4 +222,4 @@
217222
}
218223
],
219224
"outputs": {}
220-
}
225+
}

arm-template-deployment/deployResourcesInRG.json

+17-17
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
33
"contentVersion": "1.0.0.0",
44
"parameters": {
5-
"LM_Company_name": {
5+
"LM_Company_Name": {
66
"type": "string"
77
},
88
"LM_Access_Id": {
@@ -23,16 +23,16 @@
2323
"Include_Metadata_keys": {
2424
"type": "string"
2525
},
26-
"LMTenantId": {
26+
"LM_Tenant_Id": {
2727
"type": "string"
2828
},
29-
"azure_region": {
29+
"Azure_Region": {
3030
"type": "string"
3131
},
3232
"sourceCodeBranch": {
3333
"type": "string"
3434
},
35-
"Resource_Type": {
35+
"LM_Domain_Name": {
3636
"type": "string"
3737
},
3838
"TLSVersionStorageAccount" : {
@@ -43,9 +43,9 @@
4343
}
4444
},
4545
"variables": {
46-
"logsFunctionAppName": "[concat('lm-logs','-',parameters('LM_Company_name'), '-', replace(parameters('azure_region'),' ',''))]",
47-
"eventhubNamespace": "[concat('lm-logs','-',parameters('LM_Company_name'), '-', replace(parameters('azure_region'),' ',''))]",
48-
"storage": "[toLower(concat(parameters('LM_Company_name'), replace(parameters('azure_region'),' ','')))]",
46+
"logsFunctionAppName": "[concat('lm-logs','-',parameters('LM_Company_Name'), '-', replace(parameters('Azure_Region'),' ',''))]",
47+
"eventhubNamespace": "[concat('lm-logs','-',parameters('LM_Company_Name'), '-', replace(parameters('Azure_Region'),' ',''))]",
48+
"storage": "[toLower(concat(parameters('LM_Company_Name'), replace(parameters('Azure_Region'),' ','')))]",
4949
"lmAppStorageAccounts": "[if(greater(length(variables('storage')) , 24), substring(variables('storage'), sub(length(variables('storage')) , 24), 24) , variables('storage'))]",
5050
"eventhubLogsName": "log-hub",
5151
"ConsumergroupsLogsName": "LMConsumerGroup",
@@ -166,15 +166,15 @@
166166
},
167167
{
168168
"name": "LM_COMPANY",
169-
"value": "[parameters('LM_Company_name')]"
169+
"value": "[parameters('LM_Company_Name')]"
170170
},
171171
{
172-
"name" : "LM_AUTH",
173-
"value" : "[variables('lm_auth')]"
172+
"name": "LM_AUTH",
173+
"value": "[variables('lm_auth')]"
174174
},
175175
{
176-
"name" : "LM_TENANT_ID",
177-
"value" : "[parameters('LMTenantId')]"
176+
"name": "LM_TENANT_ID",
177+
"value": "[parameters('LM_Tenant_Id')]"
178178
},
179179
{
180180
"name": "AzureClientID",
@@ -206,15 +206,15 @@
206206
},
207207
{
208208
"name": "Include_Metadata_keys",
209-
"value" : "[parameters('Include_Metadata_keys')]"
209+
"value": "[parameters('Include_Metadata_keys')]"
210210
},
211211
{
212212
"name": "LOG_LEVEL",
213-
"value" : "WARNING"
213+
"value": "WARNING"
214214
},
215215
{
216-
"name": "RESOURCE_TYPE",
217-
"value": "[Parameters('Resource_Type')]"
216+
"name": "LM_DOMAIN_NAME",
217+
"value": "[parameters('LM_Domain_Name')]"
218218
}
219219
],
220220
"minTlsVersion" : "[parameters('TLSVersionFunctionApp')]"
@@ -283,4 +283,4 @@
283283
]
284284
}
285285
]
286-
}
286+
}

build.gradle

+15-15
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,32 @@ repositories {
2525
}
2626

2727
dependencies {
28-
implementation (
29-
"com.microsoft.azure.functions:azure-functions-java-library:1.4.0",
30-
"com.logicmonitor:lm-logs-sdk-java:1.2",
31-
"com.logicmonitor:lm-data-sdk:0.0.4-alpha",
32-
"com.google.code.gson:gson:2.8.6"
28+
implementation(
29+
"com.logicmonitor:lm-data-sdk:0.0.5-alpha",
30+
"com.microsoft.azure.functions:azure-functions-java-library:1.4.0",
31+
"com.logicmonitor:lm-logs-sdk-java:1.2",
32+
"com.google.code.gson:gson:2.8.6"
3333
)
34-
implementation 'com.squareup.okhttp3:okhttp:4.9.3'
34+
implementation 'com.squareup.okhttp3:okhttp:4.9.3'
3535
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.3'
3636
implementation 'io.gsonfire:gson-fire:1.8.5'
3737
implementation 'org.slf4j:slf4j-api:1.7.25'
3838
implementation 'org.apache.commons:commons-lang3:3.9'
3939
implementation 'com.jayway.jsonpath:json-path:2.5.0'
4040
implementation 'org.slf4j:slf4j-nop:1.7.25'
4141

42-
testImplementation (
43-
"org.junit.jupiter:junit-jupiter:${junitVersion}",
44-
"com.github.stefanbirkner:system-lambda:1.0.0",
45-
"org.mockito:mockito-core:3.4.4",
46-
"org.glassfish.jersey.test-framework:jersey-test-framework-core:${jerseyVersion}",
47-
"org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-grizzly2:${jerseyVersion}"
42+
testImplementation(
43+
"org.junit.jupiter:junit-jupiter:${junitVersion}",
44+
"com.github.stefanbirkner:system-lambda:1.0.0",
45+
"org.mockito:mockito-core:3.4.4",
46+
"org.glassfish.jersey.test-framework:jersey-test-framework-core:${jerseyVersion}",
47+
"org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-grizzly2:${jerseyVersion}"
4848
)
4949
testCompileOnly(
50-
"junit:junit:4.12"
50+
"junit:junit:4.12"
5151
)
5252
testRuntimeOnly(
53-
"org.junit.vintage:junit-vintage-engine:${junitVersion}"
53+
"org.junit.vintage:junit-vintage-engine:${junitVersion}"
5454
)
5555
}
5656

@@ -68,7 +68,7 @@ test {
6868
jar {
6969
manifest {
7070
attributes 'Implementation-Title': project.getName(),
71-
'Implementation-Version': project.getVersion()
71+
'Implementation-Version': project.getVersion()
7272
}
7373
}
7474

local.settings.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"LOG_LEVEL" : "WARNING",
1818
"LM_TENANT_ID" : "sample_tenant_id",
1919
"LM_AUTH": "{\"LM_ACCESS_ID\": \"id\", \"LM_ACCESS_KEY\" : \"key\", \"LM_BEARER_TOKEN\" : \"token\"}",
20-
"AzureAccountName": "LMTest Account",
21-
"RESOURCE_TYPE": "Azure"
20+
"AzureAccountName": "<Logicmonitor Azure Account>",
21+
"LM_DOMAIN_NAME" : "<LogicMonitor company domain>"
2222
}
2323
}

package/lm-logs-azure.zip

88.1 KB
Binary file not shown.

src/main/java/com/logicmonitor/logs/azure/LogEventAdapter.java

+1-8
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ public class LogEventAdapter implements Function<String, List<LogEntry>> {
102102
public static final String AZURE_CATEGORY = "category";
103103
public static final String LM_TENANT_ID = "LM_TENANT_ID";
104104

105-
public static final String RESOURCE_TYPE_KEY = "RESOURCE_TYPE";
106-
public static final String RESOURCE_TYPE_FIELD = "_resource.type";
107105
public static final String LM_TENANT_ID_KEY = "_lm.tenantId";
108106

109107
public static final Pattern RESOURCE_TYPE = Pattern.compile("/subscriptions/.*/resourceGroups/.*/providers/(?<type>[^/]*/[^/]*)/.*", Pattern.CASE_INSENSITIVE);
@@ -115,7 +113,7 @@ public class LogEventAdapter implements Function<String, List<LogEntry>> {
115113
/**
116114
* Required static metadata to be added in every LogEntry.
117115
*/
118-
public static final Map<String, String> REQ_STATIC_METADATA = Map.of("_integration", "azure");
116+
public static final Map<String, String> REQ_STATIC_METADATA = Map.of("_integration", "azure", "_resource.type", "Azure");
119117

120118
/**
121119
* Required metadata key to LogEventMessage method map.
@@ -254,11 +252,6 @@ protected LogEntry createEntry(JsonObject json) {
254252
metadata.put(LM_TENANT_ID_KEY, tenantId);
255253
}
256254

257-
String resourceType = System.getenv(RESOURCE_TYPE_KEY);
258-
if(StringUtils.isNotBlank(resourceType)){
259-
metadata.put(RESOURCE_TYPE_FIELD, resourceType);
260-
}
261-
262255
entry.setMetadata(metadata);
263256
if (scrubPattern != null) {
264257
message = scrubPattern.matcher(message).replaceAll("");

src/main/java/com/logicmonitor/logs/azure/LogEventForwarder.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ public class LogEventForwarder {
111111
/**
112112
* Transforms Azure log events into log entries.
113113
*/
114+
115+
116+
/**
117+
* Parameter: domain in the target URL '{company}.{domainName}'.
118+
*/
119+
public static final String PARAMETER_DOMAIN_NAME = "LM_DOMAIN_NAME";
114120
private static LogEventAdapter adapter;
115121

116122
private static final Gson GSON = new GsonBuilder().create();
@@ -121,6 +127,7 @@ public class LogEventForwarder {
121127

122128
protected static Configuration createDataSdkConfig() {
123129
String company = System.getenv(PARAMETER_COMPANY_NAME);
130+
String domainName = System.getenv(PARAMETER_DOMAIN_NAME);
124131
try {
125132
JsonObject authConf = GSON.fromJson(removeQuotesAndUnescape(System.getenv(PARAMETER_LM_AUTH)), JsonObject.class);
126133
String accessId = authConf.get(PARAMETER_ACCESS_ID).getAsString();
@@ -130,11 +137,11 @@ protected static Configuration createDataSdkConfig() {
130137
if (StringUtils.isNoneBlank(accessKey, accessId)) {
131138
// configure with null bearer token
132139
log(Level.FINE, "Using LMv1 for authentication with Logicmonitor.");
133-
return new Configuration(company, accessId, accessKey, null);
140+
return new Configuration(company, accessId, accessKey, null, domainName);
134141
} else {
135142
// configure with just Bearer token
136143
log(Level.FINE, "Using bearer token for authentication with Logicmonitor.");
137-
return new Configuration(company, null, null, bearerToken);
144+
return new Configuration(company, null, null, bearerToken, domainName);
138145
}
139146
} catch (Exception e) {
140147
log(Level.SEVERE,

0 commit comments

Comments
 (0)