• Beta
Integrate any Tool with Agents
  • 18 Nov 2020
  • 4 Minutes To Read
  • Share
  • Dark
    Light

Integrate any Tool with Agents

  • Share
  • Dark
    Light

Integrate your Pipelines with CTO.ai Workflow Agents

"We can get Events from ANY Pipeline or Workflow"

This document is for teams who:

  • Don't have Circle CI or GitHub and want to start collecting Events from existing CI/CD Systems
    -OR-
  • Want to get additional metrics from their pipelines/ workflows and have already setup at GitHub or CircleCI Agent

Check out our Insights Overview for a Deep Dive into how our Agents gets Events.

Ready to implement Workflow Metrics Beta?
1. SignUp for the Platform
2. Install your Agent from the list below
3. Talk to a Workflow Expert at anytime for help or how to plugin our Agent API

Acquire API Token

  1. When you Contact us to join the Beta test, we will set up your account and give you two credentials: ClientID and ClientSecret. Store these somewhere safe.
  2. Install the CTO.ai CLI as usual, by following the CLI installation instructions in the Install the CLI guide.
  3. Sign up or Sign in to your CTO.ai account.
ops account:signup

or

ops account:signin
  1. Run the generate token command to create an API token. You will be prompted for your ClientID, ClientSecret, and your account password.
    Note: Get this from one of our Support Engineers during Beta
ops generate:token
  1. Copy the generated token and store it somewhere safe. This token can be used to access the HTTP API directly, or can be provided to existing integrations (like the CTO.ai GitHub Action) to allow them to access the API on your behalf.

Acquire Team UUID

During Beta, the Events API requires you to supply the team UUID you wish to send events to. This will explain how to acquire this UUID for one of your teams.

  1. If you haven't already you'll need to install the CTO.ai CLI as usual, by following the CLI installation instructions in the Install the CLI guide. If you just got the token above skip to Step 3.
  2. Sign up or Sign in to your CTO.ai account if you're not already
ops account:signup

or

ops account:signin
  1. Switch to the team whose Team UUID you wish to access, if you're already on the team you want to use skip to step 4.
ops team:switch
  1. Get the Team UUID and validate the team
ops team:info

This will print out all the information about your current team, including the UUID.

Send HTTP API Request

The Events API endpoint is located at https://api.cto.sh/api/v1/events during Beta.
For a deailed explanation of the type of Events you can send and track check out our Delivery Events and Lifecycle Events sections.

TOKEN=your-token-abcdefg

curl --location --request POST "https://api.cto.sh/api/v1/events" \
  --header "`echo 'Authorization: Bearer' ${TOKEN}`"\
  --header 'Content-Type: application/json'\
  --data '{
      "status":"Change",
      "stage":"Initiated",
      "stage_ref":"stage1",
      "pipeline_id":"pipelineid1",
      "change_id":"changeid1",
      "team_id":"your-team-id-aaaa-bbbb-cccccccc"
    }' 

Other API features.

The Events API implements the standard query API features supported by the FeathersJS framework.

This includes, among other features:

  • Pagination ($limit and $skip)
  • Determining which fields are returned ($select)
  • Equality and inequality operators ($lt, $lte, $gt, $gte, $ne)

Track Events from Pipelines, Services, & Commands with The Ops SDK

Already started setting up CTO.ai based Workflows, any of these events can be sent from an Pipeline, Service, or Command using the sdk.track() function. This lets you use Slack as a control plane on top of your existing tools, while still tracking key lifecycle events in your workflow.
Below you'll find how to use our sdk.track() command in the following languages:

  • NodeJS
  • Bash
  • Python
  • Go

Using the NodeJS SDK

const { sdk } = require('@cto.ai/sdk')
async function main() {

  const event = {
    "stage": "Deployment",
    "status": "Succeeded",
    "stage_ref": "956b425e5bee",
    "pipeline_id": "web",
    "custom": {
      "CustomFieldABC":"CustomValueXYZ"
    }
  }
  
  sdk.track([], event)
}
main()

The first argument to sdk.track is a field that isn't used by the metrics dashboard, so it has been left blank in this example.

Using the Bash SDK

#!/bin/bash

sdk track "" \
  stage:Deployment \
  status:Succeeded \
  pipeline_id:web \
  stage_ref:956b425e5bee \
  custom_field_ABC:custom_value_XYZ

The "" argument (the first argument) is a metadata field that isn't used by the metrics dashboard, but is required by the sdk.track function, so it has been left blank in this example.

Using the Python SDK

from cto_ai import sdk

def main():
    event = {
        "stage": "Deployment",
        "status": "Succeeded",
        "stage_ref": "956b425e5bee",
        "pipeline_id": "web"
    }
    sdk.track([], "", event)

if __name__ == "__main__":
    main()

The first two arguments for sdk.track are left blank in this example because they are not used by the metrics dashboard, but they are required by the sdk.track function.

Using the Go SDK

package main

import (
	ctoai "github.com/cto-ai/sdk-go"
)

func main() {
	client := ctoai.NewClient()
	event := map[string]interface{}{
		"stage":       "Deployment",
		"status":      "Succeeded",
		"stage_ref":   "956b425e5bee",
		"pipeline_id": "web",
	}
	err := client.Sdk.Track([]string{}, "", event)
	if err != nil {
		panic(err)
	}
}

The first two arguments to client.Sdk.Track are left blank because they required by Track, but are not used by the Insights Dashboard.

Summary

Thanks for participating in the Workflow Events Beta! If anything is still unclear, please contact us. We are eager to hear your questions, feedback, and comments, so that we can make our platform better!

Was This Article Helpful?