Skip to content
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

Fix Imperva module connector #912

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Imperva/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## 2024-04-03 - 1.20

### Changed

- Use Sekoia-automation-SDK to push events to intake

## 2023-11-22 - 1.18

### Changed
Expand Down
43 changes: 0 additions & 43 deletions Imperva/imperva/fetch_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,49 +286,6 @@ def _retry(self):
reraise=True,
)

@cached_property
def __connector_user_agent(self):
return f"sekoiaio-connector-{self.configuration['intake_key']}"

def push_events_to_intakes(self, events: list[str]) -> list:
# no event to push
if not events:
return []

# Reset the consecutive error count
self._error_count = 0
self._last_events_time = datetime.utcnow()
intake_host = os.environ.get("SEKOIAIO_INTAKE_HOST", "https://intake.sekoia.io")
batch_api = urljoin(intake_host, "batch")

# Collect event_ids
event_ids: list = []

# forward the events
for chunk in self._chunk_events(events):
try:
request_body = {
"intake_key": self.configuration["intake_key"],
"jsons": chunk,
}

for attempt in self._retry():
with attempt:
res: Response = requests.post(
batch_api,
json=request_body,
headers={"User-Agent": self.__connector_user_agent},
timeout=30,
)
if res.status_code > 299:
self.log(f"Intake rejected events: {res.text}", level="error")
res.raise_for_status()
event_ids.extend(res.json().get("event_ids", []))
except Exception as ex:
self.log_exception(ex, message=f"Failed to forward {len(chunk)} events")

return event_ids

def handle_log_decrypted_content(self, decrypted_file):
decrypted_file = decrypted_file.decode("utf-8") # many lines
events_list: list[str] = decrypted_file.split("\n")
Expand Down
2 changes: 1 addition & 1 deletion Imperva/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@
"name": "Imperva",
"uuid": "ee0e5c81-5410-48d4-b155-135679c5ebb8",
"slug": "imperva",
"version": "1.19.0"
"version": "1.20.0"
}
Loading
Loading