Search 'Input' of Azure Runbook Jobs? - azure

I have a pretty simple issue which perhaps is by-design but I just wanted to make sure I wasn't missing something...
Basically we use a lot of runbooks at my job, and this results in a ton of jobs generated under the automation accounts. I found I can search based on when the job was created and the name of the runbook, but is there no way to search based on the input parameters of the runbook?
This would help troubleshooting immensely as when someone says "well when were these users created" or "when was this instance upgraded" I can just search for that input param and answer the question quickly.
Perhaps it would be best to log all of the input parameters so then that is searchable via log analytics?
Thanks!!

Welcome to Stack Overflow!
Yes, Currently from Azure Portal there is no way to search based on the input parameters of the runbook. This can be raised as an feature request in this UserVoice / feedback forum. Responsible Azure feature / product team would triage and check the feasibility of the feature request and prioritize accordingly.
However, I believe as a workaround we can accomplish your requirement by leveraging Az PowerShell cmdlet Get-AzAutomationJob as explained in below screenshots.
So the command to use would be something like below:
Get-AzAutomationJob -AutomationAccountName "<YourAutomationAccountName>" -ResourceGroupName "<YourAutomationAccountResourceGroupName>" | foreach{Get-AzAutomationJob -ResourceGroupName $_.ResourceGroupName -AutomationAccountName $_.AutomationAccountName -Id $_.JobId | ?{$_.JobParameters.GetEnumerator().Where({$_.Value -contains "<KeyValueName>"})}}
or something like below if you want to validate 2 job parameters (one being key and another being a value)
Get-AzAutomationJob -AutomationAccountName "<YourAutomationAccountName>" -ResourceGroupName "<YourAutomationAccountResourceGroupName>" | foreach{Get-AzAutomationJob -ResourceGroupName $_.ResourceGroupName -AutomationAccountName $_.AutomationAccountName -Id $_.JobId | ?{$_.JobParameters.GetEnumerator().Where({$_.Value -contains "<KeyValueName>"}) -and $_.JobParameters.GetEnumerator().Where({$_.Key -contains "<KeyName>"})}}
Similarly you may have to tweak the command a bit to fit your needs.

Related

Do ARM templates provide a way to capture the logs during creation of resources

