trmmcli

package module
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2022 License: PostgreSQL Imports: 10 Imported by: 0

README

trmm-cli

TRMM cli using the API. The API schema can be found at https://api.examlpe.com/api/schema/swagger-ui/#/.

Installation

trmm-cli requires Go 1.18. Using the Go toolchain, this command will download, compile and install trmm-cli in $HOME/go/bin (*nix) or %USERPROFILE%\go (Windows), depending on your $GOPATH.

go install gitlab.com/NiceGuyIT/trmm-cli/cmd/trmm-cli@latest

Usage

Most "listing" endpoints work. Listing endpoints output a flat list of information suitable for import into a spreadsheet. Some endpoints like /software, have a few top level fields and then a large list of items in other fields. This hierarchy is not suitable for CSV files.

Currently, trmm-cli outputs in CSV format which looses some detail when compared to a hierarchical format like JSON.

First, export your domain and API key.

cp .env-example .env
# Edit .env and add your domain and API key
export $(grep -vE "^(#.*|\s*)$" ../../.env)

# OR
export TRMM_API_DOMAIN="api.example.com"
export TRMM_API_KEY="ENTER_API_KEY_HERE"

Then run the command for the endpoint

trmm-cli checks > checks.csv
trmm-cli clients clients > clients-clients.csv
trmm-cli agents > agents.csv

And of course there is the help command.

Usage: trmm-cli <command>

trmm-cli is a command line interface to the TRMM API.

Flags:
  -h, --help                  Show context-sensitive help.
      --log-level="warn"      Log level
      --log-type="console"    Log type

accounts
  accounts users
    Work with the accounts users endpoint.

  accounts roles
    Work with the accounts roles endpoint.

  accounts api-keys
    Work with the accounts api-keys endpoint.

agents
  agents agents
    Work with the agents agents endpoint.

  agents history
    Work with the agents history endpoint.

  agents notes
    Work with the agents notes endpoint.

  agents versions
    Work with the agents versions endpoint.

alerts
  alerts templates
    Work with the alerts templates endpoint.

checks
  checks
    Work with the checks endpoint.

clients
  clients clients
    Work with the clients endpoint.

  clients sites
    Work with the clients sites endpoint.

core
  core code-sign
    Work with the core code-sign endpoint.

  core custom-fields
    Work with the core custom-fields endpoint.

  core dash-info
    Work with the core dash-info endpoint.

  core key-store
    Work with the core key-store endpoint.

  core settings
    Work with the core settings endpoint.

  core version
    Work with the core version endpoint.

  logs pending-actions
    Work with the logs pending-actions endpoint.

scripts
  scripts scripts
    Work with the scripts endpoint.

  scripts snippets
    Work with the scripts snippets endpoint.

services
  services
    Work with the services endpoint.

software
  software software
    Work with the software endpoint.

  software chocos
    Work with the software chocos endpoint.

tasks
  tasks
    Work with the tasks endpoint.

winupdate
  winupdate
    Work with the winupdate endpoint.

version
  version

license
  license

Run "trmm-cli <command> --help" for more information on a command.

trmm-cli: error: unexpected argument help
Notes

The /api/v3 APIs do not work as they need a different authentication method.

Development

This project follows the typical Go setup.

git clone https://gitlab.com/NiceGuyIT/trmm-cli
cd trmm-cli

The .env file is not used by trmm-cli directly. Instead, the export command will export the domain and API key to be used when running the program.

cp .env-example .env

## Testing
Running all tests.
Run in the root directory.

env TRMM_API_DOMAIN=api.domain.com TRMM_API_KEY=asdf123 go test -v ./...


Running single tests.

env TRMM_API_DOMAIN=api.domain.com TRMM_API_KEY=asdf123 go test -v -run TestGetAgentsClient


# Edit .env and add your domain and API key
export $(grep -vE "^(#.*|\s*)$" ../../.env)

Getting started

To make it easy for you to get started with GitLab, here's a list of recommended next steps.

Already a pro? Just edit this README.md and make it your own. Want to make it easy? Use the template at the bottom!

Add your files

cd existing_repo
git remote add origin https://gitlab.com/NiceGuyIT/trmm-cli.git
git branch -M main
git push -uf origin main

Integrate with your tools

Collaborate with your team

Test and Deploy

Use the built-in continuous integration in GitLab.


Editing this README

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to makeareadme.com for this template.

