-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support multiple destinations for a healthcheck #2704
Merged
sbylica-splunk
merged 2 commits into
develop
from
support_multiple_destinations_healthcheck
Mar 11, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||
import logging | ||||
import os | ||||
import subprocess | ||||
import re | ||||
|
||||
from flask_wtf.csrf import CSRFProtect | ||||
from flask import Flask, jsonify | ||||
|
@@ -18,11 +19,20 @@ def str_to_bool(value): | |||
'yes' | ||||
} | ||||
|
||||
def get_list_of_destinations(): | ||||
found_destinations = [] | ||||
regex = r"^SC4S_DEST_SPLUNK_HEC_(.*)_URL$" | ||||
|
||||
for var_key, var_variable in os.environ.items(): | ||||
if re.search(regex, var_key): | ||||
found_destinations.append(var_variable) | ||||
return set(found_destinations) | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be imported from:
But a dot in "conf.d" is causing an import issue. Something to think about later I guess |
||||
class Config: | ||||
SC4S_DEST_SPLUNK_HEC_DEFAULT_URL = os.getenv('SC4S_DEST_SPLUNK_HEC_DEFAULT_URL') | ||||
HEALTHCHECK_PORT = int(os.getenv('SC4S_LISTEN_STATUS_PORT', '8080')) | ||||
CHECK_QUEUE_SIZE = str_to_bool(os.getenv('HEALTHCHECK_CHECK_QUEUE_SIZE', "false")) | ||||
MAX_QUEUE_SIZE = int(os.getenv('HEALTHCHECK_MAX_QUEUE_SIZE', '10000')) | ||||
DESTINATIONS = get_list_of_destinations() | ||||
|
||||
logging.basicConfig( | ||||
format="%(asctime)s - healthcheck.py - %(levelname)s - %(message)s", | ||||
|
@@ -52,11 +62,11 @@ def check_syslog_ng_health() -> bool: | |||
return False | ||||
|
||||
def check_queue_size( | ||||
sc4s_dest_splunk_hec_default=Config.SC4S_DEST_SPLUNK_HEC_DEFAULT_URL, | ||||
sc4s_dest_splunk_hec_destinations=Config.DESTINATIONS, | ||||
max_queue_size=Config.MAX_QUEUE_SIZE | ||||
) -> bool: | ||||
"""Check syslog-ng queue size and compare it against the configured maximum limit.""" | ||||
if not sc4s_dest_splunk_hec_default: | ||||
if not sc4s_dest_splunk_hec_destinations: | ||||
logger.error( | ||||
"SC4S_DEST_SPLUNK_HEC_DEFAULT_URL not configured. " | ||||
"Ensure the default HEC destination is set, or disable HEALTHCHECK_CHECK_QUEUE_SIZE." | ||||
|
@@ -75,15 +85,22 @@ def check_queue_size( | |||
return False | ||||
|
||||
stats = result.stdout.splitlines() | ||||
destination_stat = next( | ||||
(s for s in stats if ";queued;" in s and sc4s_dest_splunk_hec_default in s), | ||||
None | ||||
) | ||||
if not destination_stat: | ||||
logger.error("No matching queue stats found for the destination URL.") | ||||
return False | ||||
|
||||
queue_size = int(destination_stat.split(";")[-1]) | ||||
queue_sizes_all_destinations = [] | ||||
|
||||
for destination in sc4s_dest_splunk_hec_destinations: | ||||
destination_stat = next( | ||||
(s for s in stats if ";queued;" in s and destination in s), | ||||
None | ||||
) | ||||
|
||||
if not destination_stat: | ||||
logger.error(f"No matching queue stats found for the destination URL {destination}.") | ||||
return False | ||||
|
||||
queue_sizes_all_destinations.append(int(destination_stat.split(";")[-1])) | ||||
|
||||
queue_size = max(queue_sizes_all_destinations) | ||||
if queue_size > max_queue_size: | ||||
logger.warning( | ||||
f"Queue size {queue_size} exceeds the maximum limit of {max_queue_size}." | ||||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just have 2 questions:
health check api
to healthcheckP.S. It's just a questions, it doesn't mean that we need to do asap, we will just discuss it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mstopa-splunk @rjha-splunk - we can talk about this on our sc4s meeting