Skip to content

Commit ac139de

Browse files
Fix IPinfo connectors: runtime pinning, dependency updates, and multi-workspace ASN support
1 parent ee47590 commit ac139de

File tree

59 files changed

+816
-549
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+816
-549
lines changed

Solutions/IPinfo/Data Connectors/ASN/AzureFunctionIPinfoASN/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
RESOURCE_GROUP_NAME = parts[4]
2525
WORKSPACE_NAME = parts[8]
2626

27-
DATA_COLLECTION_ENDPOINT_NAME = "ipinfo-logs-ingestion"
28-
ASN_DCR_NAME = "ipinfo_rule_for_ASN_tables"
27+
DATA_COLLECTION_ENDPOINT_NAME = f"ipinfo-logs-ingestion-{WORKSPACE_NAME.lower()}"
28+
ASN_DCR_NAME = f"ipinfo_rule_for_ASN_tables_{WORKSPACE_NAME.lower()}"
2929
ASN_TABLE_NAME = "Ipinfo_ASN_CL"
3030
ASN_STREAM_DECLARATION = "Custom-Ipinfo_ASN_CL"
3131

Solutions/IPinfo/Data Connectors/ASN/AzureFunctionIPinfoASN/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def upload_data_to_ASN_table(dce_endpoint, dcr_immutableid, stream_name):
2222
client = LogsIngestionClient(endpoint=dce_endpoint, credential=credential, logging_enable=True)
2323
mmdb_file_path = "/tmp/asn.mmdb"
2424
reader = maxminddb.open_database(mmdb_file_path)
25-
chunk_size = 10000
25+
chunk_size = 100
2626
data_chunk = []
2727
logging.info("Uploading Standard ASN Data.\n")
2828
for ip, ip_data in reader:
@@ -55,7 +55,6 @@ def upload_data_to_ASN_table(dce_endpoint, dcr_immutableid, stream_name):
5555
access_token = credential.get_token(AZURE_SCOPE).token
5656
if access_token:
5757
logging.info("\nAccess Token Retrieved\n")
58-
logging.info(access_token)
5958
else:
6059
logging.error("\nFailed to retrieve access token\n")
6160

Solutions/IPinfo/Data Connectors/ASN/AzureFunctionIPinfoASN/utils.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,25 @@ def get_data_collection_rule(access_token, data_collection_rule_name):
109109
url = generate_url("dataCollectionRule", rule_name=data_collection_rule_name)
110110
headers = {"Authorization": "Bearer " + access_token}
111111
response = requests.get(url, headers=headers)
112+
112113
if response.status_code == 200:
113114
data = response.json()
114115
immutableId = data["properties"]["immutableId"]
115116
streamDeclarations = list(data["properties"]["streamDeclarations"].keys())[0]
117+
118+
try:
119+
actual_workspace = data["properties"]["destinations"]["logAnalytics"][0]["workspaceResourceId"]
120+
expected_workspace = f"/subscriptions/{SUBCRIPTION_ID}/resourcegroups/{RESOURCE_GROUP_NAME}/providers/microsoft.operationalinsights/workspaces/{WORKSPACE_NAME}"
121+
122+
if actual_workspace.lower() != expected_workspace.lower():
123+
logging.warning(f"DCR '{data_collection_rule_name}' points to WRONG workspace!")
124+
logging.warning(f"Expected: {expected_workspace}")
125+
logging.warning(f"Found: {actual_workspace}")
126+
return None, None
127+
except (KeyError, IndexError) as e:
128+
logging.error(f"Failed to extract workspace from DCR: {e}")
129+
return None, None
130+
116131
return immutableId, streamDeclarations
117132

118133
logging.info(f"{data_collection_rule_name} Data Rule endpoint not exist. Status code:{response.status_code}")
@@ -159,9 +174,12 @@ def check_and_create_data_collection_rules(
159174
access_token, data_collection_rule_name, stream_declaration, columns, endpoint
160175
):
161176
dcr_immutableid, stream_name = get_data_collection_rule(access_token, data_collection_rule_name)
177+
162178
if dcr_immutableid is not None and stream_name is not None:
163-
logging.info(f"\nData collection Rule `{data_collection_rule_name}` already exists.")
179+
180+
logging.info(f"\nData collection Rule `{data_collection_rule_name}` already exists and is valid.")
164181
return dcr_immutableid, stream_name
165-
logging.info(f"\nData collection Rule for {data_collection_rule_name} doesn't exist. Creating...")
182+
183+
logging.info(f"\nCreating Data collection Rule for {data_collection_rule_name}...")
166184
create_data_collection_rule(access_token, data_collection_rule_name, stream_declaration, columns, endpoint)
167-
return get_data_collection_rule(access_token, data_collection_rule_name)
185+
return get_data_collection_rule(access_token, data_collection_rule_name)