Suggestions for a good README

Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.

Name

Choose a self-explaining name for your project.

Description

Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.

Badges

On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.

Visuals

Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.

Installation

Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.

Usage

Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

Support

Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.

Roadmap

If you have ideas for releases in the future, it is a good idea to list them in the README.

Contributing

State if you are open to contributions and what your requirements are for accepting them.

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.

Authors and acknowledgment

Show your appreciation to those who have contributed to the project.

License

For open source projects, say how it is licensed.

Project status

If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

Documentation

Overview

Package trmmcli is the higher level interface to Tactical RMM.

Package trmmcli is the higher level interface to Tactical RMM.

Package trmmcli is the higher level interface to Tactical RMM.

Index

Constants

View Source
const (
	NAME         = "trmm-cli"
	URL          = "https://gitlab.com/NiceGuyIT/trmm-cli/"
	AUTHORS      = "David Randall"
	LICENSE      = "PostgreSQL"
	COPYRIGHT    = "(c) 2022 Nice Guy IT, LLC"
	ORGANIZATION = "Nice Guy IT, LLC"
	YEAR         = "2022"
)

Variables

View Source
var (
	// VERSION TODO: Add API version, GUI version, and possibly other versions.
	VERSION    = "unknown version"
	BUILD_TIME = "unknown time"
	BUILD_ENV  = "unknown env"
	GIT_COMMIT = "unknown git commit"
	GIT_TAG    = "unknown git tag"
	GIT_BRANCH = "unknown git branch"
)

External variables pulled in during the build process

Functions

func SetLogging

func SetLogging(l *LoggingConfig)

Types

type CLI

type CLI struct {

	// Accounts command is to work with TRMM accounts.
	Accounts struct {
		Users   struct{} `kong:"cmd='',group='accounts',help='Work with the accounts users endpoint.'"`
		Roles   struct{} `kong:"cmd='',group='accounts',help='Work with the accounts roles endpoint.'"`
		APIKeys struct{} `kong:"cmd='',group='accounts',help='Work with the accounts api-keys endpoint.'"`
	} `kong:"cmd='',group='accounts',help='Work with the accounts endpoint.'"`

	// Agents command is to work with TRMM agents.
	Agents struct {
		Agents   struct{} `kong:"cmd='',group='agents',help='Work with the agents agents endpoint.'"`
		History  struct{} `kong:"cmd='',group='agents',help='Work with the agents history endpoint.'"`
		Notes    struct{} `kong:"cmd='',group='agents',help='Work with the agents notes endpoint.'"`
		Versions struct{} `kong:"cmd='',group='agents',help='Work with the agents versions endpoint.'"`
	} `kong:"cmd='',group='agents',help='Work with the agents endpoint.'"`

	// Alerts command is to work with TRMM alerts.
	Alerts struct {
		Templates struct{} `kong:"cmd='',group='alerts',help='Work with the alerts templates endpoint.'"`
	} `kong:"cmd='',group='alerts',help='Work with the alerts endpoint.'"`

	// Checks command is to work with TRMM checks.
	Checks struct {
	} `kong:"cmd='',group='checks',help='Work with the checks endpoint.'"`

	// Clients command is to work with TRMM clients.
	Clients struct {
		Clients  struct{} `kong:"cmd='',group='clients',help='Work with the clients endpoint.'"`
		Sites    struct{} `kong:"cmd='',group='clients',help='Work with the clients sites endpoint.'"`
		Offboard struct {
			ClientParam string `arg:"" name:"client" help:"Specify the client."`
			Force       bool   `help:"Force offboard the client."`
		} `kong:"cmd='',group='clients',help='Offboard a client.'"`
	} `kong:"cmd='',group='clients',help='Work with the clients endpoint.'"`

	// Core command is to work with TRMM core.
	Core struct {
		CodeSign     struct{} `kong:"cmd='',group='core',help='Work with the core code-sign endpoint.'"`
		CustomFields struct{} `kong:"cmd='',group='core',help='Work with the core custom-fields endpoint.'"`
		DashInfo     struct{} `kong:"cmd='',group='core',help='Work with the core dash-info endpoint.'"`
		KeyStore     struct{} `kong:"cmd='',group='core',help='Work with the core key-store endpoint.'"`
		Settings     struct{} `kong:"cmd='',group='core',help='Work with the core settings endpoint.'"`
		Version      struct{} `kong:"cmd='',group='core',help='Work with the core version endpoint.'"`
	} `kong:"cmd='',group='core',help='Work with the core endpoint.'"`

	// Logs command is to work with TRMM logs.
	Logs struct {
		PendingActions struct{} `kong:"cmd='',group='core',help='Work with the logs pending-actions endpoint.'"`
	} `kong:"cmd='',group='logs',help='Work with the logs endpoint.'"`

	// Scripts command is to work with TRMM scripts.
	Scripts struct {
		Scripts  struct{} `kong:"cmd='',group='scripts',help='Work with the scripts endpoint.'"`
		Snippets struct{} `kong:"cmd='',group='scripts',help='Work with the scripts snippets endpoint.'"`
	} `kong:"cmd='',group='scripts',help='Work with the scripts endpoint.'"`

	// Services command is to work with TRMM services.
	Services struct {
	} `kong:"cmd='',group='services',help='Work with the services endpoint.'"`

	// Software command for working with TRMM software.
	Software struct {
		Software struct{} `kong:"cmd='',group='software',help='Work with the software endpoint.'"`
		Chocos   struct{} `kong:"cmd='',group='software',help='Work with the software chocos endpoint.'"`
	} `kong:"cmd='',group='software',help='Work with the software endpoint.'"`

	// Tasks command is to work with TRMM tasks.
	Tasks struct {
	} `kong:"cmd='',group='tasks',help='Work with the tasks endpoint.'"`

	// Winupdate command is to work with TRMM winupdate.
	Winupdate struct {
	} `kong:"cmd='',group='winupdate',help='Work with the winupdate endpoint.'"`

	/**
	 * Non-Tactical commands
	 */
	// Logging options
	Logging struct {
		// https://github.com/rs/zerolog#leveled-logging
		Level string `kong:"enum='debug,info,warn,error',default='warn',help='Log level'"`
		Type  string `kong:"enum='json,console',default='console',help='Log type'"`
	} `kong:"embed='',prefix='log-'"`

	// Version
	Version struct {
	} `kong:"cmd='',group='version',name='version'"`

	// License
	License struct {
	} `kong:"cmd='',group='license',name='license'"`
}

