No project description provided
Project description
WithSecure Elements API Client
A Python client library for interacting with the WithSecure Elements API. This library provides a simple interface to manage organizations, devices, security incidents, and security events in your WithSecure Elements environment.
Installation
pip install withsecure-elements-api
Features
- Interact with WithSecure Elements API
- Organization management
- Device management and operations
- Device isolation and release
- Ask for malware scanning or diagnostic file collection
- Query missing update on device
- Assign profile
- Change subscription key
- Security incident monitoring
- Get details
- Retrieve detections linked to incident
- Update status and resolution
- Add comments
- Security event tracking
- Full support for pagination
- Handle raw JSON or Python objects
- Comprehensive error handling
Not implemented
- Invitations
Quick Start
Authentication
from withsecure import Client
# Initialize the client with your credentials
client = Client(
client_id="your_client_id",
secret_id="your_secret_id"
)
# Authenticate (read-only access)
client.authenticate()
# For read-write access
client.authenticate(read_write=True)
Working with Organizations
# Get all organizations
organizations = client.get_organizations()
# Get a specific organization by ID
org = client.get_organizations(organization_id="your_org_id")
# Get devices for a specific organization
devices = organizations[0].get_devices()
Managing Devices
# Get all devices
devices = client.get_devices()
# Get devices count
devices_count = client.devices_count()
# Get devices with filters
devices = client.get_devices(
organization_id="your_org_id",
device_type='computer',
online=True,
protection_status_overview='allOk',
limit=100
)
# Trigger operations on devices
device = devices[0]
# Network isolation
device.isolate(message="Security maintenance")
device.release()
# Security operations
device.scan_for_malware()
device.collect_diagnostic_file(consent_message="Please approve diagnostic collection")
# Profile and subscription management
device.assign_profile(profile_id="your_profile_id")
device.change_subscription_key(subscription_key="new_key")
# Software updates
updates = device.get_missing_updates(severity="critical", limit=100)
# Device state management
device.set_blocked()
device.set_inactive()
device.update_state(state="active")
Monitoring Security Incidents
# Get recent incidents
incidents = client.get_incident_list(
organization_id="your_org_id",
status=['new', 'inProgress'],
risk_level=["high", "severe"],
limit=50
)
# Incident management
incident = incidents[0]
# Get incident details and detections
detections = incident.get_detections(limit=100)
# Update incident status
incident.update_status(
status="inProgress",
)
# Add comments
incident.add_comment("Investigation in progress")
# Get incident details with all statuses
incident = client.get_incident_by_id("incident_uuid")
Tracking Security Events
# Get security events
events = client.get_security_events(
organization_id="your_org_id",
start_time=datetime.now() - timedelta(days=300),
engine_group="edr",
severity="high",
limit=200
)
# Get security events count
events_count = client.security_events_count(
organization_id="your_org_id",
start_time=datetime.now() - timedelta(days=300),
engine='all',
group_by='engine',
)
Working with Raw JSON
# Initialize client with JSON output
client = Client(
client_id="your_client_id",
secret_id="your_secret_id",
json_output=True
)
# Get raw JSON responses
devices_json = client.get_devices()
incidents_json = client.get_incident_list()
Advanced Usage
Using Organization Objects
# Get an organization
orgs, errors = client.get_organizations()
org = orgs[0]
# Access organization properties
print(f"Organization: {org.name} (ID: {org.id})")
# Get devices for this organization
devices = org.get_devices()
# Get incidents for this organization
incidents = org.get_incidents()
# Get security events for this organization
events = org.get_security_events(start_time=datetime.now() - timedelta(days=300), engine='all')
Working with Incidents
# Get incidents and work with incident objects
incidents = client.get_incident_list()
for incident in incidents:
print(f"Incident: {incident.name}")
print(f" - Status: {incident.status}")
print(f" - Severity: {incident.severity}")
print(f" - Created: {incident.created_timestamp}")
print(f" - Categories: {incident.categories}")
Error Handling
The client uses Python's exception system for error handling. All exceptions inherit from WithSecureError. Here's how to handle errors:
from withsecure import Client
from withsecure.exceptions import WithSecureError, AuthenticationError, ResourceNotFound, InvalidParameters
try:
client = Client(client_id="your_client_id", secret_id="your_secret_id")
client.authenticate()
# Get devices
devices = client.get_devices()
except AuthenticationError as e:
print(f"Authentication failed: {e}")
except ResourceNotFound as e:
print(f"Resource not found: {e}")
except InvalidParameters as e:
print(f"Invalid parameters: {e}")
except WithSecureError as e:
print(f"An error occurred: {e}")
Available exceptions:
WithSecureError: Base exception for all WithSecure Elements API errorsAuthenticationError: Raised when authentication failsAPIError: Base exception for API-related errorsResourceNotFound: When a requested resource is not foundRateLimitExceeded: When API rate limits are exceededServerError: When the API server returns an errorClientError: When there's an error on the client side
InvalidParameters: When invalid parameters are provided (e.g., invalid timeout values, missing required parameters)
Each API error includes:
status_code: HTTP status code (if applicable)response: The full response object (if applicable)message: Detailed error message
Example with detailed error handling:
from withsecure import Client
from withsecure.exceptions import WithSecureError, APIError
try:
client = Client(client_id="your_client_id", secret_id="your_secret_id")
client.authenticate()
devices = client.get_devices()
except APIError as e:
print(f"API Error: {e}")
print(f"Status Code: {e.status_code}")
if e.response:
print(f"Response: {e.response.text}")
except WithSecureError as e:
print(f"WithSecure Error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file withsecure_elements_api-0.1.1.tar.gz.
File metadata
- Download URL: withsecure_elements_api-0.1.1.tar.gz
- Upload date:
- Size: 27.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95b980b9b3e833e352be5c6cc07e1c3c6493deb74670af9cbb3eb62ba794126a
|
|
| MD5 |
6b79b2b4d72b34227be5279af1ae5d82
|
|
| BLAKE2b-256 |
547a4925c82b416d283700a0c8760789a03424d11be2f0107c41479801b865ef
|
Provenance
The following attestation bundles were made for withsecure_elements_api-0.1.1.tar.gz:
Publisher:
publish.yml on Attineos-Cyber/withsecure-elements-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
withsecure_elements_api-0.1.1.tar.gz -
Subject digest:
95b980b9b3e833e352be5c6cc07e1c3c6493deb74670af9cbb3eb62ba794126a - Sigstore transparency entry: 229376149
- Sigstore integration time:
-
Permalink:
Attineos-Cyber/withsecure-elements-api@abce22a34c5445d4425018cafd4c7fd3bed6cd65 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Attineos-Cyber
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@abce22a34c5445d4425018cafd4c7fd3bed6cd65 -
Trigger Event:
push
-
Statement type:
File details
Details for the file withsecure_elements_api-0.1.1-py3-none-any.whl.
File metadata
- Download URL: withsecure_elements_api-0.1.1-py3-none-any.whl
- Upload date:
- Size: 28.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c97b286e1ae33959ce297b2cd054ab57225444c6b51906bc9bef56954d89991
|
|
| MD5 |
57c8df3e323da07af92179d798daa648
|
|
| BLAKE2b-256 |
f5ef4e189ddfd676ff51f9ce915e240ecebda61c362a37816ee5ce889befa995
|
Provenance
The following attestation bundles were made for withsecure_elements_api-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on Attineos-Cyber/withsecure-elements-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
withsecure_elements_api-0.1.1-py3-none-any.whl -
Subject digest:
6c97b286e1ae33959ce297b2cd054ab57225444c6b51906bc9bef56954d89991 - Sigstore transparency entry: 229376150
- Sigstore integration time:
-
Permalink:
Attineos-Cyber/withsecure-elements-api@abce22a34c5445d4425018cafd4c7fd3bed6cd65 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Attineos-Cyber
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@abce22a34c5445d4425018cafd4c7fd3bed6cd65 -
Trigger Event:
push
-
Statement type: