Updating EventGrid Topic to set DeadLettering destination using Azure CLI - azure

I'm following the instructions here to add a --deadletter-endpoint to an existing EventGrid subscription.
The process is failing with error: Event subscription doesn't exist.
What am I missing?:
Azure Cloud Shell
Commands executed:
containername=eg-dead-letter-events //container where deadlettered events will be stored
topicid=$(az eventgrid system-topic show --name egtop-dev -g TEST_DEV --query id --output tsv) //name of eventgrid system topic
storageid=$(az storage account show --name stgdev --resource-group TEST_DEV --query id --output tsv) //name of storage account where deadlettered events will be stored
az eventgrid event-subscription update \
--name egsub-dev \ //name of Event Subscription here? also tried System Topic name, no go.
--source-resource-id $topicid \ //I cannot find a clear reference for what is supposed to go here
--deadletter-endpoint $storageid/blobServices/default/containers/$containername
Results: Event subscription doesn't exist.
Edit 1: Made some progress
This command helped list out the needed pieces:
az eventgrid event-subscription list --topic-type "Microsoft.Storage.StorageAccounts" --location southcentralus
Hardcoded values found in the above response as:
az eventgrid event-subscription update --name egsub-dev --source-resource-id /subscriptions/$subscription/resourceGroups/$resourceGroup/providers/Microsoft.Storage/storageAccounts/storageAccountThatTriggersEventGrid/providers/Microsoft.EventGrid/eventSubscriptions/egsub-dev --deadletter-endpoint $storageid/blobServices/default/containers/$containername
But this results in a different error:
No registered resource provider found for location 'southcentralus' and API version '2020-10-15-preview' for type 'storageAccounts'. The supported api-versions are '2021-04-01, 2021-02-01, 2021-01-01, 2020-08-01-preview, 2019-06-01, 2019-04-01, 2018-11-01, 2018-07-01, 2018-03-01-preview, 2018-02-01, 2017-10-01, 2017-06-01, 2016-12-01, 2016-05-01, 2016-01-01, 2015-06-15, 2015-05-01-preview'. The supported locations are 'eastus, eastus2, westus, westeurope, eastasia, southeastasia, japaneast, japanwest, northcentralus, southcentralus, centralus, northeurope, brazilsouth, australiaeast, australiasoutheast, southindia, centralindia, westindia, canadaeast, canadacentral, westus2, westcentralus, uksouth, ukwest, koreacentral, koreasouth, francecentral, australiacentral, southafricanorth, uaenorth, switzerlandnorth, germanywestcentral, norwayeast, westus3, jioindiawest'.
Thoughts on this one?

Regarding the issue, please update the script as below
sourceid=$(az eventgrid system-topic show --name egtop-dev -g TEST_DEV --query source --output tsv)
storageid=$(az storage account show --name stgdev --resource-group TEST_DEV --query id --output tsv)
az eventgrid event-subscription update \
--name egsub-dev \
--source-resource-id $sourceid\
--deadletter-endpoint $storageid/blobServices/default/containers/$containername

Related

How do I know which image version is installed on a specific instance of an Azure VMSS?

I have an Azure VMSS (Virtual Machine Scale Set) with a few instances, linked to an "image gallery". The VMSS is configured in such a way that it is supposed to always choose the latest version of a specific image from the image gallery.
How and where can I see, which version of the image is installed on a specific instance?
If the image gallery is configured to install the latest image on new instances, the image version can potentially vary between instances. The actually installed version of an image is stored in the storageProfile.imageReference.exactVersion property of the vmss object.
Listing the installed image version for a specific machine in an existing scale set:
az vmss show --resource-group "<resource group name>" \
--subscription "<subscription name>" \
--name <vmss name> \
--instance-id <instance id> \
--query storageProfile.imageReference.exactVersion
The reply matches the version number defined in the image gallery:
"2021.06.1782103"
If the instance id is not known, it is possible to get all instance ids of an existing scale set:
az vmss list-instances --resource-group "<resource group name>" \
--subscription "<subscription name>" \
--name <vmss name> \
--query [].instanceId
[
"1141",
"1142",
"1143"
]
To further simplify things, one could list the installed image version for each machine in an existing scale set. This allows, for example, to see if all instances are at the same version or one is left behind:
az vmss list-instances --resource-group "<resource group name>" \
--subscription "<subscription name>" \
--name <vmss name> \
--query [].storageProfile.imageReference.exactVersion
In an example with 3 instances the reply may indicate that two machines are on the later version (...03), and one machine is still on an older version of the image (...02):
[
"2021.06.1782102",
"2021.06.1782103",
"2021.06.1782103"
]
Finally, to combine this one can also query for instanceId and installed image version at the same time:
az vmss list-instances --resource-group "<resource group name>" --subscription "<subscription name>" --name <vmss name> --query "[].[instanceId,storageProfile.imageReference.exactVersion]"
[
[
"1141",
"2021.06.1782102"
],
[
"1142",
"2021.06.1782103"
],
[
"1143",
"2021.06.1782103"
]
]
You can get the exect version of image reference for one specfic instance by using the Get-AzVmssVM cmdlet with the following sytax:
(Get-AzVmssVM -ResourceGroupName $rgName -Name $ScaleSetName -InstanceId $instanceId).StorageProfile.ImageReference

What is the right way to get Azure Cognitive service account endpoint from Azure-CLI