CLI contains the command line configuration

func NewCLI

func NewCLI() *CLI

NewCLI starts a new configuration.

func (*CLI) ParseCLI

func (cli *CLI) ParseCLI() *CLI

ParseCLI command line options

type LoggingConfig

type LoggingConfig struct {
	// https://github.com/rs/zerolog#leveled-logging
	Level string `enum:"debug,info,warn,error" default:"info"`
	Type  string `enum:"json,console" default:"console"`
}

type TacticalCLI

type TacticalCLI struct {
	// contains filtered or unexported fields
}

TacticalCLI is the main entry to the TRMM CLI.

func NewTacticalCLI

func NewTacticalCLI() *TacticalCLI

NewTacticalCLI starts a new Tactical CLI request.

func (*TacticalCLI) Error

func (t *TacticalCLI) Error() error

Errors returns the error if present, or nil otherwise.

func (*TacticalCLI) ErrorMessage

func (t *TacticalCLI) ErrorMessage() string

ErrorMessage returns the error message.

func (*TacticalCLI) HasErrors

func (t *TacticalCLI) HasErrors() bool

HasErrors returns true if errors are present.

func (*TacticalCLI) Run

func (t *TacticalCLI) Run() *TacticalCLI

Run will run the Tactical CLI request.

func (*TacticalCLI) SetAPIKey

func (t *TacticalCLI) SetAPIKey(key string) *TacticalCLI

SetAPIKey will set the API key for Tactical RMM.

func (*TacticalCLI) SetDomain

func (t *TacticalCLI) SetDomain(domain string) *TacticalCLI

SetDomain will set the API domain for Tactical RMM.

func (*TacticalCLI) SetTimeout

func (t *TacticalCLI) SetTimeout(seconds int) *TacticalCLI

SetTimeout will set the HTTP timeout.

type TacticalConfig

type TacticalConfig struct {
	// contains filtered or unexported fields
}

TacticalConfig is the configuration for Tactical RMM.

Directories

Path Synopsis
cmd
trmm-cli
Package main is for the trmm-cli binary.
Package main is for the trmm-cli binary.
Package trmm integrates with the Tactical RMM API.
Package trmm integrates with the Tactical RMM API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL