-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge "manage sfExtras.py module in sf-operator"
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright (C) 2023 Red Hat | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
||
import os | ||
import logging | ||
|
||
import requests | ||
|
||
|
||
class SimpleFluentBitHTTPInputHandler(logging.Handler): | ||
"""A minimal handler for sending logs to the HTTP Input | ||
of a Fluent Bit collector.""" | ||
def __init__(self, url, env_prefix=None): | ||
logging.Handler.__init__(self) | ||
self.url = url | ||
self.env_prefix = env_prefix | ||
|
||
def emit(self, record): | ||
d = { | ||
'log': self.format(record) | ||
} | ||
if self.env_prefix is not None: | ||
for envvar in os.environ: | ||
if envvar.startswith(self.env_prefix): | ||
key = envvar[len(self.env_prefix):].lower() | ||
d[key] = os.environ[envvar] | ||
try: | ||
req = requests.post(self.url, json=d) | ||
req.raise_for_status() | ||
except requests.HTTPError as e: | ||
self.handleError(record) |
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