Featured image of post How to Create Synthetic Monitor With Pulumi Python

How to Create Synthetic Monitor With Pulumi Python

Prepared environment

Install pulumi

install python

install poetry

Create pulumi project

Create pulumi project

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## create folder
mkdir newrelic-pulumi-example && cd newrelic-plumi-example
# crate pulumi project without active python venv
pulumi new python --name pulumi-newrelic-simple-mintor --stack dev --description "implement new relic sythetic simple monitoring" -y --generate-only --force

## Chang python virtual environment path 
sed -i 's/venv/.venv/g' Pulumi.yaml

# init poetry
poetry init

# install pulumi-newrelic module
poetry add pulumi-newrelic

# Install poetry
poetry install --no-root

# active virtual environment
source "$( poetry env list --full-path | grep Activated | cut -d' ' -f1 )/bin/activate"

Modify main.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
tee  __main__.py << "EOF"
"""A Python Pulumi program"""

import pulumi
import pulumi_newrelic as newrelic

# Create a New Relic Synthetic Monitor
synthetic_monitor = newrelic.synthetics.Monitor("example-monitor",
        uri = "https://echowings.github.io",
        type = "SIMPLE",
        period = "EVERY_MINUTE",
        status = "ENABLED",
        locations_publics = ["AWS_US_WEST_1", "AWS_EU_WEST_2" ] # Locations from where thechecks are mode
        )
# Export the ID of the monitor
pulumi.export('monitor_id', synthetic_monitor.id)
EOF

Set pulumi api

1
2
pulumi config set newrelic:apiKey xxxx
pulumi config set newrelic:accountId xxxx

Create dev stack

1
pulumi stack init dev --yes

Preview and check pulumi code

1
pulumi preview 

Pulumi deploy

1
pulumi up --yes

Pulumi destroy

1
pulumi destroy --yes

Pulumi delete stack

1
pulumi stack rm dev --yes

Reference

Built with Hugo
Theme Stack designed by Jimmy