Today I bring you a little script for exporting all the alerts you have created in a OMS workspace, this is useful for alert management and for having documentation about it’s configuration.
It creates a CSV like this:
When you run it, it will list all the alerts it is getting.
Be patient it will take some time, but let[s discuss how this works.
The hierarchy for alerts in the rest API works like this:
In order to get the workspace you want and it’s resource group you need to get it like this:
This will get you all workspaces.
After that we need to select the workspace we want, we have a variable with that name and we need to get it from the list we got on the previous command.
ForEach($Workspace in $allWorkspaces.value)
if($Workspace.name -eq $WorkspaceID)
$url = $Workspace.id
This will go through all the WS in my subscription and add to the URL variable the one I want by name, noticed that I[m using the .value in the foreach, that’s because when I convert the request response from json, and I need to access values like this, then instead of using .value.name, inside the same cycle I can just call the .name inside WorkspaceID variable.
This URL is the base for everything, next on our hierarchy we will need to get all our saved searches:
If you notice from now on we will use the base $url we got for everything.
Once we have searches the next level is schedule for those searches, each schedule URL could look like this:
And at the end we get the type of schedules, this could be or not associated with an alert, each schedule has a value.properties.Type which will tell us if this is an alert or not.
You can use armclient which is the one i use in this script and it[s a prerequisite for running it, you can get it here: https://github.com/projectkudu/ARMClient
All configuration instructions are n the script itself, you can get it in the next link: