Package: newrelic-synthetic-python-client
newrelic-synthetic-python-clientPython lib to interact with New Relic Synthetic Monitors API using NerdGraphnewrelic-synthetic-python-clientInstallationRequirementsInstall with pipDevelopmentUsage ExampleConfiguration fileConfiguration file placesLog levelSecure CredentialList secure credentialsUpdate or Create secure credentialsScripted Browser MonitorsList scripted browser monitorsUpdate or Create scripted browser monitorUpdate scripted browser monitor with accountCRUD Alert PolicyCreate Alert PolicyList Alert PolicyUpdate Alert PolicyDelete Alert PolicyCRUD Alert conditionCreate Alert ConditionList Alert ConditionUpdate Alert ConditionDelete Alert ConditionCRUD Alert DestinationsCreate Alert DestinationsList Alert DestinationsUpdate Alert DestinationsDelete Alert DestinationsCRUD Alert ChannelsCreate Alert ChannelsList Alert ChannelsUpdate Alert ChannelsDelete Alert ChannelsCRUD Alert WorkflowsCreate Alert WorkflowsList Alert WorkflowsUpdate Alert WorkflowsDelete Alert WorkflowsService LevelCreate Synthetic Service LevelList Synthetic Service LevelUpdate Synthetic Service LevelInstallationRequirementsPython 3.8 +PoetryInstall with pippip install newrelic-synthetic-python-clientDevelopmentpython3 -m venv .venv
source ./venv/bin/activateVerify the poetry is using the virutalenvpoetry env info

Virtualenv
Python:         3.8.13
Implementation: CPython
Path:           /Users/the/path/of/newrelic-synthetic-python-client/.venv
Valid:          True

System
Platform: darwin
OS:       posix
Python:   /opt/homebrew/opt/python@3.8/bin/../Frameworks/Python.framework/Versions/3.8Install the dependenciespoetry installThis will install all the dev/non-dev dependencies.Usage ExampleConfiguration fileThe configuration file contains the information to interact with NewRelic API endpoint, either via RESTFul API or Graphql.Create a JSON file contains the API Key, the example is like the following{"endpoint":"https://api.newrelic.com/graphql","api_key":"<user_api_key>","account_id":"<numeric_account_id>"}Let's say the file is located at$HOME/my-account.json. To use this file, you need to specify it in the environment variableNEWRELIC_PYTHON_CLIENT_JSONexport NEWRELIC_PYTHON_CLIENT_JSON=.config/wats-ng-dev.jsonConfiguration file placesSearch order$HOME/.newrelic-python-client.json$HOME/.config/newrelic-python-client.json$CWD/newrelic-python-client.jsonSpecified by environment$NEWRELIC_PYTHON_CLIENT_JSONThe one with larger number will overwrite the one with smaller number.You can put the JSON configuration file to$HOME/.newrelic-python-client.jsonand the configuration will take effect.And then you add a new file in$HOME/.config/newrelic-python-client.json, and this one will take effect,$HOME/.newrelic-python-client.jsonwill no longer take effect.Then you add a new file in$CWD/newrelic-python-client.json, then only this one will take effect.And finally, if you specify the file by environment variable, the environment variable become the only one that take effect.Log levelThe default log level is set to "INFO". You can change it by updating the environment variableNR_LOG_LEVEL.The possible log levels areTRACEDEBUGINFOWARNINGERRORThe full list can be found inloguru documentthe "The severity levels" section.The following command set the log level to TRACE and run the script.NR_LOG_LEVEL="TRACE" python src/newrelic.py synthetic secure_credential put --key SPS_ID_TOKEN --value 123Secure CredentialList secure credentialspython src/newrelic.py synthetic secure_credential listUpdate or Create secure credentialspython src/newrelic.py synthetic secure_credential put --key SPS_ID_TOKEN --value 123If the keySPS_ID_TOKENalready exist in your secure credentials storage, this command will update the existing credential. If the key does not exist, this command will create a new credential.Scripted Browser MonitorsList scripted browser monitorsNR_LOG_LEVEL="TRACE" python src/newrelic.py synthetic scripted_browser listUpdate or Create scripted browser monitorNR_LOG_LEVEL="INFO" python src/newrelic.py synthetic scripted_browser put --monitor-name "AUTO CREATE"Update scripted browser monitor with accountpythonsrc/newrelic.pysyntheticscripted_browserput--monitor-name"You Scripted Monitor Name"--script-content"You Script Path"--script-content"You Script Path"CRUD Alert PolicyCreate Alert PolicyNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertpolicyadd--name'policy name'--preference="PER_CONDITION"List Alert PolicyNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertpolicylistUpdate Alert PolicyNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertpolicyupdate--name"policy name"--preference"PER_POLICY"--policy-id"3715372"Delete Alert PolicyNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertpolicydelete--policy-id"3715372"CRUD Alert conditionCreate Alert Condition# Threshold Type StaticNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertconditionadd--name"auto_add_1"--policy-id"3719613"# Threshold Type BaselineNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertconditionadd--name"auto_add_baseline"--policy-id"3717302"--type"baseline"--operator"ABOVE"--threshold"1"--threshold-duration"120"List Alert ConditionNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertconditionlistUpdate Alert Condition# Threshold Type StaticNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertconditionupdate--condition-id"28613358"--name"auto_static_update"# Threshold Type BaselineNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertconditionupdate--name"auto_add_baseline_update"--condition-id"28614376"--type"baseline"--operator"ABOVE"--threshold"1"--threshold-duration"120"Delete Alert ConditionNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertconditiondelete--condition-id"28613141"CRUD Alert DestinationsCreate Alert DestinationsNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertdestinationsadd--name"auto_add_1"--email"test@example.com"List Alert DestinationsNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertdestinationslistUpdate Alert DestinationsNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertdestinationsupdate--name"auto_add_update"--destinations-id"You-Destination-ID"Delete Alert DestinationsNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertdestinationsdelete--destinations-id"You-Destination-ID"CRUD Alert ChannelsCreate Alert ChannelsNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertchannelsadd--name"auto_channel_1"--destination-id"You-Destination-ID"List Alert ChannelsNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertchannelslistUpdate Alert ChannelsNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertchannelsupdate--name"auto_channel_update_1"--channel-id"You-Channel-ID"Delete Alert ChannelsNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertchannelsdelete--channel-id"You-Channel-ID"CRUD Alert WorkflowsCreate Alert WorkflowsNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertworkflowsadd--name"auto_workflow_add_1"--policy-id"You-Policy-ID"--channel-id"You-Channel-ID"List Alert WorkflowsNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertworkflowslist--type"EMAIL"Update Alert WorkflowsNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertworkflowsupdate--name"auto_workflow_update_1"--workflow-id"You-Workflow-ID"Delete Alert WorkflowsNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pyalertworkflowsdelete--workflow-id"You-Workflow-ID"Service LevelCreate Synthetic Service LevelNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pysyntheticservice_leveladd--monitor-name"You-monitor-name"--name"You-service-level-name"List Synthetic Service LevelNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pysyntheticservice_levellist--monitor-name"You-monitor-name"Update Synthetic Service LevelNR_LOG_LEVEL="INFO"pythonsrc/newrelic.pysyntheticservice_levelupdate--indicators-id"You-indicators-id"--count"1"