openapi: 3.0.0
servers:
    - description: Controller URL
      url: https://localhost:8080/controller/alerting/rest/v1/applications/{application-id}/
info:
    description: |
        Action apis.
        [Details at Appdynamics documentation](https://docs.appdynamics.com/display/PRO45/AppDynamics+APIs)
    version: "1.0.0"
    title: Appdynamics Action Operations
    termsOfService: 'https://www.appdynamics.com/terms/'
    license:
        name: Apache 2.0
        url: 'http://www.apache.org/licenses/LICENSE-2.0.html'

tags:
    - name: actions
      description: Manage application actions.
      externalDocs:
          description: Find out more
          url: 'https://www.appdynamics.com'

paths:
    '/actions':
        parameters:
            - $ref: '#/components/parameters/applicationId'
        post:
            description: |
                Create a new action from the provided json payload.
            tags:
                - actions
            operationId: createAction
            responses:
                '201':
                    description: Created successfully
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/Action'
                    links:
                        CreatedUserid:
                            operationId: getAction
                            parameters:
                                action-id: '$response.body#/id'
                            description:
                                The `id` value returned in the response can be used as `action-id` parameter in `GET /actions/{action-id}`
                '400':
                    $ref: '#/components/responses/BadRequest'
                '401':
                    $ref: '#/components/responses/Unauthorized'
                '403':
                    $ref: '#/components/responses/Forbidden'
                '409':
                    $ref: '#/components/responses/Conflict'
            requestBody:
                $ref: '#/components/requestBodies/Action'

        get:
            tags:
                - actions
            description: |
                Returns list of all Actions that belong to the application. Only Action names and id are returned. For getting complete details for a Action, see `GET /actions/{action-id}`
            operationId: getActionSummaries
            responses:
                '200':
                    description: Fetched successfully
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/ActionSummaryArray'
                '400':
                    $ref: '#/components/responses/BadRequest'
                '401':
                    $ref: '#/components/responses/Unauthorized'
                '403':
                    $ref: '#/components/responses/Forbidden'
                '404':
                    $ref: '#/components/responses/Conflict'
    '/actions/{action-id}':
        parameters:
            - $ref: '#/components/parameters/applicationId'
            - $ref: '#/components/parameters/actionId'
        get:
            tags:
                - actions
            summary: "Returns json representation of action for the given action id."
            description: |
                Returns json representation of action for the given action id. Valid existing action id should be provided.
            operationId: getAction
            responses:
                '200':
                    description: Fetched successfully
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/Action'
                '400':
                    $ref: '#/components/responses/BadRequest'
                '401':
                    $ref: '#/components/responses/Unauthorized'
                '403':
                    $ref: '#/components/responses/Forbidden'
                '404':
                    $ref: '#/components/responses/Conflict'
        put:
            tags:
                - action
            summary: "Update an existing action with the given action id"
            description: |
                Complete json payload for the action should be provided as input. User can first make  `GET /actions/{action-id}` to get the json payload and update required fields and send modified payload as part of this `PUT` request.
            operationId: updateAction
            responses:
                '200':
                    description: Updated successfully
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/Action'
                '400':
                    $ref: '#/components/responses/BadRequest'
                '401':
                    $ref: '#/components/responses/Unauthorized'
                '403':
                    $ref: '#/components/responses/Forbidden'
                '404':
                    $ref: '#/components/responses/Conflict'
            requestBody:
                $ref: '#/components/requestBodies/Action'
        delete:
            tags:
                - actions
            summary: "Delete an existing action with the given action id."
            description: Valid existing action id should be provided.
            operationId: deleteAction
            responses:
                '200':
                    description: Deleted successfully
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/StringIntegerPair'
                '400':
                    $ref: '#/components/responses/BadRequest'
                '401':
                    $ref: '#/components/responses/Unauthorized'
                '403':
                    $ref: '#/components/responses/Forbidden'
                '404':
                    $ref: '#/components/responses/Conflict'

externalDocs:
    description: Find out more about Swagger
    url: 'http://swagger.io'
components:
    schemas:
        Action:
            description: 'Action definition'
            type: object
            properties:
                id:
                    description: 'User does not need to provide this while creating a new action. Will be generated by system and returned in response.'
                    type: integer
                    format: int64
                    readOnly: true
                actionType:
                    $ref: '#/components/schemas/ActionTypeEnum'
            discriminator:
                propertyName: actionType
                mapping:
                    SMS: '#/components/schemas/SmsAction'
                    EMAIL: '#/components/schemas/EmailAction'
                    CUSTOM_EMAIL: '#/components/schemas/CustomEmailAction'
                    THREAD_DUMP: '#/components/schemas/ThreadDumpAction'
                    HTTP_REQUEST: '#/components/schemas/HttpRequestAction'
                    CUSTOM: '#/components/schemas/CustomAction'
                    RUN_SCRIPT_ON_NODES: '#/components/schemas/ScriptAction'
                    DIAGNOSE_BUSINESS_TRANSACTIONS: '#/components/schemas/DiagnosticAction'
                    CREATE_UPDATE_JIRA: '#/components/schemas/JiraAction'
            required:
                - actionType

        SmsAction:
            description: 'actionType: SMS, Email/SMS configuration should be already present.'
            allOf:
                - $ref: '#/components/schemas/Action'
                - type: object
                  properties:
                      phoneNumber:
                          type: string
                          pattern: ^\d{10,}$
                          example: "9876543210"
                  required:
                      - phoneNumber

        EmailAction:
            description: 'actionType: EMAIL'
            allOf:
                - $ref: '#/components/schemas/Action'
                - type: object
                  properties:
                      emails:
                          $ref: '#/components/schemas/EmailArray'
                  required:
                      - emails


        CustomEmailAction:
            description: 'actionType: CUSTOM_EMAIL, corresponds to ticked `Use Template` field in UI. One of the to, cc, bcc fields must be present'
            allOf:
                - $ref: '#/components/schemas/Action'
                - type: object
                  properties:
                      name:
                          $ref: '#/components/schemas/ActionName'
                      emailTemplateName:
                          description: 'Provided template name should be one of the already present email templates.'
                          minLength: 1
                          type: string
                      to:
                          $ref: '#/components/schemas/EmailArray'
                      cc:
                          $ref: '#/components/schemas/EmailArray'
                      bcc:
                          $ref: '#/components/schemas/EmailArray'
                      customTemplateVariables:
                          type: array
                          items:
                              $ref: '#/components/schemas/KeyValuePair'
                  required:
                      - name
                      - emailTemplateName
                      - to
                      - cc
                      - bcc

        ThreadDumpAction:
            description: 'actionType: THREAD_DUMP'
            allOf:
                - $ref: '#/components/schemas/Action'
                - type: object
                  properties:
                      name:
                          $ref: '#/components/schemas/ActionName'
                      numberOfThreadDumps:
                          description: 'Number of thread dumps to collect.'
                          type: integer
                          example: 4
                          minimum: 1
                          maximum: 50
                      intervalInMs:
                          description: 'Duration between individual thread dumps in milliseconds.'
                          type: integer
                          example: 1024
                          minimum: 500
                      approvalBeforeExecution:
                          $ref: '#/components/schemas/ApprovalBeforeExecution'
                  required:
                      - name
                      - numberOfThreadDumps
                      - intervalInMs
                      - approvalBeforeExecution

        HttpRequestAction:
            description: 'actionType: HTTP_REQUEST'
            allOf:
                - $ref: '#/components/schemas/Action'
                - type: object
                  properties:
                      name:
                          $ref: '#/components/schemas/ActionName'
                      httpRequestTemplateName:
                          description: 'Name of the HTTP request template which is already existing'
                          type: string
                          minLength: 1
                          example: "send notification on slack"
                      customTemplateVariables:
                          type: array
                          items:
                              $ref: '#/components/schemas/KeyValuePair'
                  required:
                      - name
                      - httpRequestTemplateName

        CustomAction:
            description: 'actionType: CUSTOM'
            allOf:
                - $ref: '#/components/schemas/Action'
                - type: object
                  properties:
                      name:
                          $ref: '#/components/schemas/ActionName'
                      customActionName:
                          type: string
                          minLength: 1
                          example: "script 1"
                  required:
                      - name
                      - customActionName

        ScriptAction:
            description: 'actionType: RUN_SCRIPT_ON_NODES'
            allOf:
                - $ref: '#/components/schemas/Action'
                - type: object
                  properties:
                      name:
                          $ref: '#/components/schemas/ActionName'
                      scriptPath:
                          description: 'Relative path to the script. Enter the part after `${machine.agent.directory}/local-scripts/`'
                          type: string
                          minLength: 1
                          example: "printErrors/script"
                      logFilesPath:
                          description: 'Absolute path to the log file(s)'
                          type: array
                          items:
                              type: string
                      scriptTimeout:
                          description: 'Script Timeout in minutes, after which the script execution will be halted'
                          type: integer
                          minimum: 1
                          maximum: 1440
                      approvalBeforeExecution:
                          $ref: '#/components/schemas/ApprovalBeforeExecution'
                  required:
                      - name
                      - scriptPath
                      - scriptTimeout
                      - approvalBeforeExecution

        DiagnosticAction:
            description: 'actionType: DIAGNOSING_BUSINESS_TRANSACTION'
            allOf:
                - $ref: '#/components/schemas/Action'
                - type: object
                  properties:
                      name:
                          $ref: '#/components/schemas/ActionName'
                      duration:
                          description: 'duration in minutes'
                          type: integer
                          minimum: 1
                          maximum: 10
                      snapshotRate:
                          description: 'Snapshots per minute'
                          type: integer
                          minimum: 1
                          maximum: 10
                      businessTransactions:
                          $ref: '#/components/schemas/BusinessTransactions'
                  required:
                      - name
                      - duration
                      - snapshotRate
                      - businessTransactions

        JiraAction:
            description: 'actionType: CREATE_UPDATE_JIRA'
            allOf:
                - $ref: '#/components/schemas/Action'
                - type: object
                  properties:
                      name:
                          $ref: '#/components/schemas/ActionName'
                      jiraActionDetails:
                          $ref: '#/components/schemas/JiraActionDetails'
                  required:
                      - jiraActionDetails
                      - name

        JiraActionDetails:
            description: 'Details of the ticket for the Jira action'
            type: object
            properties:
                jiraActionType:
                    $ref: '#/components/schemas/JiraActionTypeEnum'
            required:
                - jiraActionType
            discriminator:
                propertyName: jiraActionType
                mapping:
                    CREATE_JIRA: '#/components/schemas/JiraCreateAction'
                    UPDATE_JIRA: '#/components/schemas/JiraUpdateAction'

        JiraCreateAction:
            description: 'jiraActionType: CREATE_JIRA'
            allOf:
                - $ref: '#/components/schemas/JiraActionDetails'
                - type: object
                  properties:
                      assignee:
                          type: string
                          example: "admin"
                          minLength: 1
                      project:
                          type: string
                          minLength: 1
                      priority:
                          type: string
                          minLength: 1
                          example: "highest"
                      issueType:
                          type: string
                          minLength: 1
                          example: "new feature"
                  required:
                      - assignee
                      - project
                      - priority
                      - issueType

        JiraUpdateAction:
            description: 'jiraActionType: UPDATE_JIRA'
            allOf:
                - $ref: '#/components/schemas/JiraActionDetails'
                - type: object
                  properties:
                      changePriorityTo:
                          type: string
                          minLength: 1
                          example: "low"
                  required:
                      - changePriorityTo

        ActionName:
            description: 'Name of the action'
            type: string
            minLength: 1
            example: "Do Something"

        ApprovalBeforeExecution:
            description: 'Send email before execution'
            type: object
            properties:
                requireApproval:
                    type: boolean
                    example: true
                approverEmail:
                    $ref: '#/components/schemas/Email'

        BusinessTransactions:
            description: 'Run diagnostic session on these Business Transactions'
            type: object
            properties:
                businessTransactionScope:
                    $ref: '#/components/schemas/BusinessTransactionScopeEnum'
            discriminator:
                propertyName: businessTransactionScope
                mapping:
                    ALL_AFFECTED_BUSINESS_TRANSACTIONS: '#/components/schemas/AllAffectedBusinessTransactions'
                    SPECIFIC_BUSINESS_TRANSACTIONS: '#/components/schemas/SpecificBusinessTransactions'

        AllAffectedBusinessTransactions:
            description: 'businessTransactionScope: ALL_AFFECTED_BUSINESS_TRANSACTIONS'
            allOf:
                - $ref: '#/components/schemas/BusinessTransactions'
                - type: object

        SpecificBusinessTransactions:
            description: 'businessTransactionScope: SPECIFIC_BUSINESS_TRANSACTION'
            allOf:
                - $ref: '#/components/schemas/BusinessTransactions'
                - type: object
                  properties:
                      businessTransactionNames:
                          type: array
                          items:
                              type: string
                          minItems: 1
                          example: ["/get/someList", "/delete/someItem"]
                  required:
                      - businessTransactionNames

        EmailArray:
            type: array
            items:
                $ref: '#/components/schemas/Email'
            example: ["some.one@appdy.com", "some.two@appdy.com"]

        KeyValuePair:
            type: object
            properties:
                key:
                    type: string
                    example: "key1"
                value:
                    type: string
                    example: "value1"
            required:
                - key
                - value

        Email:
            type: string
            pattern: ^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$
            example: "some.one@appdy.com"

        ActionSummaryArray:
            type: array
            items:
                $ref: '#/components/schemas/ActionSummary'

        ActionSummary:
            description: "Summary for an Action"
            type: object
            properties:
                id:
                    type: integer
                    format: int64
                name:
                    $ref: '#/components/schemas/ActionName'
                actionType:
                    $ref: '#/components/schemas/ActionTypeEnum'

        StringIntegerPair:
            type: object
            properties:
                id:
                    type: integer
                    format: int64
                    example: 123
                name:
                    type: string
                    minLength: 1
                    example: "some string"
            required:
                - id
                - value

        JiraActionTypeEnum:
            type: string
            enum:
                - CREATE_JIRA
                - UPDATE_JIRA

        BusinessTransactionScopeEnum:
            type: string
            enum:
                - ALL_AFFECTED_BUSINESS_TRANSACTIONS
                - SPECIFIC_BUSINESS_TRANSACTIONS

        ActionTypeEnum:
            type: string
            enum:
                - SMS
                - EMAIL
                - CUSTOM_EMAIL
                - THREAD_DUMP
                - HTTP_REQUEST
                - CUSTOM
                - RUN_SCRIPT_ON_NODES
                - DIAGNOSE_BUSINESS_TRANSACTIONS
                - CREATE_UPDATE_JIRA
        ErrorResponse:
            type: object
            properties:
                statusCode:
                    type: integer
                    example: 404
                message:
                    type: string
                    example: "Action with given Id not found."

    parameters:
        applicationId:
            in: path
            name: application-id
            required: true
            schema:
                type: integer
                format: int64
                example: 10
        actionId:
            in: path
            name: action-id
            description: Id of the action for which the operation is to be done
            required: true
            schema:
                type: integer
                format: int64
                example: 24
    requestBodies:
        Action:
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/Action'
    responses:
        NotFound:
            description: The specified resource was not found
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ErrorResponse'
        Unauthorized:
            description: Unauthorized
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ErrorResponse'
        BadRequest:
            description: Bad Request
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ErrorResponse'
        Forbidden:
            description: Forbidden
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ErrorResponse'
        Conflict:
            description: Already exists
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ErrorResponse'
