Expand description
§VictorOps Rust Client
A Rust client library for the VictorOps (Splunk On-Call) REST API.
§Features
- Complete VictorOps REST API coverage
- Async/await support with Tokio
- Type-safe API responses with Serde
- Comprehensive error handling
- Request/response details for debugging
- Configurable HTTP client with timeout support
§Installation
Add this to your Cargo.toml:
[dependencies]
victorops = "0.1.0"§Quick Start
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_id = "your-api-id".to_string();
let api_key = "your-api-key".to_string();
let client = victorops::Client::new(
api_id,
api_key,
"https://api.victorops.com".to_string(),
)?;
let (incidents, _details) = client.get_incidents().await?;
println!("Found {} incidents", incidents.incidents.len());
Ok(())
}§Examples
Run the team schedule example:
export VICTOROPS_API_ID="your-api-id"
export VICTOROPS_API_KEY="your-api-key"
cargo run --example team_schedule team-slugRun the incidents example:
export VICTOROPS_API_ID="your-api-id"
export VICTOROPS_API_KEY="your-api-key"
cargo run --example incidents§API Coverage
§Incidents
get_incident(id)- Get a specific incidentget_incidents()- Get all incidents
§Users
create_user(user)- Create a new userget_user(username)- Get user by usernameget_user_by_email(email)- Get user by email addressget_all_users()- Get all users (v1)get_all_users_v2()- Get all users (v2)update_user(user)- Update user informationdelete_user(username, replacement)- Delete user with replacement
§Teams
create_team(team)- Create a new teamget_team(team_id)- Get team by IDget_all_teams()- Get all teamsget_team_members(team_id)- Get team membersget_team_admins(team_id)- Get team administratorsupdate_team(team)- Update team informationdelete_team(team_id)- Delete teamadd_team_member(team_id, username)- Add member to teamremove_team_member(team_id, username, replacement)- Remove member from teamis_team_member(team_id, username)- Check if user is team member
§On-Call Schedules
get_api_team_schedule()- Get team on-call scheduleget_user_on_call_schedule()- Get user on-call scheduletake_on_call_for_team()- Take on-call for teamtake_on_call_for_policy()- Take on-call for escalation policy
§Escalation Policies
create_escalation_policy(policy)- Create escalation policyget_escalation_policy(id)- Get escalation policy by IDget_all_escalation_policies()- Get all escalation policiesdelete_escalation_policy(id)- Delete escalation policy
§Routing Keys
create_routing_key(key)- Create routing keyget_routing_key(name)- Get routing key by nameget_all_routing_keys()- Get all routing keys
§Contact Methods
create_contact(username, contact)- Create contact methodget_contact(username, ext_id, type)- Get contact methodget_all_contacts(username)- Get all contact methods for userget_contact_by_id(username, id, type)- Get contact method by IDdelete_contact(username, ext_id, type)- Delete contact method
§Configuration
§Basic Client
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = victorops::Client::new(
"api-id".to_string(),
"api-key".to_string(),
"https://api.victorops.com".to_string(),
)?;
Ok(())
}§Client with Custom Timeout
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = victorops::Client::with_timeout(
"api-id".to_string(),
"api-key".to_string(),
"https://api.victorops.com".to_string(),
Duration::from_secs(60),
)?;
Ok(())
}§Request Details
All API methods return a tuple containing the response data and request details:
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = victorops::Client::new(
"api-id".to_string(),
"api-key".to_string(),
"https://api.victorops.com".to_string(),
)?;
let (user, details) = client.get_user("username").await?;
println!("Status: {}", details.status_code);
println!("Response: {}", details.response_body);
println!("Request: {}", details.request_body);
Ok(())
}§Error Handling
The library provides comprehensive error handling through the Error enum:
use victorops::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = victorops::Client::new(
"api-id".to_string(),
"api-key".to_string(),
"https://api.victorops.com".to_string(),
)?;
match client.get_user("nonexistent").await {
Ok((user, _)) => println!("User found: {:?}", user),
Err(Error::Api { status: 404, .. }) => println!("User not found"),
Err(Error::Http(e)) => println!("HTTP error: {}", e),
Err(e) => println!("Other error: {}", e),
}
Ok(())
}§Error Types
Http- HTTP request failuresJson- JSON serialization/deserialization errorsUrlParse- URL parsing errorsInvalidHeaderValue- Invalid HTTP header valuesApi- API-specific errors with status codesAuthentication- Authentication failuresNotFound- Resource not foundInvalidInput- Invalid input parameters
§Types
The library includes comprehensive type definitions for all VictorOps entities:
User- User account informationTeam- Team details and membershipIncident- Incident data and transitionsEscalationPolicy- Escalation policy configurationContact- Contact method informationRoutingKey- Routing key configuration- Schedule types for on-call management
All types support Serde serialization/deserialization and include optional fields as appropriate for the VictorOps API.
§License
This project is licensed under the MIT License.