Solutions/IPinfo/Data Connectors/ASN/azuredeploy_Connector_IPinfo_ASN_AzureFunction.json

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,34 @@
99
"type": "string"
1010
},
1111
"RESOURCE_ID": {
12-
"type": "string",
13-
"defaultValue": "Resouce ID",
12+
"type": "string",
1413
"metadata": {
15-
"description": "Use 'Log Analytic Workspace-->Properties' blade having 'Resource ID' property value. This is a fully qualified resourceId which is in format '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}'"
14+
"description": "REQUIRED. Use 'Log Analytic Workspace-->Properties' blade having 'Resource ID' property value. This is a fully qualified resourceId which is in format '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}'"
1615
}
1716
},
1817
"TENANT_ID": {
1918
"type": "string",
20-
"defaultValue": "Tenant ID"
19+
"metadata": {
20+
"description": "REQUIRED. Azure AD Tenant ID (found in Azure Active Directory --> Properties)"
21+
}
2122
},
2223
"CLIENT_ID": {
2324
"type": "string",
24-
"defaultValue": "Client ID"
25+
"metadata": {
26+
"description": "REQUIRED. Service Principal Application (Client) ID"
27+
}
2528
},
2629
"CLIENT_SECRET": {
27-
"type": "securestring"
30+
"type": "securestring",
31+
"metadata": {
32+
"description": "REQUIRED. Service Principal Client Secret"
33+
}
2834
},
2935
"IPINFO_TOKEN": {
3036
"type": "string",
31-
"defaultValue": "IPinfo Token"
37+
"metadata": {
38+
"description": "REQUIRED. IPinfo API Token (obtain from ipinfo.io)"
39+
}
3240
},
3341
"RETENTION_IN_DAYS": {
3442
"type": "string",
@@ -105,17 +113,14 @@
105113
"name": "EP2",
106114
"tier": "ElasticPremium",
107115
"family": "EP"
108-
},
109-
"kind": "elastic",
116+
},
117+
"kind": "linux",
110118
"properties": {
111119
"name": "[variables('FunctionName')]",
112120
"targetWorkerCount": 1,
113121
"targetWorkerSizeId": 3,
114122
"reserved": true,
115-
"maximumElasticWorkerCount": 20,
116-
"siteConfig": {
117-
"linuxFxVersion": "python|3.11"
118-
}
123+
"maximumElasticWorkerCount": 20
119124
}
120125
},
121126

@@ -160,16 +165,18 @@
160165
"[resourceId('Microsoft.Web/serverfarms', variables('FunctionName'))]",
161166
"[resourceId('Microsoft.Insights/components', variables('FunctionName'))]"
162167
],
163-
"kind": "functionapp",
168+
"kind": "functionapp,linux",
164169
"identity": {
165170
"type": "SystemAssigned"
166171
},
167172
"properties": {
168173
"name": "[variables('FunctionName')]",
169174
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('FunctionName'))]",
170175
"httpsOnly": true,
171-
"clientAffinityEnabled": true,
172-
"alwaysOn": true
176+
"reserved": true,
177+
"siteConfig": {
178+
"linuxFxVersion": "python|3.11"
179+
}
173180
},
174181
"resources": [
175182
{

Solutions/IPinfo/Data Connectors/ASN/host.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
},
1212
"extensionBundle": {
1313
"id": "Microsoft.Azure.Functions.ExtensionBundle",
14-
"version": "[3.*, 4.0.0)"
14+
"version": "[4.0.0, 5.0.0)"
1515
}
1616
}

Solutions/IPinfo/Data Connectors/ASN/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ azure.identity
77
azure.monitor.ingestion
88
requests
99
maxminddb
10+
cffi

0 commit comments

Comments
 (0)