How to use Falconpy
#1021
-
Hello everyone, everything good ? How do I start with Falconpy in my terminal? |
Beta Was this translation helpful? Give feedback.
Answered by
jshcodes
Aug 17, 2023
Replies: 1 comment
-
Hi @felipemor - If you've got Python configured, then the next step would be to configure your API client keys (within the CrowdStrike console navigate to Support and resources -> API clients and keys) and then start coding! Quick Start procedureIf we use the Quick Start from the main README.md for this repository as an example, the steps would be:
Quick Start code"""CrowdStrike FalconPy Quick Start."""
import os
from falconpy import Hosts
# Use the API Clients and Keys page within your Falcon console to generate credentials.
# You will need to assign the Hosts: READ scope to your client to run this example.
# CrowdStrike does not recommend you hardcode credentials within source code.
# Instead, provide these values as variables that are retrieved from the environment,
# read from an encrypted file or secrets store, provided at runtime, etc.
# This example retrieves credentials from the environment as the variables
# "FALCON_CLIENT_ID" and "FALCON_CLIENT_SECRET".
hosts = Hosts(client_id=os.getenv("FALCON_CLIENT_ID"),
client_secret=os.getenv("FALCON_CLIENT_SECRET")
)
SEARCH_FILTER = "hostname-search-string"
# Retrieve a list of hosts that have a hostname that matches our search filter
hosts_search_result = hosts.query_devices_by_filter(filter=f"hostname:*'*{SEARCH_FILTER}*'")
# Confirm we received a success response back from the CrowdStrike API
if hosts_search_result["status_code"] == 200:
hosts_found = hosts_search_result["body"]["resources"]
# Confirm our search produced results
if hosts_found:
# Retrieve the details for all matches
hosts_detail = hosts.get_device_details(ids=hosts_found)["body"]["resources"]
for detail in hosts_detail:
# Display the AID and hostname for this match
aid = detail["device_id"]
hostname = detail["hostname"]
print(f"{hostname} ({aid})")
else:
print("No hosts found matching that hostname within your Falcon tenant.")
else:
# Retrieve the details of the error response
error_detail = hosts_search_result["body"]["errors"]
for error in error_detail:
# Display the API error detail
error_code = error["code"]
error_message = error["message"]
print(f"[Error {error_code}] {error_message}") |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jshcodes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @felipemor -
If you've got Python configured, then the next step would be to configure your API client keys (within the CrowdStrike console navigate to Support and resources -> API clients and keys) and then start coding!
Quick Start procedure
If we use the Quick Start from the main README.md for this repository as an example, the steps would be:
example.py
.