| 1 | import httpx |
| 2 | from loguru import logger |
| 3 | |
| 4 | from app.integrations.modules.schema.sap_siem import CollectSapSiemRequest |
| 5 | from app.integrations.modules.schema.sap_siem import InvokeSapSiemAnalysis |
| 6 | |
| 7 | |
| 8 | async def post_to_copilot_sap_module_collect(data: CollectSapSiemRequest): |
| 9 | """ |
| 10 | Send a POST request to the copilot-sap-module Docker container. |
| 11 | |
| 12 | Args: |
| 13 | data (CollectHuntress): The data to send to the copilot-sap-module Docker container. |
| 14 | """ |
| 15 | logger.info(f"Sending POST request to http://copilot-sap-module/collect with data: {data.model_dump()}") |
| 16 | async with httpx.AsyncClient() as client: |
| 17 | try: |
| 18 | response = await client.post( |
| 19 | "http://copilot-sap-module/sap-siem/collect", |
| 20 | json=data.to_dict(), |
| 21 | timeout=120, |
| 22 | ) |
| 23 | logger.info(f"Response from copilot-sap-module: {response.json()}") |
| 24 | except httpx.RequestError as e: |
| 25 | logger.error(f"An error occurred while sending the POST request to copilot-sap-module: {e}") |
| 26 | return None |
| 27 | |
| 28 | |
| 29 | async def post_to_copilot_sap_module_sap_siem_successful_user_login_with_different_ip(data: InvokeSapSiemAnalysis): |
| 30 | """ |
| 31 | Send a POST request to the copilot-sap-module Docker container. |
| 32 | |
| 33 | Args: |
| 34 | data (InvokeSapSiemAnalysis): The data to send to the copilot-sap-module Docker container. |
| 35 | """ |
| 36 | logger.info( |
| 37 | f"Sending POST request to http://copilot-sap-module/sap-siem/same_user_failed_login_from_different_ip with data: {data.model_dump()}", |
| 38 | ) |
| 39 | async with httpx.AsyncClient() as client: |
| 40 | try: |
| 41 | response = await client.post( |
| 42 | "http://copilot-sap-module/sap-siem/successful_user_login_with_different_ip", |
| 43 | json=data.model_dump(), |
| 44 | timeout=120, |
| 45 | ) |
| 46 | logger.info(f"Response from copilot-sap-module: {response.json()}") |
| 47 | except httpx.RequestError as e: |
| 48 | logger.error(f"An error occurred while sending the POST request to copilot-sap-module: {e}") |
| 49 | return None |
| 50 | |
| 51 | |
| 52 | async def post_to_copilot_sap_module_same_user_failed_login_from_different_ip(data: InvokeSapSiemAnalysis): |
| 53 | """ |
| 54 | Send a POST request to the copilot-sap-module Docker container. |
| 55 | |
| 56 | Args: |
| 57 | data (InvokeSapSiemAnalysis): The data to send to the copilot-sap-module Docker container. |
| 58 | """ |
| 59 | logger.info( |
| 60 | f"Sending POST request to http://copilot-sap-module/sap-siem/same_user_failed_login_from_different_ip with data: {data.model_dump()}", |
| 61 | ) |
| 62 | async with httpx.AsyncClient() as client: |
| 63 | try: |
| 64 | response = await client.post( |
| 65 | "http://copilot-sap-module/sap-siem/same_user_failed_login_from_different_ip", |
| 66 | json=data.model_dump(), |
| 67 | timeout=120, |
| 68 | ) |
| 69 | logger.info(f"Response from copilot-sap-module: {response.json()}") |
| 70 | except httpx.RequestError as e: |
| 71 | logger.error(f"An error occurred while sending the POST request to copilot-sap-module: {e}") |
| 72 | return None |
| 73 | |
| 74 | |
| 75 | async def post_to_copilot_sap_module_same_user_failed_login_from_different_geo_location(data: InvokeSapSiemAnalysis): |
| 76 | """ |
| 77 | Send a POST request to the copilot-sap-module Docker container. |
| 78 | |
| 79 | Args: |
| 80 | data (InvokeSapSiemAnalysis): The data to send to the copilot-sap-module Docker container. |
| 81 | """ |
| 82 | logger.info( |
| 83 | f"Sending POST request to http://copilot-sap-module/sap-siem/same_user_failed_login_from_different_geo_location with data: {data.model_dump()}", |
| 84 | ) |
| 85 | async with httpx.AsyncClient() as client: |
| 86 | try: |
| 87 | response = await client.post( |
| 88 | "http://copilot-sap-module/sap-siem/same_user_failed_login_from_different_geo_location", |
| 89 | json=data.model_dump(), |
| 90 | timeout=120, |
| 91 | ) |
| 92 | logger.info(f"Response from copilot-sap-module: {response.json()}") |
| 93 | except httpx.RequestError as e: |
| 94 | logger.error(f"An error occurred while sending the POST request to copilot-sap-module: {e}") |
| 95 | return None |
| 96 | |
| 97 | |
| 98 | async def post_to_copilot_sap_module_same_user_successful_login_from_different_geo_location(data: InvokeSapSiemAnalysis): |
| 99 | """ |
| 100 | Send a POST request to the copilot-sap-module Docker container. |
| 101 | |
| 102 | Args: |
| 103 | data (InvokeSapSiemAnalysis): The data to send to the copilot-sap-module Docker container. |
| 104 | """ |
| 105 | logger.info( |
| 106 | f"Sending POST request to http://copilot-sap-module/sap-siem/same_user_successful_login_from_different_geo_location with data: {data.model_dump()}", |
| 107 | ) |
| 108 | async with httpx.AsyncClient() as client: |
| 109 | try: |
| 110 | response = await client.post( |
| 111 | "http://copilot-sap-module/sap-siem/same_user_successful_login_from_different_geo_location", |
| 112 | json=data.model_dump(), |
| 113 | timeout=120, |
| 114 | ) |
| 115 | logger.info(f"Response from copilot-sap-module: {response.json()}") |
| 116 | except httpx.RequestError as e: |
| 117 | logger.error(f"An error occurred while sending the POST request to copilot-sap-module: {e}") |
| 118 | return None |
| 119 | |
| 120 | |
| 121 | async def post_to_copilot_sap_module_brute_force_failed_logins_multiple_ips(data: InvokeSapSiemAnalysis): |
| 122 | """ |
| 123 | Send a POST request to the copilot-sap-module Docker container. |
| 124 | |
| 125 | Args: |
| 126 | data (InvokeSapSiemAnalysis): The data to send to the copilot-sap-module Docker container. |
| 127 | """ |
| 128 | logger.info( |
| 129 | f"Sending POST request to http://copilot-sap-module/sap-siem/brute_force_failed_logins_multiple_ips with data: {data.model_dump()}", |
| 130 | ) |
| 131 | async with httpx.AsyncClient() as client: |
| 132 | try: |
| 133 | response = await client.post( |
| 134 | "http://copilot-sap-module/sap-siem/brute_force_failed_logins_multiple_ips", |
| 135 | json=data.model_dump(), |
| 136 | timeout=120, |
| 137 | ) |
| 138 | logger.info(f"Response from copilot-sap-module: {response.json()}") |
| 139 | except httpx.RequestError as e: |
| 140 | logger.error(f"An error occurred while sending the POST request to copilot-sap-module: {e}") |
| 141 | return None |
| 142 | |
| 143 | |
| 144 | async def post_to_copilot_sap_module_brute_force_failed_logins_same_ip(data: InvokeSapSiemAnalysis): |
| 145 | """ |
| 146 | Send a POST request to the copilot-sap-module Docker container. |
| 147 | |
| 148 | Args: |
| 149 | data (InvokeSapSiemAnalysis): The data to send to the copilot-sap-module Docker container. |
| 150 | """ |
| 151 | logger.info( |
| 152 | f"Sending POST request to http://copilot-sap-module/sap-siem/brute_force_failed_logins_same_ip with data: {data.model_dump()}", |
| 153 | ) |
| 154 | async with httpx.AsyncClient() as client: |
| 155 | try: |
| 156 | response = await client.post( |
| 157 | "http://copilot-sap-module/sap-siem/brute_force_failed_logins_same_ip", |
| 158 | json=data.model_dump(), |
| 159 | timeout=120, |
| 160 | ) |
| 161 | logger.info(f"Response from copilot-sap-module: {response.json()}") |
| 162 | except httpx.RequestError as e: |
| 163 | logger.error(f"An error occurred while sending the POST request to copilot-sap-module: {e}") |
| 164 | return None |
| 165 | |
| 166 | |
| 167 | async def post_to_copilot_sap_module_successful_login_after_multiple_failed_logins(data: InvokeSapSiemAnalysis): |
| 168 | """ |
| 169 | Send a POST request to the copilot-sap-module Docker container. |
| 170 | |
| 171 | Args: |
| 172 | data (InvokeSapSiemAnalysis): The data to send to the copilot-sap-module Docker container. |
| 173 | """ |
| 174 | logger.info( |
| 175 | f"Sending POST request to http://copilot-sap-module/sap-siem/successful_login_after_multiple_failed_logins with data: {data.model_dump()}", |
| 176 | ) |
| 177 | async with httpx.AsyncClient() as client: |
| 178 | try: |
| 179 | response = await client.post( |
| 180 | "http://copilot-sap-module/sap-siem/successful_login_after_multiple_failed_logins", |
| 181 | json=data.model_dump(), |
| 182 | timeout=120, |
| 183 | ) |
| 184 | logger.info(f"Response from copilot-sap-module: {response.json()}") |
| 185 | except httpx.RequestError as e: |
| 186 | logger.error(f"An error occurred while sending the POST request to copilot-sap-module: {e}") |
| 187 | return None |