I was using the following command
$cogVisionEndpoint = (az cognitiveservices account show -n $accountName -g $resourceGroupName --query endpoint --output tsv)
but I found out that this stopped working when I ran this on another machine with a slightly newer version of Azure-CLI.
The JSON returned by the az cognitiveservices account show command is not consistent and looks like it has changed from version to a version.
How can I reliably get this not having to worry about the version of Azure CLI on the machine that I'm running on?
Or is there a completely different way to get the endpoint value?
With the newest version you will find endpoint in properties and since you rely on CLI version installed on the given machine you can simply modify your code to something like this:
$cogVisionEndpoint = (az cognitiveservices account show -n $accountName -g $resourceGroupName --query endpoint --output tsv)
if( !$cogVisionEndpoint ) {
$cogVisionEndpoint = (az cognitiveservices account show -n $accountName -g $resourceGroupName --query "properties.endpoint" --output tsv)
}

The attempt to validate the provided endpoint resource failed

Trying to create a new azure eventgrid endpoint subscription based on the code in the Microsoft tutorial here errors:
az eventgrid event-subscription create --source-resource-id $topicid --name eventsubscriptionname --endpoint-type storagequeue --endpoint $queueid --expiration-date "2020-05-15"
Deployment failed. Correlation ID: xxxx. The attempt to validate the provided azure endpoint resource:xxxx failed.
The tutorial says to ensure the account has write access to the storage, which it does, I am the owner. All properties in the command have valid values and I am executing from the azure cli.
What could I be doing wrong?
That's weird... I tried on my side and I have the expected result using the following commands :
$resourcegroup="your resource group"
$storagename="your storage name"
$queuename="your queue name"
$topicname="your topic name"
$subscriptionname="your subscription name"
$storageid=az storage account show --name $storagename --resource-group $resourcegroup --query id --output tsv
$queueid="$storageid/queueservices/default/queues/$queuename"
$topicid=az eventgrid topic show --name $topicname -g $resourcegroup --query id --output tsv
az eventgrid event-subscription create --source-resource-id $topicid --name $subscriptionname --endpoint-type storagequeue --endpoint $queueid --expiration-date "2020-05-15"
I sued PowerShell version 5.1.18362.752 and AZ CLI version 2.5.1

Showing error when trying to start backup of vms through cli commands

I wrote the command:
az backup protection backup-now --resource-group Rsrgrp \
--vault-name CLIbkvault --container-name CLIcont \
--item-name MyItem --retain-until 29-02-2020 \
--backup-management-type AzureStorage
And I'm gettnig this error:
Item not found. Please provide a valid item_name.
I dont know which item name the error is referring to.
My guess this is the first time you try to backup the resource, is that so?
If so, you will need to first add the resource as protected to the backup vault, then the item name will be the name of the resource you are backing up.
Azure VM
az backup protection enable-for-vm --policy-name
--vm
[--disk-list-setting {exclude, include}]
[--diskslist]
[--ids]
[--resource-group]
[--subscription]
[--vault-name]
Azure File Share
az backup protection enable-for-azurefileshare --azure-file-share
--policy-name
--storage-account
[--ids]
[--resource-group]
[--subscription]
[--vault-name]
Azure Workload
az backup protection enable-for-azurewl --policy-name
--protectable-item-name
--protectable-item-type {HANAInstance, SAPHanaDatabase, SAPHanaSystem, SQLAG, SQLDatabase, SQLInstance}
--server-name
--workload-type {AzureFileShare, MSSQL, SAPHANA, SAPHanaDatabase, SQLDataBase, VM}
[--ids]
[--resource-group]
[--subscription]
[--vault-name]
https://learn.microsoft.com/en-us/cli/azure/backup/protection

Move Azure VM from one OMS work-space to another using CLI

Is there a command to move Azure VM from one OMS( Log Analytics) work-space to the another OMS work-space ?
I read the documentation of AzureRmResource but not sure if this is the right option ?
According to your scenario, you need remove agent on your VM and install OMS agent with new OMS configuration. Here is the script you could use. I test in my lab, it works for me.
#!/bin/sh
# resource group name, vm nmae, OMS Id and OMS key.
rg=<resource group name>
vmname=<>
omsid="<>"
omskey=""
##Remvoe OMS agent from VM
az vm extension delete -g $rg --vm-name $vmname -n OmsAgentForLinux
# re-install and configure the OMS agent with your new OMS.
az vm extension set \
--resource-group $rg \
--vm-name $vmname \
--name OmsAgentForLinux \
--publisher Microsoft.EnterpriseCloud.Monitoring \
--version 1.0 --protected-settings '{"workspaceKey": "'"$omskey"'"}' \
--settings '{"workspaceId": "'"$omsid"'"}'
Use the command 'az vm extension set'.
Sample bash script for this.
#!/bin/sh
vmname=<Replace with your vm name>
rgname=<Replace with your Resource Group name>
omsid=<Replace with your OMS Id>
omskey=<Replace with your OMS key>
az vm extension set \
--resource-group $rgname \
--vm-name $vmname \
--name OmsAgentForLinux \
--publisher Microsoft.EnterpriseCloud.Monitoring \
--version 1.0 --protected-settings '{"workspaceKey": "'"$omskey"'"}' \
--settings '{"workspaceId": "'"$omsid"'"}'

Resources