we have ARM template which creates the azure resources. While we run the powershell script which created the resources, we want to log all the info.
we want to know if any logging functionality which azure ARM template provides
the list of resources we are as follows :
- storage account
- automation account
- key-vault
- Sql server pool
- functionApp etc
Below are some of the general configurations you can use for the New-AzureRmResourceGroupDeployment to get the most amount of logging from the command. You may lookup the equivalent AZ cmdlet, if you need to.
You can use the -Verbose and -DeploymentDebugLogLevel All parameters to get some more logging info. Note that the Deployment debug parameter will cause a warning to show up in your console output stream.
You can use the -ErrorVariable ErrorMessages parameter to get the error messages and then use them appropriately in your script.
Lastly, you can use the JSON output of the cmdlet to get some insights, if any.
Below is how the cmldet typically looks like for me..
$jsonOutput = New-AzureRmResourceGroupDeployment -Name $DeploymentName `
-ResourceGroupName $ResourceGroupName `
-TemplateFile $TemplateFileToDeploy `
-TemplateParameterObject $TemplateParameters `
-Force -Verbose `
-ErrorVariable ErrorMessages -DeploymentDebugLogLevel All
closest you can get is launch new-azresourcegroupdeployment with the -verbose switch, that would give you some idea whats going on, but I dont really think you are interested in that, you are mostly interested in errors. Fairly certain new-azresourcegroupdeployment outputs those.

Powershell command to fetch Azure monitor alert rules is not working

I have created an alert rule and associated it with a VM. Now trying to fetch the alert rule through Powershell, but getting null. What's wrong with this code ?
Get-AzAlertRule -ResourceGroupName 'pacbldnew'
see the alert rule
powershell code returning null
That is just a warning. The command should work, make sure the alert rule is existing.
Update1:
Try the command below to get what you want.
Get-AzResource -ResourceGroupName joywebapp -ResourceType microsoft.insights/metricAlerts
Update2:
If you want to get the details, try the script as below.
$names = (Get-AzResource -ResourceGroupName joywebapp -ResourceType microsoft.insights/metricAlerts).Name
foreach($name in $names){
Get-AzResource -ResourceGroupName joywebapp -Name $name -ResourceType microsoft.insights/metricAlerts | ConvertTo-Json
}
Joy is right in the way that the cmdlet should still execute as what you see is just a warning. However, this could be happening as Powershell support for newer metric alerts is still in the works as mentioned in the Official docs.
Also, as an alternative, if it helps, you could use Azure CLI to list newer Metric Alerts, as it now supports fetching elaborate results of queries belonging to the Microsoft.Insights/metricAlerts resource type.
For example:
az monitor metrics alert list -g <Resource group name> --output yaml
The result would look something like this:
You also get to choose out of the many output formats (json, jsonc, yaml, table, tsv) available with Az CLI.
Hope this helps!
Go to Azure- home security center and settings and filter and extract all rules
This query has worked for me:
Get-AzResource -ResourceType "microsoft.insights/scheduledqueryrules" -ResourceGroupName "Alert-RG"

Azure Powershell how many times a service is called given a time range

I can use Get-AzureRmResource and filter by resource type
(Microsoft.Web/Sites) to have a list of web apps and services.
I need to get the answer to "Given this date range 1-1-2018 to present,
how many times each site has been called/used/visited?"
Do I use Get-AzureRmLog? if no, what can I use? If yes, what in log Analytics and give me the counts by service?
Thanks
No, this is not really possible with these commands, they are related to the Azure platform
You need to use something like this:
Get-AzureRmAppServicePlanMetrics -ResourceGroupName "Default-Web-WestUS" -Name "ContosoWebApp" -StartTime 2016-11-30T22:00:00Z -EndTime 2016-11-30T22:30:00Z -Granularity PT1M -Metrics ["Requests"]
https://www.reddit.com/r/AZURE/comments/60n0rl/azure_app_service_metrics/
https://learn.microsoft.com/en-us/powershell/module/azurerm.websites/get-azurermwebappmetrics?view=azurermps-5.6.0

Where do I get the ResourceGroup for AzureResourceManager CmdLets?

The new and soon to supercede AzureRsourceManager cmdlets all require a -ResourceGroupName parameter. Where am I expected to get this? Not including the UI, since that'd mostly defeat the purpose of automating.
Currently, I'm calling Get-AzureResourceGroup and trying each one until I get a hit. This is extremely slow - on the order of minutes. For example, to get WebApp information, I'm running this,
$groups = Get-AzureResourceGroup
foreach ($g in $groups)
{
if ($ResourceGroup) { $ResourceGroup.Value = $g.ResourceGroupName }
$app = Get-AzureWebApp -Name $Name -ResourceGroupName $g.ResourceGroupName -ErrorAction SilentlyContinue
Write-Verbose "Checking $($g.ResourceGroupName)"
if ($app)
{
$ResourceGroups[$g.ResourceGroupName] = #($ResourceGroups[$g.ResourceGroupName]) + $Name
return $app
}
}
If you go to the portal and navigate to your web app you can easily see which resource group it's in. See the screenshot below. What resource group is, is an arbitrary name to group resources. For example below you can see that it is grouping two Web Apps and two App Service Plans.
You can use the Get-AzureRmResourceGroup PowerShell command from Azure PowerShell without any parameter to get all the resource groups in very fast response time.
Reference Link: Get-AzureRMResourceGroup description
Note: You need to update your Azure PowerShell to the latest version for this new feature. The current version is 1.0.1 (November 2015 Update)
As #theadriangreen noted in his comment, it's faster to directly query the REST API. I found that some of the RM cmdlets actually do this anyway.
I've written a set of PowerShell functions to make using the API easier and faster (uses caching), in this gist.

Start-AzureVM: Getting struck continously

Can anyone please tell me if there are any change for "Start-AzureVM" API?
It is getting struck with following command
Start-AzureVM -ServiceName (get-azurevm | where {$_.name -eq $VMName}).ServiceName -NAME $VMName
Also help me on where to look for latest azure API changes?
Make sure that you select a valid Azure Subscription using Select-AzureSubscription cmdlet before you use Start-AzureVM cmdlet.
When you do not have a valid Azure Subscription, there is a potential chance for all other Azure cmdlets behave awkwardly like you mentioned in your question.

Resources