-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change file output to CSV with a config parameter for separator
- Loading branch information
Showing
6 changed files
with
58 additions
and
18 deletions.
There are no files selected for viewing
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
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,35 @@ | ||
import logging | ||
import os | ||
from . import _Interface | ||
import collections | ||
import pandas | ||
|
||
|
||
class FileInterface(_Interface.Interface): | ||
|
||
def __init__(self, path='output', separate_by_content_type=True, separator=';', **kwargs): | ||
""" | ||
Interface to send logs to an Azure Log Analytics Workspace. | ||
""" | ||
super().__init__(**kwargs) | ||
self.path = path | ||
self.paths = {} | ||
self.separate_by_content_type = separate_by_content_type | ||
self.separator = separator | ||
self.results = collections.defaultdict(pandas.DataFrame) | ||
|
||
def _send_message(self, msg, content_type, **kwargs): | ||
|
||
if content_type not in self.paths: | ||
self.paths[content_type] = "{}_{}.csv".format(self.path, content_type.replace('.', '')) \ | ||
if self.separate_by_content_type else self.path | ||
df = pandas.json_normalize(msg) | ||
self.results[content_type] = pandas.concat([self.results[content_type], df]) | ||
|
||
def output(self): | ||
|
||
for content_type, result in self.results.items(): | ||
result.to_csv(self.paths[content_type], index=False, sep=self.separator, mode='a', | ||
header=not os.path.exists(self.paths[content_type])) | ||
|
||
|
Binary file not shown.