To get you started with managing configurations, this section will guide you through a simple example: creating a tagging rule with Dynatrace Configuration as Code via Monaco. You will learn how to create, deploy, and delete a configuration.
The latest version of Dynatrace Configuration as Code via Monaco (the Dynatrace Monaco CLI) installed (see Install Dynatrace Configuration as Code via Monaco) and available on your PATH
.
A Dynatrace environment and access to create environment tokens.
A Dynatrace token with at least the following permissions:
DataExport
)
ReadConfig
)
WriteConfig
)
settings.read
) (API v2)
settings.write
) (API v2)
To learn how to create tokens, see Create an API token.
If you're stuck at any point while following this guide, you can find a finished version of the project on GitHub.
You can create a tagging rule in an environment that will apply tags to hosts and services where a Dynatrace server is detected.
Run the following command to create a directory.
mkdir learn-monaco-auto-tag
Change to the new directory.
cd learn-monaco-auto-tag
Create a project directory to store the tagging configuration and change to it.
mkdir -p project-example/auto-tag
cd project-example/auto-tag
Create these two files:
touch auto-tag.json auto-tag.yaml
auto-tag.json
will store the JSON configuration of the tagging configuration.auto-tag.yaml
will be the YAML configuration file which will list the configurations to be deployed.Open the auto-tag.json
configuration file in your text editor, paste the configuration below and save the file.
The name used in this configuration is specified as a variable and its value will be given in the YAML configuration.
{"name": "{{ .name }}","rules": [{"enabled": true,"valueNormalization": "Leave text as-is","type": "ME","attributeRule": {"entityType": "PROCESS_GROUP","conditions": [{"key": "PROCESS_GROUP_PREDEFINED_METADATA","dynamicKey": "DYNATRACE_CLUSTER_ID","operator": "BEGINS_WITH","stringValue": "Server on Cluster","caseSensitive": true}],"pgToHostPropagation": true,"pgToServicePropagation": true}}]}
Open the auto-tag.yaml
configuration file in your text editor, paste the configuration below and save the file.
The name of the tag should be provided here. In this example: DTServer
.
configs:- id: application-taggingtype:settings:schema: builtin:tags.auto-taggingscope: environmentconfig:template: "auto-tag.json"name: "DTServer"
Change back to the configuration directory folder (learn-monaco-auto-tag
).
cd ../..
Create a deployment manifest file to instruct the Dynatrace Monaco CLI which project to deploy and where to deploy it.
touch manifest.yaml
Open the deployment manifest file (manifest.yaml
) in your text editor, paste in the configuration below, replace the URL value with your environment URL, and save the file.
manifestVersion: 1.0projects:- name: auto-tagpath: project-exampleenvironmentGroups:- name: developmentenvironments:- name: development-environmenturl:value: "https://<your-dynatrace-environment>.live.dynatrace.com"auth:token:name: "devToken"
Export your Dynatrace token to your environment. Make sure that your token has the permissions listed in the prerequisites.
export devToken=YourTokenValue
Run monaco deploy --dry-run
to ensure your configuration is syntactically valid and consistent.
monaco deploy --dry-run manifest.yaml
If the dry run was successful, the Dynatrace Monaco CLI will return the following message.
2023-08-24T10:21:07+02:00 info Loading manifest "{your full path to the file}/manifest.yaml". Restrictions: groups=[], environments=[]2023-08-24T10:21:07+02:00 info Loading 1 projects...2023-08-24T10:21:08+02:00 info Projects to be deployed (1):2023-08-24T10:21:08+02:00 info - auto-tag2023-08-24T10:21:08+02:00 info Environments to deploy to (1):2023-08-24T10:21:08+02:00 info - development-environment2023-08-24T10:21:08+02:00 info Validating configurations for environment `development-environment`...2023-08-24T10:21:08+02:00 info [coord=auto-tag:builtin:tags.auto-tagging:application-tagging] Deploying config2023-08-24T10:21:08+02:00 info Validation finished without errors
Now that you have created the configuration you need to deploy it to your Dynatrace environment. To do this, you use the monaco deploy
command.
To apply your configuration with the monaco deploy
command, provide the name of the deployment file as an argument.
monaco deploy manifest.yaml
If the deployment is successful, Dynatrace Configuration as Code CLI will return the following message:
2023-08-24T10:21:13+02:00 info Loading manifest "{your full path to the file}/manifest.yaml". Restrictions: groups=[], environments=[]2023-08-24T10:21:13+02:00 info Loading 1 projects...2023-08-24T10:21:13+02:00 info Projects to be deployed (1):2023-08-24T10:21:13+02:00 info - auto-tag2023-08-24T10:21:13+02:00 info Environments to deploy to (1):2023-08-24T10:21:13+02:00 info - development-environment2023-08-24T10:21:13+02:00 info Deploying configurations to environment `development-environment`...2023-08-24T10:21:13+02:00 info [coord=auto-tag:builtin:tags.auto-tagging:application-tagging] Deploying config2023-08-24T10:21:14+02:00 info Deployment finished without errors
If your configuration fails to deploy, refer to the output error description. You may have syntax errors in your files or your token requires more permissions.
To verify that your tag has been created
DTServer
.Now that your configuration is deployed, you can delete it. To do this, you will use the monaco delete
command.
To delete the previously created tag DTServer
, create a file called delete.yaml
in the root folder.
touch delete.yaml
Open the file in your text editor and paste the following configuration, then save the changes.
delete:- type: auto-tagname: "DTServer"
Delete the tag from your environment.
The delete
command requires both the delete file and the deployment manifest file as arguments.
The deployment manifest file indicates in which environments to delete the configuration specified in the delete file.
monaco delete --manifest manifest.yaml --file delete.yaml -e development-environment
If the deletion is successful, monaco
returns the following message:
2023-08-24T10:10:37+02:00 info Loading manifest "{your full path to the file}/manifest.yaml". Restrictions: groups=[], environments=[]2023-08-24T10:10:39+02:00 info Deleting configs for environment `development-environment`...2023-08-24T10:10:39+02:00 info Deleting configs of type auto-tag...
Now that you know the basics of creating, deploying, and deleting a configuration, you're ready to learn more.