Skip to content

Commit 3e2be63

Browse files
committed
v3.1.1-better-logging
1 parent 6483c69 commit 3e2be63

File tree

6 files changed

+23
-22
lines changed

6 files changed

+23
-22
lines changed
Binary file not shown.

Solutions/GreyNoiseThreatIntelligence/Data Connectors/GreyNoiseAPISentinelConnector/main.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import datetime
2-
import json
32
import logging
43
import os
54
import sys
@@ -27,12 +26,12 @@
2726

2827
GreyNoiseSetup = namedtuple("GreyNoiseSetup", ["api_key", "query", "tries", "size"])
2928
MSALSetup = namedtuple("MSALSetup", ["tenant_id", "client_id", "client_secret", "workspace_id"])
30-
class GreuNoiseSentinelUpdater(object):
29+
class GreyNoiseSentinelUpdater(object):
3130
"""Simple wrapper class to handle consuming IPs"""
3231

3332
def __init__(self, greynoise_setup: GreyNoiseSetup,
3433
msal_setup: MSALSetup):
35-
super(GreuNoiseSentinelUpdater, self).__init__()
34+
super(GreyNoiseSentinelUpdater, self).__init__()
3635

3736
self.greynoise_query = greynoise_setup.query
3837
self.greynoise_size = greynoise_setup.size
@@ -75,6 +74,8 @@ def get_token(self):
7574
A token access key.
7675
"""
7776
logging.info("Getting token for tenant: {0}".format(self.msal_tenant_id))
77+
logging.info("Using client_id: {0}".format(self.msal_client_id))
78+
logging.info("Using workspace_id: {0}".format(self.msal_workspace_id))
7879
try:
7980
context = msal.ConfidentialClientApplication(self.msal_client_id,
8081
authority='https://login.microsofto'
@@ -154,23 +155,24 @@ def upload_indicators_to_sentinel(self, token: str, indicators: list):
154155
response.raise_for_status()
155156
except requests.HTTPError as e:
156157
status_retry += 1
157-
if e.response.status_code == (429 or 503):
158-
logging.error("HTTP: " + int(e.response.status_code))
158+
if e.response.status_code in (429, 503):
159+
logging.error("HTTP: " + str(e.response.status_code))
159160
if status_retry > 3:
160161
logging.error("Too many upload indicators API retries, exiting.")
161162
sys.exit(1)
162-
sleep_for = int(e.response.message.split()[7]) + 5 if e.response.message else 60
163+
retry_after = e.response.headers.get('Retry-After')
164+
sleep_for = int(retry_after) + 5 if retry_after else 60
163165
logging.info("API Rate limit exceeded (HTTP 429) or Server Error (HTTP 503), waiting {0} seconds...".format(sleep_for))
164166
time.sleep(sleep_for)
165167
logging.info("Retrying upload...")
166168
self.upload_indicators_to_sentinel(token, indicators)
167169
elif e.response.status_code == 401:
168-
logging.error("HTTP: " + int(e.response.status_code))
170+
logging.error("HTTP: " + str(e.response.status_code))
169171
logging.error('Did you add the Azure Sentinel Contributor role to your service principal?')
170172
logging.error('More info here: https://learn.microsoft.com/en-us/azure/sentinel/upload-indicators-api#acquire-an-access-token')
171173
logging.error(e.response.text)
172174
elif e.response.status_code:
173-
logging.error("HTTP: " + int(e.response.status_code))
175+
logging.error("HTTP: " + str(e.response.status_code))
174176
logging.error(e.response.text)
175177
logging.error('Cannot upload indicators to Azure Sentinel, exiting.')
176178
sys.exit(1)
@@ -179,8 +181,8 @@ def upload_indicators_to_sentinel(self, token: str, indicators: list):
179181
# Check for submission errors
180182
if response.json().get('errors') != []:
181183
logging.warning('Nonfatal error in submitting indicator. While a field failed, \n' \
182-
'the rest of the indicator failed and we can continue.')
183-
logging.warning('Error: ' + json.loads(response.json()).get('error'))
184+
'the rest of the indicator succeeded and we can continue.')
185+
logging.warning('Error: ' + str(response.json().get('errors')))
184186

185187
return response.json()
186188
except requests.exceptions.JSONDecodeError:
@@ -408,7 +410,7 @@ def main(mytimer: func.TimerRequest) -> None:
408410
env.get("TENANT_ID"), env.get("CLIENT_ID"), env.get("CLIENT_SECRET"), env.get("WORKSPACE_ID")
409411
)
410412

411-
g = GreuNoiseSentinelUpdater(greynoise_setup, msal_setup)
413+
g = GreyNoiseSentinelUpdater(greynoise_setup, msal_setup)
412414
g.consume_ips()
413415

414416
logging.info('Python timer trigger function ran at %s', utc_timestamp)

Solutions/GreyNoiseThreatIntelligence/Data Connectors/GreyNoiseConnector_UploadIndicatorsAPI.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
}
3232
],
3333
"availability": {
34-
"status": 1,
35-
"isPreview": true
34+
"status": 1
3635
},
3736
"permissions": {
3837
"resourceProvider": [
@@ -101,7 +100,7 @@
101100
"description": "Follow this section here to add **'ThreatIndicators.ReadWrite.OwnedBy'** permission to the AAD App: https://learn.microsoft.com/en-us/azure/sentinel/connect-threat-intelligence-tip#specify-the-permissions-required-by-the-application. \n Back in your AAD App, ensure you grant admin consent for the permissions you just added. \n Finally, in the 'Tokens and APIs' section, generate a client secret and save it. You will need it in Step 6. "
102101
},{
103102
"title": "5. Deploy the Threat Intelligence (New) Solution, (v3.0.14 or later) which includes the Threat Intelligence Upload Indicators API (Preview)",
104-
"description": "See Microsoft Sentinel Content Hub for this Solution, and install it in the Microsoft Sentinel instance. Note that you do not need to do any confirguration in this step."
103+
"description": "See Microsoft Sentinel Content Hub for this Solution, and install it in the Microsoft Sentinel instance. Note that you do not need to do any configuration in this step."
105104
},
106105
{
107106
"title": "6. Deploy the Azure Function",

Solutions/GreyNoiseThreatIntelligence/Data Connectors/azuredeploy_Connector_GreyNoiseAPISentinel_AzureFunction.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"defaultValue": "Workspace ID"
1414
},
1515
"GREYNOISE_KEY": {
16-
"type": "string",
17-
"defaultValue": "GreyNoise API Key"
16+
"type": "securestring",
17+
"defaultValue": ""
1818
},
1919
"TENANT_ID": {
2020
"type": "string",
@@ -25,8 +25,8 @@
2525
"defaultValue": "Client ID"
2626
},
2727
"CLIENT_SECRET": {
28-
"type": "string",
29-
"defaultValue": "Client Secret"
28+
"type": "securestring",
29+
"defaultValue": ""
3030
},
3131
"GREYNOISE_CLASSIFICATIONS": {
3232
"type": "string",

Solutions/GreyNoiseThreatIntelligence/Package/mainTemplate.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@
11181118
"title": "4. Specify the AAD permissions to enable MS Graph API access to the upload-indicators API."
11191119
},
11201120
{
1121-
"description": "See Microsoft Sentinel Content Hub for this Solution, and install it in the Microsoft Sentinel instance. Note that you do not need to do any confirguration in this step.",
1121+
"description": "See Microsoft Sentinel Content Hub for this Solution, and install it in the Microsoft Sentinel instance. Note that you do not need to do any configuration in this step.",
11221122
"title": "5. Deploy the Threat Intelligence (New) Solution, (v3.0.14 or later) which includes the Threat Intelligence Upload Indicators API (Preview)"
11231123
},
11241124
{
@@ -1331,7 +1331,7 @@
13311331
"title": "4. Specify the AAD permissions to enable MS Graph API access to the upload-indicators API."
13321332
},
13331333
{
1334-
"description": "See Microsoft Sentinel Content Hub for this Solution, and install it in the Microsoft Sentinel instance. Note that you do not need to do any confirguration in this step.",
1334+
"description": "See Microsoft Sentinel Content Hub for this Solution, and install it in the Microsoft Sentinel instance. Note that you do not need to do any configuration in this step.",
13351335
"title": "5. Deploy the Threat Intelligence (New) Solution, (v3.0.14 or later) which includes the Threat Intelligence Upload Indicators API (Preview)"
13361336
},
13371337
{

Solutions/GreyNoiseThreatIntelligence/SolutionMetadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"publisherId": "greynoiseintelligenceinc1681236078693",
2+
"publisherId": "greynoiseintelligenceinc16812GreyNoiseAPISentinelConn6078693",
33
"offerId": "microsoft-sentinel-byol-greynoise",
44
"firstPublishDate": "2023-09-05",
5-
"lastPublishDate": "2026-03-12",
5+
"lastPublishDate": "2026-04-09",
66
"providers": ["GreyNoise Intelligence, Inc."],
77
"categories": {
88
"domains" : ["Security - Threat Intelligence"],

0 commit comments

Comments
 (0)