TheHive API Client for Rust
TheHive is an open-source, scalable, and collaborative Security Incident Response Platform (SIRP). It is designed to help SOCs, CSIRTs, CERTs, and any security practitioner to investigate and respond to security incidents quickly and efficiently. TheHive allows analysts to create cases for investigations, add observables (like IPs, URLs, domains, files), create tasks, log their progress, and collaborate with team members.
The TheHive API provides a programmatic interface to its comprehensive set of features, offering several advantages:
- Automation: Automate the creation of alerts and cases from external systems (SIEMs, EDRs, email alerts), and manage their lifecycle programmatically.
- Integration: Seamlessly integrate TheHive's incident management capabilities into your existing security ecosystem (SOAR platforms, threat intelligence feeds, custom scripts).
- Scalability: Handle a large volume of security events and manage numerous cases and observables programmatically.
- Customization: Build custom scripts and tools that leverage TheHive's backend for tailored security operations and reporting.
- Efficiency: Speed up incident response by automating repetitive tasks, enriching cases with threat intelligence, and orchestrating response actions.
Installation
To use this client in your Rust project, add it as a dependency in your Cargo.toml.
[]
= "0.1"
Rust Usage Examples
Below are conceptual examples of how to use the generated Rust client to interact with TheHive API. Ensure you have configured your client with the correct TheHive URL and API key, via environment variables THEHIVE_API_ENDPOINT and THEHIVE_API_KEY.
1. Create an Alert with an IP Observable
This example demonstrates how to create a new alert in TheHive and attach an IP address as an observable.
use env;
use Configuration;
use alert_api; // Module for alert operations
use ;
async
2. Create a New Case
This example shows how to create a new case from scratch.
use env;
use Configuration;
use case_api; // Module for case operations
use ;
async
3. Promote an Alert to a Case
This example demonstrates how to promote an existing alert to a new case. You would get the alert_id_to_promote from a previous operation (like creating an alert).
use env;
use Configuration;
use alert_api;
use InputPromoteAlert;
async
Running the Examples
To run the provided examples, you'll first need to ensure you have a running TheHive instance and the necessary credentials. The examples are configured to use environment variables for the API endpoint and API key.
Prerequisites:
- A running TheHive 5.x instance.
- An API key for your TheHive user.
- Rust and Cargo installed.
- The client library cloned or added as a dependency to your project as described in the "Installation" section.
Environment Variables: Before running any example, you need to set the following environment variables in your terminal session:
THEHIVE_API_ENDPOINT: The URL of your TheHive API. If not set, it defaults tohttp://localhost:9000/apiin the examples.THEHIVE_API_KEY: Your TheHive API key. This variable must be set.
Executing an Example:
Once the environment variables are set, you can run an example using Cargo. The examples are located in the examples/ directory and defined in the Cargo.toml file.
For instance, to run an example named create_minimalistic_case:
Replace create_minimalistic_case with the actual name of the example you wish to run. You can list available examples by checking the examples/ directory and the Cargo.toml file.
Documentation for API Endpoints
All URIs are relative to http://localhost:9000/api
| Class | Method | HTTP request | Description |
|---|---|---|---|
| AlertApi | add_alert_attachments | POST /v1/alert/{alert_id}/attachments | Add attachments to an alert |
| AlertApi | bulk_delete_alerts | POST /v1/alert/delete/_bulk | Bulk delete alerts |
| AlertApi | bulk_merge_alerts_into_case | POST /v1/alert/merge/_bulk | Bulk merge alerts into a case |
| AlertApi | bulk_update_alerts | PATCH /v1/alert/_bulk | Bulk update alerts |
| AlertApi | create_alert | POST /v1/alert | Create an alert |
| AlertApi | create_alert_observable | POST /v1/alert/{alert_id}/observable | Create an observable in an alert |
| AlertApi | create_alert_procedure | POST /v1/alert/{alert_id}/procedure | Create a procedure in an alert |
| AlertApi | delete_alert | DELETE /v1/alert/{alert_id} | Delete an alert |
| AlertApi | delete_alert_attachment | DELETE /v1/alert/{alert_id}/attachment/{attachment_id} | Delete an alert attachment |
| AlertApi | download_alert_attachment | GET /v1/alert/{alert_id}/attachment/{attachment_id}/download | Download an alert attachment |
| AlertApi | follow_alert | POST /v1/alert/{alert_id}/follow | Follow an alert |
| AlertApi | get_alert_by_id | GET /v1/alert/{alert_id} | Get an alert by ID |
| AlertApi | merge_alert_into_case | POST /v1/alert/{alert_id}/merge/{case_id} | Merge an alert into an existing case |
| AlertApi | promote_alert_to_case | POST /v1/alert/{alert_id}/case | Promote an alert to a case |
| AlertApi | unfollow_alert | POST /v1/alert/{alert_id}/unfollow | Unfollow an alert |
| AlertApi | update_alert | PATCH /v1/alert/{alert_id} | Update an alert |
| CaseApi | create_case | POST /v1/case | Create a case |
| CaseApi | delete_case | DELETE /v1/case/{case_id} | Delete a case |
| CaseApi | get_case_by_id | GET /v1/case/{case_id} | Get a case by ID or number |
| CaseApi | update_case | PATCH /v1/case/{case_id} | Update a case |
| CaseTemplateApi | create_case_template | POST /v1/caseTemplate | Create a case template |
| CaseTemplateApi | delete_case_template | DELETE /v1/caseTemplate/{case_template_id} | Delete a case template |
| CaseTemplateApi | get_case_template_by_id | GET /v1/caseTemplate/{case_template_id} | Get a case template by ID |
| CaseTemplateApi | update_case_template | PATCH /v1/caseTemplate/{case_template_id} | Update a case template |
| CommentApi | create_alert_comment | POST /v1/alert/{alert_id}/comment | Create a comment in an alert |
| CommentApi | create_case_comment | POST /v1/case/{case_id}/comment | Create a comment in a case |
| CommentApi | delete_comment | DELETE /v1/comment/{comment_id} | Delete a comment |
| CommentApi | update_comment | PATCH /v1/comment/{comment_id} | Update a comment |
| QueryApi | find_entities_by_query | POST /v1/query | Find entities using a flexible query |
| UserApi | create_user | POST /v1/user | Create a new user |
| UserApi | delete_user | DELETE /v1/user/{user_id}/force | Delete a user (force) |
| UserApi | get_current_user | GET /v1/user/current | Get current authenticated user's details |
| UserApi | get_user_api_key | GET /v1/user/{user_id}/key | Get user's API key |
| UserApi | get_user_by_id | GET /v1/user/{user_id} | Get user details by ID |
| UserApi | remove_user_api_key | DELETE /v1/user/{user_id}/key | Remove user's API key |
| UserApi | renew_user_api_key | POST /v1/user/{user_id}/key/renew | Renew user's API key |
| UserApi | set_user_organisations | PUT /v1/user/{user_id}/organisations | Set user's organisations and profiles |
| UserApi | set_user_password | POST /v1/user/{user_id}/password/set | Set a user's password |
| UserApi | update_user | PATCH /v1/user/{user_id} | Update user details |
Documentation For Models
- AddAlertAttachments201Response
- BulkDeleteAlertsRequest
- BulkMergeAlertsIntoCaseRequest
- CaseStatusValue
- ErrorResponse
- FindEntitiesByQuery200Response
- ImpactStatusValue
- InputAlert
- InputAnalyzerJob
- InputApplyCaseTemplate
- InputBulkOrganisationLink
- InputBulkUpdateAlert
- InputBulkUpdateCase
- InputBulkUpdateObservable
- InputBulkUpdateTask
- InputCase
- InputCasePage
- InputCaseTemplate
- InputComment
- InputCustomEvent
- InputCustomField
- InputCustomFieldValue
- InputImportCase
- InputObservable
- InputObservableType
- InputOrganisation
- InputOrganisationLink
- InputProcedure
- InputProfile
- InputPromoteAlert
- InputQuery
- InputResponderAction
- InputShare
- InputTask
- InputTaskLog
- InputUpdateAlert
- InputUpdateCase
- InputUpdateCasePage
- InputUpdateComment
- InputUpdateCustomEvent
- InputUpdateCustomField
- InputUpdateObservable
- InputUpdateOrganisation
- InputUpdateProcedure
- InputUpdateProfile
- InputUpdateTask
- InputUpdateTaskLog
- InputUpdateUser
- InputUser
- InputUserOrganisation
- MergeAlertIntoCaseCaseIdParameter
- OutputAlert
- OutputAnalyzer
- OutputAnalyzerJob
- OutputAttachment
- OutputCase
- OutputCasePage
- OutputCaseTemplate
- OutputComment
- OutputCustomEvent
- OutputCustomField
- OutputCustomFieldValue
- OutputObservable
- OutputObservableType
- OutputOrganisation
- OutputOrganisationProfile
- OutputProcedure
- OutputProfile
- OutputResponder
- OutputResponderAction
- OutputShare
- OutputSharingProfile
- OutputTask
- OutputTaskLog
- OutputTimeline
- OutputTimelineEvent
- OutputUser
- OutputUserOrganisation
- PapValue
- QueryFilterLt
- QueryFilterLtAllOfLt
- QueryOperation
- QueryPaginate
- QuerySortExpr
- SetUserOrganisations200Response
- SetUserOrganisationsRequest
- SetUserPasswordRequest
- SeverityValue
- TlpValue