CLI

Interact with the OpsLevel API via our CLI to perform CRUD actions on services, teams, or checks and even submit deploy events.

With the OpsLevel CLI you can perform create, retrieve, update and delete actions on the data in OpsLevel.

Installation

brew install opslevel/tap/cli

You will also need an API Token to authorize the CLI to talk to your account.

The CLI is setup with a few top level “action” commands like get, list, create, delete which have subcommands for each “resource object” in OpsLevel. So most commands will take the format of opslevel <action> <resource> with a handful of exceptions.

The follow commands assume you have set your API Token as an environment variables export OPSLEVEL_API_TOKEN=XXX

It should also be noted that the CLI is currently in beta and does not yet support all resources and CRUD actions.

Retrieve Data

One of the main use-cases is to retrieve information about your account so you can use your service catalog to power other tools or processes.

First let’s start with listing the all tier and lifecycle objects in your account.

> opslevel list tier 
Alias   ID
tier_1  Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMTg
tier_2  Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMTUx
tier_3  Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMTUy
tier_4  Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMTUz
> opslevel list lifecycle
Alias                ID
pre-alpha            Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvMjI
alpha                Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvMjM
beta                 Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvMjU
generally_available  Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvMjY
end-of-life          Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvMjg

The output is the valid alias and id values for each tier and lifecycle that you may need to use in other commands.

You can copy one of the id’s and then pipe that into a get action to retrieve more details about the object.

Lets inspect one of the level objects. Use the corresponding list action then select the id for one of them and then feed it to a get action.

> opslevel list level         
Alias     ID                                
beginner  Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMTg   
bronze    Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMTUx  
silver    Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMTUy  
gold      Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMTUz  
> opslevel get level Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMTUy
{
  "Alias": "silver",
  "description": "Services in this level satisfy important and critical checks. This is considered healthy.",
  "id": "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMTUy",
  "Index": 2,
  "Name": "Silver"
}

With these two action together you can introspect all data about the objects in your account.

Create Data

To create simple objects in OpsLevel you can use the create action subcommands. Here is an example showing how to create a new rubric category which returns the id of the newly created resource.

> opslevel create category Chaos
Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvMTE4OA
> opslevel get category Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvMTE4OA
{
  "id": "Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvMTE4OA",
  "Name": "Chaos"
}

Most objects in OpsLevel will need more complex data structures when creating them and in these cases the data can be supplied by a yaml file. Here we create a deploy event using the CLI and an inline heredoc yaml definition.

cat << EOF | opslevel create deploy -i "https://app.opslevel.com/integrations/deploy/XXX" -f -
service: "foo"
description: "Hello World"
environment: "Production"
deploy-number: 10
deployer:
  name: john
  email: john@example.com
EOF

Delete data

The delete action allows you to pass the id of a resource to delete. Lets delete the category we just created.

> opslevel delete category Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvMTE4OA

This command paired with the list command and some xargs elbow grease creates a really easy way to cleanup a bunch of resources in OpsLevel.

Special commands

There are also some specialized commands included with the CLI that provide specific needs such as the export or completion commands. You can always introspect aspects about the CLI by adding the -h to print out help information or to see the available commands.

You can use the completion command to generate the autocompletion script for the specified shell to help with tab completion of the commands.

There is also an export terraform command which you can read more about in our Terraform docs

Deploys

You can also use the CLI to submit deploy events by using the following command.

opslevel create deploy -i "https://app.opslevel.com/integrations/deploy/xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx" -s "shopping_cart"

or with additional details - you can read more about the available fields in our deploy documentation

cat << EOF | opslevel create deploy -i "https://app.opslevel.com/integrations/deploy/xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx"
service: "shopping_cart"
description: "Deployed by CI Pipeline: Deploy #234"
environment: "Production"
deploy-number: 234
deploy-url: https://heroku.deploys.com
dedup-id: 9ae54794-dfc5-4ac8-b1b5-78789f20f3f8
deployer:
  id: 1a9f841f-9a3d-4423-a05a-7e9c31a02b16
  name: Michael Scott
  email: mscott@example.com
EOF

It should be noted that the CLI will autofill fields where it can such as deployed-at with the current time of when the command is run. Also all of the commit information will be scrapped from the git repository if run inside a directory with a git repository.