> ## Documentation Index
> Fetch the complete documentation index at: https://chatcli.edilsonfreitas.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Criar Runbook

> Cria um novo runbook de remediação

<ParamField body="name" type="string" required>
  Nome único do runbook (slug, ex: `runbook-disk-cleanup`)
</ParamField>

<ParamField body="category" type="string" required>
  Categoria: `oomkill`, `crashloop`, `latency`, `scaling`, `disk`, `network`, `custom`
</ParamField>

<ParamField body="description" type="string" required>
  Descrição do objetivo do runbook
</ParamField>

<ParamField body="severity" type="string[]" required>
  Lista de severidades alvo: `critical`, `high`, `medium`, `low`
</ParamField>

<ParamField body="automated" type="boolean" default="false">
  Se o runbook pode ser executado automaticamente
</ParamField>

<ParamField body="approvalRequired" type="boolean" default="true">
  Se requer aprovação antes da execução
</ParamField>

<ParamField body="rollbackOnFailure" type="boolean" default="true">
  Se deve executar rollback automático em caso de falha
</ParamField>

<ParamField body="steps" type="object[]" required>
  Lista de passos do runbook

  <Expandable title="Propriedades do step">
    <ParamField body="name" type="string" required>
      Identificador único do passo
    </ParamField>

    <ParamField body="description" type="string" required>
      Descrição do passo
    </ParamField>

    <ParamField body="action" type="string" required>
      Tipo de ação: `kubectl`, `script`, `ai-analyze`, `notification`, `wait`
    </ParamField>

    <ParamField body="command" type="string">
      Comando a ser executado (para ações `kubectl` e `script`)
    </ParamField>

    <ParamField body="timeout" type="string" default="60s">
      Timeout do passo no formato Go duration
    </ParamField>

    <ParamField body="continueOnFailure" type="boolean" default="false">
      Se deve continuar para o próximo passo mesmo em caso de falha
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="matchConditions" type="object">
  Condições para matching automático com incidentes

  <Expandable title="Propriedades">
    <ParamField body="resourceTypes" type="string[]">
      Tipos de recurso (ex: `["Deployment", "StatefulSet"]`)
    </ParamField>

    <ParamField body="descriptionPatterns" type="string[]">
      Padrões regex para match na descrição do incidente
    </ParamField>

    <ParamField body="namespaces" type="string[]">
      Namespaces onde o runbook se aplica
    </ParamField>
  </Expandable>
</ParamField>

<ResponseExample>
  ```json Response 201 theme={"system"}
  {
    "apiVersion": "v1",
    "kind": "Runbook",
    "metadata": {
      "name": "runbook-disk-cleanup",
      "createdAt": "2026-03-19T16:00:00Z",
      "createdBy": "admin@empresa.com"
    },
    "spec": {
      "category": "disk",
      "description": "Limpeza automática de disco quando uso excede 85%",
      "severity": ["medium", "high"],
      "automated": true,
      "approvalRequired": true,
      "rollbackOnFailure": false,
      "steps": [
        {
          "name": "check-disk-usage",
          "description": "Verificar uso atual do disco",
          "action": "kubectl",
          "command": "exec -it $POD -- df -h /data",
          "timeout": "30s"
        },
        {
          "name": "cleanup-temp-files",
          "description": "Remover arquivos temporarios com mais de 7 dias",
          "action": "script",
          "command": "find /data/tmp -mtime +7 -delete",
          "timeout": "120s"
        },
        {
          "name": "verify-disk-usage",
          "description": "Verificar uso de disco após limpeza",
          "action": "kubectl",
          "command": "exec -it $POD -- df -h /data",
          "timeout": "30s"
        }
      ],
      "matchConditions": {
        "resourceTypes": ["StatefulSet", "Deployment"],
        "descriptionPatterns": ["disk.*usage.*high", "filesystem.*full"],
        "namespaces": ["production", "staging"]
      }
    }
  }
  ```
</ResponseExample>


## OpenAPI

````yaml POST /runbooks
openapi: 3.1.0
info:
  title: ChatCLI AIOps Platform API
  description: >-
    REST API for the ChatCLI AIOps Platform — incidents, SLOs, runbooks,
    approvals, postmortems, analytics, audit, federation and health.


    The playground below uses **editable server variables** so you can point
    requests at your own self-hosted instance. Adjust `host`, `port` and
    `basePath` to match your deployment, then click **Try it**.
  version: 1.0.0
  contact:
    name: ChatCLI
    url: https://github.com/diillson/chatcli
  license:
    name: Apache-2.0
    identifier: Apache-2.0
servers:
  - url: http://{host}:{port}/{basePath}
    description: >-
      Self-hosted ChatCLI AIOps Platform — adjust host, port and basePath to
      match your deployment.
    variables:
      host:
        default: localhost
        description: >-
          Hostname or IP of your ChatCLI operator. For Kubernetes, use the
          Service DNS (e.g. chatcli-api.chatcli-system.svc) or your Ingress
          host.
      port:
        default: '8090'
        description: >-
          Port the API listens on. Default is 8090; configurable via Helm value
          `apiPort` or env var CHATCLI_API_PORT.
      basePath:
        default: api/v1
        description: >-
          API base path. Always `api/v1` unless you have a custom proxy rewrite
          in front of the operator.
