Scripting and CI/CD
The Status200 CLI is designed for automation. It supports environment-variable-based authentication, JSON output for programmatic parsing, and appropriate exit codes for pipeline integration.
Environment Variables
Set these environment variables to authenticate without saved contexts:
export S200_API_KEY=sk-your-api-key
export S200_URL=https://status200.ruThese take precedence over saved contexts but are overridden by CLI flags.
Exit Codes
| Code | Meaning |
|---|---|
0 | Success |
1 | General error |
2 | Authentication error (missing or invalid credentials) |
3 | Not found (404) |
Use exit codes in scripts to handle errors:
if ! status200 monitor list > /dev/null 2>&1; then
echo "Failed to list monitors"
exit 1
fiJSON Processing with jq
Use -o json to produce machine-readable output:
# Extract all incident titles
status200 incident list -o json | jq '.[].title'
# Get the ID of a newly created monitor
NEW_ID=$(status200 monitor create --data '{"name":"API Health"}' -o json | jq -r '._id')
echo "Created monitor: $NEW_ID"
# Count incidents by severity
status200 incident count --query '{"incidentSeverityId":"<severity-id>"}'Creating Resources from Files
Use --file to create resources from JSON files, useful for version-controlled infrastructure:
# monitor.json
# {
# "name": "API Health Check",
# "projectId": "your-project-id"
# }
status200 monitor create --file monitor.jsonBatch Operations
Process multiple resources in a loop:
# Create multiple monitors from a JSON array file
cat monitors.json | jq -r '.[] | @json' | while read monitor; do
status200 monitor create --data "$monitor"
doneCI/CD Pipeline Examples
GitHub Actions
name: Check Active Incidents
on:
schedule:
- cron: '*/5 * * * *'
jobs:
health-check:
runs-on: ubuntu-latest
steps:
- name: Install Status200 CLI
run: npm install -g @status200/cli
- name: Check for active incidents
env:
S200_API_KEY: ${{ secrets.S200_API_KEY }}
S200_URL: https://status200.ru
run: |
INCIDENT_COUNT=$(status200 incident count)
if [ "$INCIDENT_COUNT" -gt 0 ]; then
echo "WARNING: $INCIDENT_COUNT incidents found"
exit 1
fiGeneric CI/CD Script
#!/bin/bash
set -e
export S200_API_KEY="$CI_S200_API_KEY"
export S200_URL="$CI_S200_URL"
# Create a deployment incident and capture the ID
# Note: currentIncidentStateId and incidentSeverityId must reference existing state/severity IDs in your project
INCIDENT_ID=$(status200 incident create --data '{
"title": "Deployment Started",
"currentIncidentStateId": "'"$INVESTIGATING_STATE_ID"'",
"incidentSeverityId": "'"$SEVERITY_ID"'",
"declaredAt": "'"$(date -u +%Y-%m-%dT%H:%M:%SZ)"'"
}' -o json | jq -r '._id')
# Run deployment steps here...
# Resolve the incident after successful deployment
status200 incident update "$INCIDENT_ID" --data '{"currentIncidentStateId":"'"$RESOLVED_STATE_ID"'"}'Docker
FROM node:20-slim
RUN npm install -g @status200/cli
ENV S200_API_KEY=""
ENV S200_URL=""
ENTRYPOINT ["status200"]docker run --rm \
-e S200_API_KEY=sk-abc123 \
-e S200_URL=https://status200.ru \
status200-cli incident listUsing a Specific Context in Scripts
If you have multiple contexts saved, target a specific one:
status200 --context production incident list
status200 --context staging monitor count