Fixed Breaking Datetime change
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
import utils.pretty as ct
|
||||
|
||||
#Standard Libary Imports:
|
||||
from datetime import datetime
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
@@ -198,22 +198,21 @@ def findAllAgents(url):
|
||||
def findAgents(url, device_input_str):
|
||||
|
||||
os.makedirs("device_search", exist_ok=True)
|
||||
# Step 1: Get the DataFrame from your function
|
||||
df = findAllAgents(url)
|
||||
|
||||
# Step 2: Parse the input string into device names (newline-separated only)
|
||||
#Parse the input string into device names (newline-separated only)
|
||||
device_names = device_input_str.strip().split('\n')
|
||||
device_names = [name.strip() for name in device_names if name.strip()]
|
||||
|
||||
# Step 3: Build a regex pattern for case-insensitive matching
|
||||
#Build a regex pattern for case-insensitive matching
|
||||
pattern = '|'.join([re.escape(name) for name in device_names])
|
||||
regex = re.compile(pattern, re.IGNORECASE)
|
||||
|
||||
# Step 4: Filter the DataFrame using regex
|
||||
#Filter the DataFrame using regex
|
||||
matched_df = df[df['hostname'].apply(lambda x: bool(regex.search(str(x))))]
|
||||
|
||||
# Step 5: Export to CSV with timestamp
|
||||
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
||||
#Export to CSV with timestamp
|
||||
timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
||||
filename = f"agentsearch_{timestamp}.csv"
|
||||
matched_df.to_csv(f"device_search\\{filename}", index=False)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user