Skip to content

Commit 219ca8f

Browse files
gpavlidiYanis Pavlidisjkppr
authored
Fix back-to-back SecGemini investigations (#3597)
* Fix back to back investigations by forcing termination * Address review comments * fix linters * Adding docker host infos for local LLM dev. --------- Co-authored-by: Yanis Pavlidis <[email protected]> Co-authored-by: Janosch <[email protected]>
1 parent 01506b5 commit 219ca8f

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

data/timesketch.conf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,18 @@ LLM_PROVIDER_CONFIGS = {
424424
'secgemini_log_analyzer_agent': {
425425
'logs_processor_api_url': '',
426426
'api_key': '',
427-
'model': 'logs_analysis_agent-1.1'
427+
'model': 'logs_analysis_agent-1.1',
428+
'base_url': '',
429+
'wss_url': '',
430+
# Configuration for individual agents. This is a dictionary where the
431+
# key is the agent name and the value is another dictionary with
432+
# agent-specific configuration parameters.
433+
# Example:
434+
# 'agents_config': {
435+
# 'logs_analysis_loop_agent': {
436+
# 'max_iterations': 10,
437+
# }
438+
'agents_config': {},
428439
}
429440
},
430441
'default': {

docs/developers/getting-started.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,32 @@ Point your browser to `http://localhost:5001/` to access the new frontend UI.
146146
All changes to the `timesketch/frontend-ng/` path will be automatically build
147147
and loaded in the new frontend.
148148
149+
### Accessing services on your host machine
150+
151+
In some development scenarios, you might need the Timesketch container to
152+
communicate with a service running directly on your host machine (the "docker
153+
host"). A common use case is when you are running local LLM (Large Language
154+
Model) services (e.g., Ollama) that need access to hardware like GPUs which may
155+
not be available to the container.
156+
157+
To enable this, you need to make the docker host accessible from within the
158+
Timesketch container. You can achieve this by adding an `extra_hosts` entry to
159+
the `timesketch` service in your `docker/dev/docker-compose.yml` file:
160+
161+
```yaml
162+
services:
163+
timesketch:
164+
...
165+
# Make docker host accessible for local development.
166+
extra_hosts:
167+
- host.docker.internal:host-gateway
168+
```
169+
170+
After adding this and restarting your container, you can configure Timesketch to
171+
connect to services on your host using `http://host.docker.internal:<PORT>`. For
172+
example, you could configure an LLM provider in `timesketch.conf` to use a base
173+
URL of `http://host.docker.internal:8000`.
174+
149175
## API development
150176
151177
Exposing new functionality via the API starts at `/timesketch/api/v1/routes.py`.

timesketch/lib/llms/providers/secgemini_log_analyzer_agent.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,19 @@ def __init__(self, config: dict, **kwargs: Any):
6868
if self.server_url:
6969
os.environ["SEC_GEMINI_LOGS_PROCESSOR_API_URL"] = self.server_url
7070

71+
self.base_url = self.config.get("base_url")
72+
self.wss_url = self.config.get("wss_url")
73+
self.agents_config = self.config.get("agents_config", {})
74+
7175
try:
72-
self.sg_client = SecGemini(api_key=self.api_key)
76+
if self.base_url and self.wss_url:
77+
self.sg_client = SecGemini(
78+
base_url=self.base_url,
79+
base_websockets_url=self.wss_url,
80+
api_key=self.api_key,
81+
)
82+
else:
83+
self.sg_client = SecGemini(api_key=self.api_key)
7384
except Exception as e:
7485
raise ValueError(f"Failed to initialize SecGemini client: {e}") from e
7586

@@ -102,7 +113,9 @@ async def _run_async_stream(self, log_path, prompt):
102113
str: The content chunks of the streamed response from the agent.
103114
"""
104115
self._session = self.sg_client.create_session(
105-
model=self.model, enable_logging=self.enable_logging
116+
model=self.model,
117+
enable_logging=self.enable_logging,
118+
agents_config=self.agents_config,
106119
)
107120
self.session_id = self._session.id
108121
# TODO: Could we check if the API key has logging enabled and if not ERR
@@ -181,6 +194,8 @@ async def _run_async_stream(self, log_path, prompt):
181194

182195
if json_str:
183196
yield json_str
197+
# force termination to avoid back2back runs
198+
break
184199
finally:
185200
if debug_log_file:
186201
debug_log_file.close()

0 commit comments

Comments
 (0)