-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* change to SQL to no longer get all partitions from partition table, only the online and online_active tables. Small change to main thread for better cpu management * added modified library for azure caller * Added extra logging to cover errors to attempt calls to azure, added a health check to see if azure can be reached, changed the database calls to only get the last 3 months opf data. including the PasswordHandler.py as this was missed in the include in previous versions, but was in released versions * changed health check timeout to 10 seconds, removed second call to health check
- Loading branch information
1 parent
06e6fb8
commit 474f7af
Showing
13 changed files
with
378 additions
and
167 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import base64 | ||
import os | ||
from cryptography.fernet import Fernet | ||
|
||
|
||
def encrypt_password(pass_phrase): | ||
key = base64.urlsafe_b64encode(os.urandom(32)) | ||
string_key = key.decode("utf-8") | ||
cipher_suite = Fernet(string_key) | ||
ciphered_text = cipher_suite.encrypt(str.encode(pass_phrase)) | ||
'''f = open("password.txt", "w") | ||
f.write(ciphered_text.decode("utf-8")) | ||
f.close()''' | ||
return string_key, ciphered_text.decode("utf-8") | ||
|
||
|
||
def get_encrypted_password(): | ||
f = open("password.txt", "r") | ||
return f.read() | ||
|
||
|
||
def decrypt_password(key, encypted_pass_phrase): | ||
cipher_suite = Fernet(key) | ||
return cipher_suite.decrypt(str.encode(encypted_pass_phrase)) | ||
|
||
|
||
'''if get_encrypted_password(): | ||
pass_phrase = get_encrypted_password() | ||
key = input("Please enter your key:\n") | ||
print((decrypt_password(key, pass_phrase)).decode("utf-8")) | ||
else: | ||
pass_phrase = input("Please enter your pass phrase:\n") | ||
key = save_encrypted_password(pass_phrase) | ||
print(f'Please save this key somewhere safe if you need to log in again : {key}')''' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2016 Yoichi Kawasaki | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
version = '0.1.0' | ||
#from handlersocket.client import Client, TransportError, RemoteError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# -*- coding: utf-8 -*- | ||
import requests | ||
import datetime | ||
import hashlib | ||
import hmac | ||
import base64 | ||
import simplejson as json | ||
|
||
""" | ||
This is Azure Log Analytics Data Collector API Client libraries | ||
Data Collector API can be refered in the following document: | ||
https://docs.microsoft.com/en-us/azure/log-analytics/log-analytics-data-collector-api | ||
""" | ||
|
||
__author__ = 'Yoichi Kawasaki' | ||
|
||
### Global Defines | ||
_LOG_ANALYTICS_DATA_COLLECTOR_API_VERSION = '2016-04-01' | ||
|
||
|
||
class DataCollectorAPIClient: | ||
""" | ||
Azure Log Analytics Data Collector API Client Class | ||
""" | ||
|
||
def __init__(self, customer_id, shared_key): | ||
self.customer_id = customer_id | ||
self.shared_key = shared_key | ||
|
||
# Build the API signature | ||
def __signature(self, date, content_length): | ||
try: | ||
sigs = "POST\n{}\napplication/json\nx-ms-date:{}\n/api/logs".format( | ||
str(content_length), date) | ||
utf8_sigs = sigs.encode('utf-8') | ||
decoded_shared_key = base64.b64decode(self.shared_key) | ||
hmac_sha256_sigs = hmac.new( | ||
decoded_shared_key, utf8_sigs, digestmod=hashlib.sha256).digest() | ||
encoded_hash = base64.b64encode(hmac_sha256_sigs).decode('utf-8') | ||
authorization = "SharedKey {}:{}".format(self.customer_id, encoded_hash) | ||
return authorization | ||
except Exception as e: | ||
raise e | ||
|
||
def __rfc1123date(self): | ||
return datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT') | ||
|
||
# Build and send a request to the POST API | ||
def post_data(self, log_type, json_records, record_timestamp='', timeout=None): | ||
# Check if string contains other than alpha characters | ||
if not log_type.isalpha(): | ||
raise Exception( | ||
"ERROR: log_type supports only alpha characters: {}".format(log_type)) | ||
try: | ||
body = json.dumps(json_records) | ||
rfc1123date = self.__rfc1123date() | ||
content_length = len(body) | ||
signature = self.__signature(rfc1123date, content_length) | ||
uri = "https://{}.ods.opinsights.azure.com/api/logs?api-version={}".format( | ||
self.customer_id, _LOG_ANALYTICS_DATA_COLLECTOR_API_VERSION) | ||
|
||
""" | ||
time-generated-field | ||
The name of a field in the data that contains the timestamp of the data item. | ||
If this isn’t specified, the default is the time that the message is ingested. | ||
The field format is ISO 8601 format YYYY-MM-DDThh:mm:ssZ | ||
""" | ||
headers = { | ||
'content-type': 'application/json', | ||
'Authorization': signature, | ||
'Log-Type': log_type, | ||
'x-ms-date': rfc1123date, | ||
'time-generated-field': record_timestamp, | ||
'User-Agent': 'SentinelPartner-Forcepoint-DLP/1.8', | ||
} | ||
return requests.post(uri, data=body, headers=headers, timeout=timeout) | ||
except Exception as e: | ||
raise | ||
|
||
def health_check(self, log_type, record_timestamp='', timeout=10): | ||
try: | ||
|
||
rfc1123date = self.__rfc1123date() | ||
content_length = 0 | ||
signature = self.__signature(rfc1123date, content_length) | ||
uri = "https://{}.ods.opinsights.azure.com/api/logs?api-version={}".format( | ||
self.customer_id, _LOG_ANALYTICS_DATA_COLLECTOR_API_VERSION) | ||
|
||
""" | ||
time-generated-field | ||
The name of a field in the data that contains the timestamp of the data item. | ||
If this isn’t specified, the default is the time that the message is ingested. | ||
The field format is ISO 8601 format YYYY-MM-DDThh:mm:ssZ | ||
""" | ||
headers = { | ||
'content-type': 'application/json', | ||
'Authorization': signature, | ||
'Log-Type': log_type, | ||
'x-ms-date': rfc1123date, | ||
'time-generated-field': record_timestamp, | ||
'User-Agent': 'SentinelPartner-Forcepoint-DLP/1.8', | ||
} | ||
|
||
return requests.get(uri, headers=headers, timeout=timeout) | ||
except Exception as e: | ||
raise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def is_success(status_code): | ||
return True if (status_code == 200) else False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VERSION = "0.2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters