A brief introduction to the Opscompass CLI with examples
The Opscompass Command Line Interface (CLI) can be a powerful tool to use for automating tasks and extracting data from Opscompass. Below are some examples to help you get familiar with the CLI.
This KB article assumes you have already installed the Opscompass CLI and logged in as shown in this Knowledge Base article: https://kb.opscompass.com/knowledge/opscompass-command-line-interface
The first thing you will want to get is your company name to be used with subsequent commands:
opscompass accounts list-companies
Output:
[
{
"name": "Acme Inc",
"company": "acmeinc"
}
]
The output shows you full company name and also what is referred to as the the “Company ID”or “slug” in some commands. Here the “Company ID is “acmeinc”. The “Compnay ID” is also seen in the URL when you are signed into the Opscompass web interface:
Most customers will have only one company listed, unless you have subsidiaries that are running Opscompass separately, then you may have access to more than one company.
Now you can list the Cloud accounts that are connected to your Company account:
opscompass accounts list-accounts --company acmeinc
Sample output:
[
{
"name": "Acme Inc",
"id": 11294,
"cloudId": "Ht70sAbc23fdWAcUxIk0",
"cloudProvider": "mlss",
"removedFromCloudAt": null
},
{
"name": "acmeinc.onmicrosoft.com",
"id": 11247,
"cloudId": "2bef17fb-8b6e-4b32-862c-c36e77a7592c",
"cloudProvider": "microsoft365",
"removedFromCloudAt": null
},
{
"name": "acmeinc-sub-compartment-1",
"id": 12054,
"cloudId": "ocid1.compartment.oc1..aaaaaaaa23jk2kj389202kj3jjk2kj3j2koou322",
"cloudProvider": "oci",
"removedFromCloudAt": null
}
]
We can see that Acme Inc has one Microsoft 365 account, one Oracle Cloud Infrastructure (OCI) account, and a MLSS account, which is an Opscompass license monitoring account.
Examples
The general syntax of a CLI command is:
opscompass module action --parameter1 value --parameter2 value
Below we give several more examples of CLI commands for various modules. Most of these generate output to lengthy to be included here, but they will give you a quick introduction to some useful commands. We use the Company ID/slug “acmeinc” in all the examples. Substitute your own Company ID.
Defaults
The “defaults” module lets you store some common defaults so you don’t have to type them for every command.
To see your current defaults:
opscompass defaults list-defaults
Your defaults are all set to “none” to start with. To set your default company ID so you don’t have to put it on other commands, use your Company ID with “set-defaults”:
opscompass defaults set-defaults --company acmeinc
Now, for example, I can type “opscompass accounts list-accounts” without the “--company” parameter
For more information, see our “Defaults” KB article: https://kb.opscompass.com/knowledge/cli/defaults
Resources
The “resources” module allows you to list resources or retrieve information about specific resources.
To list all AWS EC2 Instances across all Cloud Accounts:
opscompass resources list --company acmeinc --resource-types AWS::EC2::Instance
To list all Azure SQL databases across all Cloud Accounts
opscompass resources list --company acmeinc --resource-types Microsoft.Sql/servers
To add a tag to a specific resource by ID:
opscompass resources add-tags --company acmeinc --id 12345 --tag "example-tag"
See our KB article about tagging multiple resources: https://kb.opscompass.com/knowledge/tagging-multiple-resources
To get information about a specific resource by ID:
opscompass resources get --company acmeinc --id 1234567
See our KB article showing how to find the ID for a resource: https://kb.opscompass.com/knowledge/cli/resource-company-id
See our Resources CLI KB Article for complete options and syntax: https://kb.opscompass.com/knowledge/cli/resources
Compliance
The “compliance” module allows you to list data or retrieve information about specific compliance checks.
To lists all exceptions and mitigations that have been set across all of your accounts:
opscompass compliance list-compliance-exceptions --company acmeinc
To lists all email addresses that appear in one or more breaches from Have I Been Pwned:
opscompass compliance list-breaches --company acmeinc
To list all compliance checks that have been disabled for a company
opscompass compliance list-disabled-checks --company acmeinc
See our Compliance CLI KB Article for complete options and syntax: https://kb.opscompass.com/knowledge/cli/compliance
License Manager
The Licensing module is used to list information for Oracle and SQL Server license monitoring configurations.
The most common command you will use is to list all of the monitoring configurations associated with the given company:
opscompass license-manager list-monitoring-configurations –company acmeinc
Other commands are beyond the scope of this CLI introduction. Please see our License Manager KB article for complete options and syntax: https://kb.opscompass.com/knowledge/cli/license-manager