security:
  - ApiKeyAuth: []
tags:
  - name: Incidents
    description: >-
      Incident lifecycle: list, fetch, acknowledge, resolve, snooze, timeline
      and remediation views.
  - name: Runbooks
    description: Remediation runbooks (list, create, update, delete).
  - name: SLOs
    description: Service Level Objectives and error budgets.
  - name: Approvals
    description: Approval workflow for risky remediations.
  - name: Postmortems
    description: Auto-generated postmortems with review, feedback and close.
  - name: Remediations
    description: Remediation plans and agentic execution history.
  - name: AI Insights
    description: AI root-cause analysis and recommendations per incident.
  - name: Analytics
    description: 'Operational analytics: MTTD, MTTR, trends, capacity, compliance.'
  - name: Audit
    description: Immutable audit log and exports.
  - name: Federation
    description: 'Multi-cluster federation: clusters, status and cross-cluster correlations.'
  - name: Health
    description: Liveness and readiness probes.
paths:
  /runbooks:
    post:
      tags:
        - Runbooks
      summary: Create Runbook
      description: Creates a new remediation runbook.
      operationId: createRunbook
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RunbookInput'
            example:
              name: runbook-disk-cleanup
              category: disk
              description: Automatic disk cleanup when usage exceeds 85%.
              severity:
                - medium
                - high
              automated: true
              approvalRequired: true
              rollbackOnFailure: false
              steps:
                - name: check-disk-usage
                  description: Check current disk usage
                  action: kubectl
                  command: exec -it $POD -- df -h /data
                  timeout: 30s
                - name: cleanup-temp-files
                  description: Remove temp files older than 7 days
                  action: script
                  command: find /data/tmp -mtime +7 -delete
                  timeout: 120s
              matchConditions:
                resourceTypes:
                  - StatefulSet
                  - Deployment
                descriptionPatterns:
                  - disk.*usage.*high
                  - filesystem.*full
                namespaces:
                  - production
                  - staging
      responses:
        '201':
          description: Runbook created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Runbook'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimited'
components:
  schemas:
    RunbookInput:
      type: object
      required:
        - name
        - category
        - description
        - severity
        - steps
      properties:
        name:
          type: string
          example: runbook-disk-cleanup
        category:
          type: string
          enum:
            - oomkill
            - crashloop
            - latency
            - scaling
            - disk
            - network
            - custom
        description:
          type: string
        severity:
          type: array
          items:
            type: string
            enum:
              - critical
              - high
              - medium
              - low
        automated:
          type: boolean
          default: false
        approvalRequired:
          type: boolean
          default: true
        rollbackOnFailure:
          type: boolean
          default: true
        steps:
          type: array
          items:
            $ref: '#/components/schemas/RunbookStep'
        matchConditions:
          $ref: '#/components/schemas/RunbookMatchConditions'
    Runbook:
      type: object
      properties:
        apiVersion:
          type: string
          example: v1
        kind:
          type: string
          example: Runbook
        metadata:
          type: object
          properties:
            name:
              type: string
            createdAt:
              type: string
              format: date-time
            createdBy:
              type: string
            updatedAt:
              type: string
              format: date-time
            updatedBy:
              type: string
            version:
              type: string
        spec:
          $ref: '#/components/schemas/RunbookInput'
    RunbookStep:
      type: object
      required:
        - name
        - description
        - action
      properties:
        name:
          type: string
        description:
          type: string
        action:
          type: string
          enum:
            - kubectl
            - script
            - ai-analyze
            - notification
            - wait
        command:
          type: string
        timeout:
          type: string
          default: 60s
        continueOnFailure:
          type: boolean
          default: false
    RunbookMatchConditions:
      type: object
      properties:
        resourceTypes:
          type: array
          items:
            type: string
        descriptionPatterns:
          type: array
          items:
            type: string
        namespaces:
          type: array
          items:
            type: string
    Error:
      type: object
      required:
        - apiVersion
        - kind
        - error
      properties:
        apiVersion:
          type: string
          example: v1
        kind:
          type: string
          example: Error
        error:
          oneOf:
            - type: object
              required:
                - code
                - message
              properties:
                code:
                  type: integer
                  example: 404
                message:
                  type: string
                  example: Resource not found
                details:
                  type: string
            - type: string
        code:
          type: integer
          description: Top-level code (only used by some endpoints).
          example: 400
  responses:
    BadRequest:
      description: Invalid request payload or parameters
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Missing or invalid API token
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    RateLimited:
      description: Rate limit exceeded for this token's role
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        Bearer token issued by the operator. Format: `Authorization: Bearer
        <token>`.

````