generated from qbeyond/terraform-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_logs.tf
183 lines (170 loc) · 5.6 KB
/
custom_logs.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
locals {
columns = {
"state" = "string"
"TimeGenerated" = "datetime"
"additional_information" = "string"
"affected_entity" = "string"
"affected_object" = "string"
"monitor_description" = "string"
"monitor_name" = "string"
"monitor_package" = "string"
"script_name" = "string"
"script_version" = "string"
"threshold" = "string"
"value" = "string"
}
kql_types = join(", ", [for column_name, column_type in local.columns : "${column_name}:${column_type}"])
resource_group_id = regex("^((/[^/]+){4})", var.log_analytics_workspace.id)[0]
}
resource "azapi_resource" "data_collection_json_logs_table" {
name = "MonitoringScriptsJSON_CL"
parent_id = var.log_analytics_workspace.id
type = "Microsoft.OperationalInsights/workspaces/tables@2022-10-01"
tags = var.tags
schema_validation_enabled = false
body = jsonencode(
{
"properties" : {
"schema" : {
"name" : "MonitoringScriptsJSON_CL",
"columns" : [
for column_name, column_type in local.columns : {
"name" = column_name
"type" = column_type
"description" = ""
}
]
},
"retentionInDays" : 30,
"totalRetentionInDays" : 30
}
}
)
}
resource "azapi_resource" "data_collection_text_logs_table" {
name = "MonitoringScriptsTEXT_CL"
parent_id = var.log_analytics_workspace.id
type = "Microsoft.OperationalInsights/workspaces/tables@2022-10-01"
tags = var.tags
schema_validation_enabled = false
body = jsonencode(
{
"properties" : {
"schema" : {
"name" : "MonitoringScriptsTEXT_CL",
"columns" : [
{
"name" = "TimeGenerated"
"type" = "datetime"
},
{
"name" = "RawData"
"type" = "string"
}
]
},
"retentionInDays" : 30,
"totalRetentionInDays" : 30
}
}
)
}
resource "azapi_resource" "dcr_custom_json_logs" {
type = "Microsoft.insights/dataCollectionRules@2023-03-11"
name = "dcr-prd-all-CustomJSONLog-01"
parent_id = local.resource_group_id
location = var.log_analytics_workspace.location
schema_validation_enabled = false
tags = var.tags
body = jsonencode(
{
properties = {
dataFlows = [
{
streams = [
"Custom-${azapi_resource.data_collection_json_logs_table.name}"
],
destinations = [
"${var.log_analytics_workspace.name}"
],
transformKql = "source"
outputStream = "Custom-${azapi_resource.data_collection_json_logs_table.name}"
}
]
dataSources = {
logFiles = [
{
name = "Custom-${azapi_resource.data_collection_json_logs_table.name}"
format = "json"
streams = ["Custom-${azapi_resource.data_collection_json_logs_table.name}"]
filePatterns = ["c:\\program files\\ud\\logs\\json\\*.log"]
}
]
}
destinations = {
logAnalytics = [
{
name = var.log_analytics_workspace.name
workspaceResourceId = var.log_analytics_workspace.id
}
]
}
dataCollectionEndpointId = azurerm_monitor_data_collection_endpoint.dce.id
streamDeclarations = {
Custom-MonitoringScriptsTEXT_CL = {
columns = [
for column_name, column_type in local.columns : {
"name" = column_name
"type" = column_type
}
]
}
}
}
}
)
}
resource "azurerm_monitor_data_collection_rule" "dcr_custom_text_logs" {
name = "dcr-prd-all-CustomTextLog-01"
resource_group_name = var.log_analytics_workspace.resource_group_name
location = var.log_analytics_workspace.location
tags = var.tags
description = "Collect custom log data for monitoring"
data_collection_endpoint_id = azurerm_monitor_data_collection_endpoint.dce.id
destinations {
log_analytics {
workspace_resource_id = var.log_analytics_workspace.id
name = var.log_analytics_workspace.name
}
}
data_flow {
streams = ["Custom-${azapi_resource.data_collection_text_logs_table.name}"]
destinations = [var.log_analytics_workspace.name]
output_stream = "Custom-${azapi_resource.data_collection_text_logs_table.name}"
transform_kql = "source"
}
data_sources {
log_file {
name = "Custom-${azapi_resource.data_collection_text_logs_table.name}"
format = "text"
streams = ["Custom-${azapi_resource.data_collection_text_logs_table.name}"]
file_patterns = ["c:\\program files\\ud\\logs\\*.log"]
settings {
text {
record_start_timestamp_format = "ISO 8601"
}
}
}
}
stream_declaration {
stream_name = "Custom-${azapi_resource.data_collection_text_logs_table.name}"
column {
name = "TimeGenerated"
type = "datetime"
}
column {
name = "RawData"
type = "string"
}
}
}