Skip to content

Commit

Permalink
fix query name
Browse files Browse the repository at this point in the history
  • Loading branch information
talltechy committed Apr 19, 2024
1 parent ac76d8d commit 064fc2d
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/rapid7/api_r7_isvm_sonar_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
secrets = dotenv_values(".env")

def load_csv(filepath):
# Load CSV and return as DataFrame, automatically stripping whitespace from headers
"""
DataFrame: The loaded data.
Returns:
filepath (str): The path to the CSV file.
Args:
Load a CSV file and return it as a DataFrame, automatically stripping whitespace from headers.
"""
return pd.read_csv(filepath, skipinitialspace=True)

def create_sonar_query(url, name, criteria, username, password):
Expand All @@ -33,12 +41,23 @@ def create_sonar_query(url, name, criteria, username, password):
return response.status_code, response.text

def main():
"""
Main function to create Sonar queries based on data from a CSV file.
This function reads data from a CSV file, cleans the data, and creates Sonar queries based on the data.
The queries are then sent to the specified InsightVM host using the provided credentials.
Parameters:
None
Returns:
None
"""
filepath = 'test.csv' # Update with your file path
ivm_host = secrets['ivm_host']
ivm_port = secrets['ivm_port']
username = secrets['ivm_username']
password = secrets['ivm_password']

# Construct the URL using the host and port
url = f'https://{ivm_host}:{ivm_port}/api/3/sonar_queries' # API endpoint

Expand Down Expand Up @@ -81,9 +100,8 @@ def main():

criteria = {"filters": filters}
name = "Example Sonar Query"

name = row['domain'] if pd.notna(row['domain']) else row['ip_lower'] if pd.notna(row['ip_lower']) else f"{row['ip_lower']} - {row['ip_upper']}"
status_code, response_text = create_sonar_query(url, name, criteria, username, password)

print("Status Code:", status_code)
print("Response:", response_text)

Expand Down

0 comments on commit 064fc2d

Please sign in to comment.