Skip to main content

Commands Endpoints

Execute and manage remote commands on servers.

List Commands

Get command history.

GET /api/v1/commands

Query Parameters

ParameterTypeDescription
server_idstringFilter by server UUID
statusstringFilter by status: pending, running, completed, failed, timeout
typestringFilter by command type
fromstringStart date (ISO 8601)
tostringEnd date (ISO 8601)
pageintegerPage number (default: 1)
limitintegerItems per page (default: 50, max: 100)

Response

Success (200):

{
"commands": [
{
"id": "cmd-abc123",
"type": "ban-ip",
"server": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"hostname": "web-server-01"
},
"params": {
"jail": "sshd",
"ip": "192.168.1.100"
},
"status": "completed",
"result": {
"success": true,
"output": "IP 192.168.1.100 banned"
},
"initiated_by": "admin",
"created_at": "2024-01-15T10:30:00Z",
"completed_at": "2024-01-15T10:30:05Z"
}
],
"total": 150,
"page": 1,
"limit": 50
}

Get Command

Get a specific command by ID.

GET /api/v1/commands/{commandId}

Path Parameters

ParameterTypeDescription
commandIdstringCommand ID

Response

Success (200):

{
"id": "cmd-abc123",
"type": "ban-ip",
"server": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"hostname": "web-server-01"
},
"params": {
"jail": "sshd",
"ip": "192.168.1.100"
},
"status": "completed",
"result": {
"success": true,
"output": "IP 192.168.1.100 banned",
"exit_code": 0
},
"initiated_by": "admin",
"created_at": "2024-01-15T10:30:00Z",
"started_at": "2024-01-15T10:30:02Z",
"completed_at": "2024-01-15T10:30:05Z"
}

Execute Command

Execute a command on a server.

POST /api/v1/servers/{serverId}/commands

Path Parameters

ParameterTypeDescription
serverIdstringServer UUID

Request Body

{
"type": "ban-ip",
"params": {
"jail": "sshd",
"ip": "192.168.1.100"
}
}

Available Command Types

TypeDescriptionRequired Params
ban-ipBan an IPjail, ip
unban-ipUnban an IPjail, ip
jail-statusGet jail statusjail
jail-enableEnable a jailjail
jail-disableDisable a jailjail
jail-reloadReload jail configjail
reload-allReload fail2ban-
service-restartRestart fail2ban-
deploy-templateDeploy templatetemplate_id, settings
remove-templateRemove templatetemplate_name

Response

Success (201):

{
"id": "cmd-abc123",
"type": "ban-ip",
"status": "pending",
"created_at": "2024-01-15T10:30:00Z"
}

Example

curl -X POST "https://bloqd.example.com/api/v1/servers/550e8400-e29b-41d4-a716-446655440000/commands" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "ban-ip",
"params": {
"jail": "sshd",
"ip": "192.168.1.100"
}
}'

Batch Execute

Execute the same command on multiple servers.

POST /api/v1/commands/batch

Request Body

{
"server_ids": [
"550e8400-e29b-41d4-a716-446655440000",
"550e8400-e29b-41d4-a716-446655440001"
],
"type": "reload-all"
}

Response

Success (201):

{
"commands": [
{
"id": "cmd-abc123",
"server_id": "550e8400-e29b-41d4-a716-446655440000",
"status": "pending"
},
{
"id": "cmd-abc124",
"server_id": "550e8400-e29b-41d4-a716-446655440001",
"status": "pending"
}
]
}

Cancel Command

Cancel a pending command.

DELETE /api/v1/commands/{commandId}

Path Parameters

ParameterTypeDescription
commandIdstringCommand ID

Response

Success (200):

{
"message": "Command cancelled"
}
note

Only pending commands can be cancelled. Running commands will continue to completion.


Retry Command

Retry a failed or timed-out command.

POST /api/v1/commands/{commandId}/retry

Path Parameters

ParameterTypeDescription
commandIdstringCommand ID

Response

Success (201):

{
"id": "cmd-abc125",
"type": "ban-ip",
"status": "pending",
"retry_of": "cmd-abc123",
"created_at": "2024-01-15T10:35:00Z"
}

Get Pending Commands

Get pending commands for a server (used by agent).

GET /api/v1/servers/{serverId}/commands/pending

Response

Success (200):

{
"commands": [
{
"id": "cmd-abc123",
"type": "ban-ip",
"params": {
"jail": "sshd",
"ip": "192.168.1.100"
}
}
]
}

Report Command Result

Report command execution result (used by agent).

POST /api/v1/commands/{commandId}/result

Path Parameters

ParameterTypeDescription
commandIdstringCommand ID

Request Body

{
"success": true,
"output": "IP 192.168.1.100 banned successfully",
"exit_code": 0
}

Response

Success (200):

{
"message": "Result recorded"
}

Command Statistics

Get command execution statistics.

GET /api/v1/commands/stats

Query Parameters

ParameterTypeDescription
server_idstringFilter by server UUID
periodstringday, week, month

Response

Success (200):

{
"total": 1523,
"by_status": {
"completed": 1450,
"failed": 50,
"timeout": 23
},
"by_type": {
"ban-ip": 800,
"unban-ip": 300,
"reload-all": 200,
"deploy-template": 150,
"other": 73
},
"avg_execution_time_ms": 2500,
"success_rate": 95.2
}