Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application Insights resources #5543

Closed
rcarmo opened this issue Feb 10, 2018 · 14 comments
Closed

Application Insights resources #5543

rcarmo opened this issue Feb 10, 2018 · 14 comments

Comments

@rcarmo
Copy link
Member

rcarmo commented Feb 10, 2018

Is there a roadmap for creating App Insights resources via the CLI without resorting to resource create?

@rcarmo
Copy link
Member Author

rcarmo commented Feb 10, 2018

For the record, this is how I'm doing it now. But being able to do this in a cleaner way and also having a command to create and retrieve application instrumentation keys would be nice:

	az resource create \
		--resource-group $RESOURCE_GROUP \
		--resource-type "Microsoft.Insights/components" \
		--name $NAMESPACE_PREFIX-appinsights \
		--location $PRIMARY_LOCATION \
		--properties '{"ApplicationId":"facerecognition","Application_Type":"other", "Flow_Type":"Redfield", "Request_Source":"IbizaAIExtension"}'

@tjprescott
Copy link
Member

Thanks for your interest @rcarmo.

cc/ @mayurid @twitchax

@kizotheitguy
Copy link

Thanks for the command..
The below should help retrieve application instrumentation keys

az resource show -g $RESOURCEGROUPNAME -n $APPLICATION_NAME --resource-type "Microsoft.Insights/components" --query properties.InstrumentationKey

@Dave76
Copy link

Dave76 commented Nov 15, 2018

Thanks for the tips, but any ETA on when there will be an az insights cli command?

@Jarlotee
Copy link
Contributor

Does anyone know how to create an API key through the CLI?

@joshgav
Copy link

joshgav commented Nov 16, 2018

cc @nikmd23, this would be helpful for programmatically setting up an app insights space and referencing the instrumentation key.

@arjenbloemsma
Copy link

This does work. However, when I "connect" the resulting Application Insights to an app service (function app) by using the instrumentation key the Application Map seems not to work. Any ideas on that?

@nikmd23
Copy link

nikmd23 commented Nov 17, 2018

I've looped in the right people at AppInsights to see this thread!

@kuvinodms
Copy link

kuvinodms commented Jan 29, 2019

@yugangw-msft
I'm trying following command (Azure CLI version - 2.0.52) but its not working for me:

az resource create --resource-group myresourcegroup --name myappinsights --resource-type Microsoft.Insights/components --location southcentralus --properties '{"Application_Type":"web"}'

Error:
Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
File "C:\Users\VSSADM1\AppData\Local\Temp\pip-install-bb1gu7gd\knack\knack\cli.py", line 206, in invoke
File "C:\Users\VSSADM1\AppData\Local\Temp\pip-install-bb1gu7gd\azure-cli-core\azure\cli\core\commands_init_.py", line 328, in execute
File "C:\Users\VSSADM1\AppData\Local\Temp\pip-install-bb1gu7gd\azure-cli-core\azure\cli\core\commands_init_.py", line 386, in run_jobs_serially
File "C:\Users\VSSADM1\AppData\Local\Temp\pip-install-bb1gu7gd\azure-cli-core\azure\cli\core\commands_init
.py", line 379, in run_job
File "C:\Users\VSSADM1\AppData\Local\Temp\pip-install-bb1gu7gd\six\six.py", line 693, in reraise
File "C:\Users\VSSADM1\AppData\Local\Temp\pip-install-bb1gu7gd\azure-cli-core\azure\cli\core\commands_init
.py", line 356, in run_job
File "C:\Users\VSSADM1\AppData\Local\Temp\pip-install-bb1gu7gd\azure-cli-core\azure\cli\core\commands_init
.py", line 171, in call
File "C:\Users\VSSADM1\AppData\Local\Temp\pip-install-bb1gu7gd\azure-cli-core\azure\cli\core_init_.py", line 441, in default_command_handler
File "C:\Users\VSSADM1\AppData\Local\Temp\pip-install-bb1gu7gd\azure-cli-resource\azure\cli\command_modules\resource\custom.py", line 754, in create_resource
File "C:\Users\VSSADM1\AppData\Local\Temp\pip-install-bb1gu7gd\azure-cli-resource\azure\cli\command_modules\resource\custom.py", line 1753, in create_resource
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\json_init_.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\json\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Am I missing anything here ?

@markheath
Copy link
Contributor

@kuvinodms It can be really hard to escape the properties JSON correctly. So I tend to save it to a JSON file and then pass it to the Azure CLI with the --properties @props.json syntax

Here's an example using PowerShell and the Azure CLI:

'{"Application_Type":"web"}' | Out-File props.json
az resource create `
    -g $resourceGroup -n $appInsightsName `
    --resource-type "Microsoft.Insights/components" `
    --properties "@props.json"

see my article here

@zakimaksyutov
Copy link

Thank you @markheath, file approach did work for me.

@achandmsft achandmsft added this to To do in Compute Features via automation Mar 7, 2019
@NicoSorrenti
Copy link

NicoSorrenti commented Mar 7, 2019

The file approach works just as expected, but if anybody wants to use the command in PowerShell without writing to a file, the JSON can be escaped adding a \ in the double quotes works, like this:

az resource create --resource-group myresourcegroup --name myappinsights --resource-type Microsoft.Insights/components --location southcentralus --properties '{\"Application_Type\":\"web\"}'
(taking the @kuvinodms code as an example)

@markheath
Copy link
Contributor

markheath commented Mar 7, 2019

@NicoSorrenti thanks - I thought I'd tried that, but I'll give it another go.

@yugangw-msft
Copy link
Contributor

yugangw-msft commented Apr 16, 2019

Closing. PR made from @alexeldeib has taken care of this.
To use it, please run "az extension add -n application-insights", and you will see related commands under az monitor app-insights. Once commands are stabilized, we will move them to CLI's core monitor command module

Compute Features automation moved this from To do to Done Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests