Skip to content

Commit

Permalink
Update event_generator to use date_time_no_millis compatible datetime…
Browse files Browse the repository at this point in the history
… format
  • Loading branch information
QU3B1M committed Dec 3, 2024
1 parent a84acd8 commit 0f2bc40
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ecs/command/event-generator/event_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

def generate_random_date(initial_date=None, days_range=30):
if initial_date is None:
initial_date = datetime.datetime.now()
initial_date = datetime.datetime.now(datetime.timezone.utc)
random_days = random.randint(0, days_range)
new_timestamp = initial_date + datetime.timedelta(days=random_days)
return int(new_timestamp.timestamp() * 1000) # Convert to milliseconds and return as int
return new_timestamp.strftime('%Y-%m-%dT%H:%M:%SZ')


def generate_random_command(include_all_fields=False):
Expand Down Expand Up @@ -89,10 +89,10 @@ def inject_events(ip, port, index, username, password, data, use_index=False):
if use_index:
# Generate UUIDs for the document id
doc_id = str(uuid.uuid4())
url = f'https://{ip}:{port}/{index}/_doc/{doc_id}'
url = f'http://{ip}:{port}/{index}/_doc/{doc_id}'
else:
# Default URL for command manager API without the index
url = f'https://{ip}:{port}/_plugins/_command_manager/commands'
url = f'http://{ip}:{port}/_plugins/_command_manager/commands'
response = session.post(url, json=event_data, headers=headers)
if response.status_code != 201:
logging.error(f'Error: {response.status_code}')
Expand Down

0 comments on commit 0f2bc40

Please sign in to comment.