This document provides comprehensive documentation for the OpsSight DevOps Platform API.
- Overview
- Authentication
- API Endpoints
- Data Models
- Error Handling
- Rate Limiting
- Webhooks
- SDKs and Libraries
- Examples
The OpsSight API is a RESTful API that provides access to DevOps metrics, monitoring data, and platform functionality. The API is built using FastAPI and follows OpenAPI 3.0 specification.
Base URL: https://api.your-domain.com/api/v1
Content Type: application/json
API Version: v1
- Swagger UI:
https://api.your-domain.com/docs - ReDoc:
https://api.your-domain.com/redoc - OpenAPI Schema:
https://api.your-domain.com/openapi.json
The API uses JWT (JSON Web Tokens) for authentication with GitHub OAuth integration.
-
Authorization Request
GET /auth/github -
Authorization Callback
GET /auth/github/callback?code={authorization_code}&state={state} -
Token Response
{ "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...", "refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...", "token_type": "bearer", "expires_in": 3600 }
All authenticated requests must include the Authorization header:
Authorization: Bearer {access_token}
POST /auth/refresh
Content-Type: application/json
{
"refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."
}Initiate GitHub OAuth flow.
Parameters:
redirect_uri(query): Optional redirect URI after authentication
Response:
{
"auth_url": "https://github.com/login/oauth/authorize?client_id=...",
"state": "random_state_string"
}Handle GitHub OAuth callback.
Parameters:
code(query): Authorization code from GitHubstate(query): State parameter for CSRF protection
Response:
{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"token_type": "bearer",
"expires_in": 3600,
"user": {
"id": 123,
"login": "username",
"name": "Full Name",
"email": "user@example.com",
"avatar_url": "https://avatars.githubusercontent.com/u/123"
}
}Refresh access token.
Request Body:
{
"refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."
}Response:
{
"access_token": "new_access_token",
"token_type": "bearer",
"expires_in": 3600
}Logout and invalidate tokens.
Headers:
Authorization: Bearer {access_token}
Response:
{
"message": "Successfully logged out"
}Get current user profile.
Headers:
Authorization: Bearer {access_token}
Response:
{
"id": 123,
"login": "username",
"name": "Full Name",
"email": "user@example.com",
"avatar_url": "https://avatars.githubusercontent.com/u/123",
"created_at": "2023-01-01T00:00:00Z",
"updated_at": "2023-01-01T00:00:00Z",
"permissions": ["read", "write", "admin"]
}Update current user profile.
Headers:
Authorization: Bearer {access_token}
Request Body:
{
"name": "Updated Name",
"email": "updated@example.com"
}Response:
{
"id": 123,
"login": "username",
"name": "Updated Name",
"email": "updated@example.com",
"avatar_url": "https://avatars.githubusercontent.com/u/123",
"updated_at": "2023-01-01T00:00:00Z"
}Get application metrics.
Headers:
Authorization: Bearer {access_token}
Parameters:
start_time(query): Start time in ISO formatend_time(query): End time in ISO formatmetric_type(query): Type of metric (cpu, memory, requests, etc.)
Response:
{
"metrics": [
{
"name": "cpu_usage",
"value": 75.5,
"unit": "percent",
"timestamp": "2023-01-01T00:00:00Z",
"tags": {
"host": "web-01",
"service": "frontend"
}
}
],
"total_count": 100,
"start_time": "2023-01-01T00:00:00Z",
"end_time": "2023-01-01T01:00:00Z"
}Submit custom metrics.
Headers:
Authorization: Bearer {access_token}
Content-Type: application/json
Request Body:
{
"metrics": [
{
"name": "custom_metric",
"value": 42.0,
"unit": "count",
"timestamp": "2023-01-01T00:00:00Z",
"tags": {
"component": "api",
"environment": "production"
}
}
]
}Response:
{
"message": "Metrics submitted successfully",
"accepted_count": 1
}Get Kubernetes cluster information.
Headers:
Authorization: Bearer {access_token}
Response:
{
"clusters": [
{
"name": "production-cluster",
"version": "v1.25.0",
"status": "healthy",
"nodes": 5,
"pods": 120,
"namespaces": 15,
"created_at": "2023-01-01T00:00:00Z"
}
]
}Get cluster nodes.
Headers:
Authorization: Bearer {access_token}
Path Parameters:
cluster_name: Name of the cluster
Response:
{
"nodes": [
{
"name": "node-1",
"status": "Ready",
"cpu_usage": 45.2,
"memory_usage": 67.8,
"pods": 25,
"created_at": "2023-01-01T00:00:00Z"
}
]
}Get cluster pods.
Headers:
Authorization: Bearer {access_token}
Path Parameters:
cluster_name: Name of the cluster
Query Parameters:
namespace(optional): Filter by namespacestatus(optional): Filter by pod status
Response:
{
"pods": [
{
"name": "app-pod-123",
"namespace": "default",
"status": "Running",
"ready": true,
"cpu_usage": 10.5,
"memory_usage": 128.0,
"created_at": "2023-01-01T00:00:00Z"
}
]
}Get CI/CD pipeline information.
Headers:
Authorization: Bearer {access_token}
Query Parameters:
repository(optional): Filter by repositorybranch(optional): Filter by branchstatus(optional): Filter by pipeline status
Response:
{
"pipelines": [
{
"id": "pipeline-123",
"repository": "org/repo",
"branch": "main",
"status": "success",
"duration": 300,
"started_at": "2023-01-01T00:00:00Z",
"finished_at": "2023-01-01T00:05:00Z",
"commit": {
"sha": "abc123",
"message": "Add new feature",
"author": "developer@example.com"
}
}
]
}Get specific pipeline details.
Headers:
Authorization: Bearer {access_token}
Path Parameters:
pipeline_id: ID of the pipeline
Response:
{
"id": "pipeline-123",
"repository": "org/repo",
"branch": "main",
"status": "success",
"duration": 300,
"started_at": "2023-01-01T00:00:00Z",
"finished_at": "2023-01-01T00:05:00Z",
"commit": {
"sha": "abc123",
"message": "Add new feature",
"author": "developer@example.com"
},
"stages": [
{
"name": "build",
"status": "success",
"duration": 120,
"started_at": "2023-01-01T00:00:00Z",
"finished_at": "2023-01-01T00:02:00Z"
},
{
"name": "test",
"status": "success",
"duration": 180,
"started_at": "2023-01-01T00:02:00Z",
"finished_at": "2023-01-01T00:05:00Z"
}
]
}Get Ansible playbook execution history.
Headers:
Authorization: Bearer {access_token}
Query Parameters:
playbook(optional): Filter by playbook namestatus(optional): Filter by execution status
Response:
{
"executions": [
{
"id": "exec-123",
"playbook": "deploy.yml",
"status": "success",
"duration": 240,
"started_at": "2023-01-01T00:00:00Z",
"finished_at": "2023-01-01T00:04:00Z",
"hosts": ["web-01", "web-02"],
"tasks_total": 10,
"tasks_successful": 10,
"tasks_failed": 0
}
]
}Execute Ansible playbook.
Headers:
Authorization: Bearer {access_token}
Content-Type: application/json
Path Parameters:
playbook_name: Name of the playbook to execute
Request Body:
{
"hosts": ["web-01", "web-02"],
"variables": {
"app_version": "1.2.3",
"environment": "production"
}
}Response:
{
"execution_id": "exec-456",
"status": "running",
"message": "Playbook execution started"
}Get active alerts.
Headers:
Authorization: Bearer {access_token}
Query Parameters:
severity(optional): Filter by alert severitystatus(optional): Filter by alert status
Response:
{
"alerts": [
{
"id": "alert-123",
"name": "High CPU Usage",
"severity": "critical",
"status": "active",
"description": "CPU usage above 90% for 5 minutes",
"created_at": "2023-01-01T00:00:00Z",
"updated_at": "2023-01-01T00:05:00Z",
"tags": {
"host": "web-01",
"service": "frontend"
}
}
]
}Acknowledge an alert.
Headers:
Authorization: Bearer {access_token}
Path Parameters:
alert_id: ID of the alert to acknowledge
Response:
{
"message": "Alert acknowledged successfully",
"acknowledged_at": "2023-01-01T00:00:00Z"
}Get API health status.
Response:
{
"status": "healthy",
"timestamp": "2023-01-01T00:00:00Z",
"version": "1.0.0",
"database": {
"status": "connected",
"response_time": 5.2
},
"external_services": {
"github": {
"status": "available",
"response_time": 120.5
},
"kubernetes": {
"status": "available",
"response_time": 45.8
}
}
}{
"id": "integer",
"login": "string",
"name": "string",
"email": "string",
"avatar_url": "string",
"created_at": "datetime",
"updated_at": "datetime",
"permissions": ["string"]
}{
"name": "string",
"value": "number",
"unit": "string",
"timestamp": "datetime",
"tags": {
"key": "string"
}
}{
"id": "string",
"repository": "string",
"branch": "string",
"status": "string",
"duration": "integer",
"started_at": "datetime",
"finished_at": "datetime",
"commit": {
"sha": "string",
"message": "string",
"author": "string"
},
"stages": [
{
"name": "string",
"status": "string",
"duration": "integer",
"started_at": "datetime",
"finished_at": "datetime"
}
]
}{
"id": "string",
"name": "string",
"severity": "string",
"status": "string",
"description": "string",
"created_at": "datetime",
"updated_at": "datetime",
"tags": {
"key": "string"
}
}The API uses standard HTTP status codes and returns detailed error information in JSON format.
{
"error": {
"code": "ERROR_CODE",
"message": "Human-readable error message",
"details": {
"field": "Additional error details"
}
},
"request_id": "unique_request_identifier"
}{
"error": {
"code": "INVALID_REQUEST",
"message": "The request is invalid",
"details": {
"field": "start_time",
"error": "Invalid datetime format"
}
},
"request_id": "req-123"
}{
"error": {
"code": "UNAUTHORIZED",
"message": "Authentication required",
"details": {
"reason": "Missing or invalid token"
}
},
"request_id": "req-124"
}{
"error": {
"code": "FORBIDDEN",
"message": "Insufficient permissions",
"details": {
"required_permission": "admin"
}
},
"request_id": "req-125"
}{
"error": {
"code": "NOT_FOUND",
"message": "Resource not found",
"details": {
"resource": "pipeline",
"id": "pipeline-123"
}
},
"request_id": "req-126"
}{
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Rate limit exceeded",
"details": {
"limit": 100,
"remaining": 0,
"reset_at": "2023-01-01T01:00:00Z"
}
},
"request_id": "req-127"
}{
"error": {
"code": "INTERNAL_ERROR",
"message": "An internal server error occurred",
"details": {
"error_id": "err-789"
}
},
"request_id": "req-128"
}The API implements rate limiting to ensure fair usage and system stability.
- Authenticated requests: 1000 requests per hour
- Unauthenticated requests: 100 requests per hour
- Webhook endpoints: 100 requests per hour
All API responses include rate limit information:
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1640995200
When rate limits are exceeded, the API returns a 429 status code:
{
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Rate limit exceeded",
"details": {
"limit": 1000,
"remaining": 0,
"reset_at": "2023-01-01T01:00:00Z"
}
},
"request_id": "req-127"
}The API supports webhooks for real-time event notifications.
pipeline.started: Pipeline execution startedpipeline.completed: Pipeline execution completedpipeline.failed: Pipeline execution failedalert.created: New alert createdalert.resolved: Alert resolveddeployment.started: Deployment starteddeployment.completed: Deployment completed
{
"event": "pipeline.completed",
"timestamp": "2023-01-01T00:00:00Z",
"data": {
"pipeline": {
"id": "pipeline-123",
"repository": "org/repo",
"branch": "main",
"status": "success",
"duration": 300
}
}
}Webhooks are signed using HMAC-SHA256. The signature is included in the X-Webhook-Signature header:
X-Webhook-Signature: sha256=5d41402abc4b2a76b9719d911017c592
Configure webhooks through the API:
POST /webhooks
Content-Type: application/json
Authorization: Bearer {access_token}
{
"url": "https://your-domain.com/webhook",
"events": ["pipeline.completed", "alert.created"],
"secret": "your-webhook-secret"
}- Python:
pip install opsight-python - Node.js:
npm install opsight-js - Go:
go get github.com/org/opsight-go
from opsight import Client
client = Client(
api_url="https://api.your-domain.com/api/v1",
access_token="your_access_token"
)
# Get user profile
user = client.users.get_me()
print(f"Hello, {user.name}!")
# Get metrics
metrics = client.metrics.list(
start_time="2023-01-01T00:00:00Z",
end_time="2023-01-01T01:00:00Z"
)import { OpsightClient } from 'opsight-js';
const client = new OpsightClient({
apiUrl: 'https://api.your-domain.com/api/v1',
accessToken: 'your_access_token'
});
// Get user profile
const user = await client.users.getMe();
console.log(`Hello, ${user.name}!`);
// Get pipelines
const pipelines = await client.pipelines.list({
repository: 'org/repo'
});// 1. Initiate OAuth flow
const authResponse = await fetch('/api/v1/auth/github');
const { auth_url, state } = await authResponse.json();
// 2. Redirect user to GitHub
window.location.href = auth_url;
// 3. Handle callback (on callback URL)
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
const state = urlParams.get('state');
const tokenResponse = await fetch(`/api/v1/auth/github/callback?code=${code}&state=${state}`);
const { access_token } = await tokenResponse.json();
// 4. Store token and make authenticated requests
localStorage.setItem('access_token', access_token);const response = await fetch('/api/v1/metrics?start_time=2023-01-01T00:00:00Z&end_time=2023-01-01T01:00:00Z', {
headers: {
'Authorization': `Bearer ${access_token}`,
'Content-Type': 'application/json'
}
});
const { metrics } = await response.json();
console.log('Metrics:', metrics);const metrics = [
{
name: 'api_requests',
value: 150,
unit: 'count',
timestamp: new Date().toISOString(),
tags: {
endpoint: '/api/users',
method: 'GET',
status: '200'
}
}
];
const response = await fetch('/api/v1/metrics', {
method: 'POST',
headers: {
'Authorization': `Bearer ${access_token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ metrics })
});
const result = await response.json();
console.log('Metrics submitted:', result);const express = require('express');
const crypto = require('crypto');
const app = express();
app.use(express.json());
app.post('/webhook', (req, res) => {
const signature = req.headers['x-webhook-signature'];
const payload = JSON.stringify(req.body);
// Verify signature
const expectedSignature = crypto
.createHmac('sha256', 'your-webhook-secret')
.update(payload)
.digest('hex');
if (signature !== `sha256=${expectedSignature}`) {
return res.status(401).send('Invalid signature');
}
// Process webhook event
const { event, data } = req.body;
console.log(`Received ${event} event:`, data);
res.status(200).send('OK');
});async function apiCall() {
try {
const response = await fetch('/api/v1/metrics', {
headers: {
'Authorization': `Bearer ${access_token}`
}
});
if (!response.ok) {
const error = await response.json();
throw new Error(`API Error: ${error.error.message}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error('API call failed:', error.message);
throw error;
}
}For more information and live examples, visit the interactive API documentation or check out the SDK documentation.