Skip to content

Commit 65f4593

Browse files
isra-felLucas Yao (Wicresoft North America)LucasYao93
authored
Az.MonitoringSolutions (#12297)
* initial generation for resource: solution * wip * test * wip * design review * wip * finalize readme.md * Add test cases and example of monitor solutions. * Modified test cases and examples. * Modified test cases and examples. * Add related link of New-AzMonitorLogAnalyticsSolution. * doc * update description of updte-solution Co-authored-by: Lucas Yao (Wicresoft North America) <[email protected]> Co-authored-by: LucasYao93 <[email protected]>
1 parent f21b149 commit 65f4593

32 files changed

+3152
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

src/MonitoringSolutions/.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
bin
2+
obj
3+
.vs
4+
generated
5+
internal
6+
exports
7+
custom/*.psm1
8+
test/*-TestResults.xml
9+
/*.ps1
10+
/*.ps1xml
11+
/*.psm1
12+
/*.snk
13+
/*.csproj
14+
/*.nuspec
15+
/*.psd1
16+
tools
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
2+
# ----------------------------------------------------------------------------------
3+
#
4+
# Copyright Microsoft Corporation
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ----------------------------------------------------------------------------------
15+
16+
<#
17+
.Synopsis
18+
Creates a log analytics solution.
19+
.Description
20+
Creates a log analytics solution.
21+
.Outputs
22+
Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Models.Api20151101Preview.ISolution
23+
.Link
24+
https://docs.microsoft.com/en-us/powershell/module/az.monitoringsolutions/new-azmonitorloganalyticssolution
25+
.LINK
26+
[Get-AzOperationalInsightsWorkspace](https://docs.microsoft.com/en-us/powershell/module/az.operationalinsights/get-azoperationalinsightsworkspace)
27+
#>
28+
function New-AzMonitorLogAnalyticsSolution {
29+
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Models.Api20151101Preview.ISolution])]
30+
[CmdletBinding(DefaultParameterSetName = 'CreateExpanded', PositionalBinding = $false, SupportsShouldProcess, ConfirmImpact = 'Medium')]
31+
param(
32+
[Parameter(Mandatory)]
33+
[Alias('SolutionType')]
34+
[System.String]
35+
# Type of the solution to be created. For example "Container".
36+
${Type},
37+
38+
[Parameter(Mandatory)]
39+
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Path')]
40+
[System.String]
41+
# The name of the resource group to get.
42+
# The name is case insensitive.
43+
${ResourceGroupName},
44+
45+
[Parameter()]
46+
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Path')]
47+
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Runtime.DefaultInfo(Script = '(Get-AzContext).Subscription.Id')]
48+
[System.String]
49+
# Gets subscription credentials which uniquely identify Microsoft Azure subscription.
50+
# The subscription ID forms part of the URI for every service call.
51+
${SubscriptionId},
52+
53+
[Parameter(Mandatory)]
54+
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Body')]
55+
[System.String]
56+
# Resource location. Must be the same as the log analytic workspace.
57+
${Location},
58+
59+
[Parameter()]
60+
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Body')]
61+
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Runtime.Info(PossibleTypes = ([Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Models.Api20151101Preview.ISolutionTags]))]
62+
[System.Collections.Hashtable]
63+
# Resource tags
64+
${Tag},
65+
66+
[Parameter(Mandatory)]
67+
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Body')]
68+
[System.String]
69+
# The Azure resource ID for the workspace where the solution will be deployed/enabled.
70+
${WorkspaceResourceId},
71+
72+
[Parameter()]
73+
[Alias('AzureRMContext', 'AzureCredential')]
74+
[ValidateNotNull()]
75+
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Azure')]
76+
[System.Management.Automation.PSObject]
77+
# The credentials, account, tenant, and subscription used for communication with Azure.
78+
${DefaultProfile},
79+
80+
[Parameter(DontShow)]
81+
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Runtime')]
82+
[System.Management.Automation.SwitchParameter]
83+
# Wait for .NET debugger to attach
84+
${Break},
85+
86+
[Parameter(DontShow)]
87+
[ValidateNotNull()]
88+
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Runtime')]
89+
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Runtime.SendAsyncStep[]]
90+
# SendAsync Pipeline Steps to be appended to the front of the pipeline
91+
${HttpPipelineAppend},
92+
93+
[Parameter(DontShow)]
94+
[ValidateNotNull()]
95+
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Runtime')]
96+
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Runtime.SendAsyncStep[]]
97+
# SendAsync Pipeline Steps to be prepended to the front of the pipeline
98+
${HttpPipelinePrepend},
99+
100+
[Parameter(DontShow)]
101+
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Runtime')]
102+
[System.Uri]
103+
# The URI for the proxy server to use
104+
${Proxy},
105+
106+
[Parameter(DontShow)]
107+
[ValidateNotNull()]
108+
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Runtime')]
109+
[System.Management.Automation.PSCredential]
110+
# Credentials for a proxy server to use for the remote call
111+
${ProxyCredential},
112+
113+
[Parameter(DontShow)]
114+
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Runtime')]
115+
[System.Management.Automation.SwitchParameter]
116+
# Use the default credentials for the proxy
117+
${ProxyUseDefaultCredentials}
118+
)
119+
120+
process {
121+
$resourceIdentifier = [Microsoft.Azure.Management.Internal.Resources.Utilities.Models.ResourceIdentifier]::new($WorkspaceResourceId)
122+
$workspaceName = $resourceIdentifier.ResourceName
123+
$solutionName = "$Type($workspaceName)"
124+
$PSBoundParameters.Add('Name', $solutionName) | Out-Null
125+
$PSBoundParameters.Add('PlanName', $solutionName) | Out-Null
126+
$PSBoundParameters.Add('PlanProduct', "OMSGallery/$Type") | Out-Null
127+
$PSBoundParameters.Add('PlanPublisher', "Microsoft") | Out-Null
128+
$PSBoundParameters.Add('PlanPromotionCode', "") | Out-Null
129+
$PSBoundParameters.Remove('Type') | Out-Null
130+
Az.MonitoringSolutions.internal\New-AzMonitorLogAnalyticsSolution @PSBoundParameters
131+
}
132+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Custom
2+
This directory contains custom implementation for non-generated cmdlets for the `Az.MonitoringSolutions` module. Both scripts (`.ps1`) and C# files (`.cs`) can be implemented here. They will be used during the build process in `build-module.ps1`, and create cmdlets into the `..\exports` folder. The only generated file into this folder is the `Az.MonitoringSolutions.custom.psm1`. This file should not be modified.
3+
4+
## Info
5+
- Modifiable: yes
6+
- Generated: partial
7+
- Committed: yes
8+
- Packaged: yes
9+
10+
## Details
11+
For `Az.MonitoringSolutions` to use custom cmdlets, it does this two different ways. We **highly recommend** creating script cmdlets, as they are easier to write and allow access to the other exported cmdlets. C# cmdlets *cannot access exported cmdlets*.
12+
13+
For C# cmdlets, they are compiled with the rest of the generated low-level cmdlets into the `./bin/Az.MonitoringSolutions.private.dll`. The names of the cmdlets (methods) and files must follow the `[cmdletName]_[variantName]` syntax used for generated cmdlets. The `variantName` is used as the `ParameterSetName`, so use something appropriate that doesn't clash with already created variant or parameter set names. You cannot use the `ParameterSetName` property in the `Parameter` attribute on C# cmdlets. Each cmdlet must be separated into variants using the same pattern as seen in the `generated/cmdlets` folder.
14+
15+
For script cmdlets, these are loaded via the `Az.MonitoringSolutions.custom.psm1`. Then, during the build process, this module is loaded and processed in the same manner as the C# cmdlets. The fundemental difference is the script cmdlets use the `ParameterSetName` attribute and C# cmdlets do not. To create a script cmdlet variant of a generated cmdlet, simply decorate all parameters in the script with the new `ParameterSetName` in the `Parameter` attribute. This will appropriately treat each parameter set as a separate variant when processed to be exported during the build.
16+
17+
## Purpose
18+
This allows the modules to have cmdlets that were not defined in the REST specification. It also allows combining logic using generated cmdlets. This is a level of customization beyond what can be done using the [readme configuration options](https://github.com/Azure/autorest/blob/master/docs/powershell/options.md) that are currently available. These custom cmdlets are then referenced by the cmdlets created at build-time in the `..\exports` folder.
19+
20+
## Usage
21+
The easiest way currently to start developing custom cmdlets is to copy an existing cmdlet. For C# cmdlets, copy one from the `generated/cmdlets` folder. For script cmdlets, build the project using `build-module.ps1` and copy one of the scripts from the `..\exports` folder. After that, if you want to add new parameter sets, follow the guidelines in the `Details` section above. For implementing a new cmdlets, at minimum, please keep these parameters:
22+
- Break
23+
- DefaultProfile
24+
- HttpPipelineAppend
25+
- HttpPipelinePrepend
26+
- Proxy
27+
- ProxyCredential
28+
- ProxyUseDefaultCredentials
29+
30+
These provide functionality to our HTTP pipeline and other useful features. In script, you can forward these parameters using `$PSBoundParameters` to the other cmdlets you're calling within `Az.MonitoringSolutions`. For C#, follow the usage seen in the `ProcessRecordAsync` method.
31+
32+
### Attributes
33+
For processing the cmdlets, we've created some additional attributes:
34+
- `Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Models.DescriptionAttribute`
35+
- Used in C# cmdlets to provide a high-level description of the cmdlet. This is propegated to reference documentation via [help comments](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comment_based_help) in the exported scripts.
36+
- `Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Models.DoNotExportAttribute`
37+
- Used in C# and script cmdlets to suppress creating an exported cmdlet at build-time. These cmdlets will *not be exposed* by `Az.MonitoringSolutions`.
38+
- `Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Models.InternalExportAttribute`
39+
- Used in C# cmdlets to route exported cmdlets to the `..\internal`, which are *not exposed* by `Az.MonitoringSolutions`. For more information, see [readme.md](..\internal/readme.md) in the `..\internal` folder.
40+
- `Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Models.ProfileAttribute`
41+
- Used in C# and script cmdlets to define which Azure profiles the cmdlet supports. This is only supported for Azure (`--azure`) modules.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
Module Name: Az.MonitoringSolutions
3+
Module Guid: ea677a1c-aecd-4441-8953-7881b5cfc8a6
4+
Download Help Link: https://docs.microsoft.com/en-us/powershell/module/az.monitoringsolutions
5+
Help Version: 1.0.0.0
6+
Locale: en-US
7+
---
8+
9+
# Az.MonitoringSolutions Module
10+
## Description
11+
Microsoft Azure PowerShell: MonitoringSolutions cmdlets
12+
13+
## Az.MonitoringSolutions Cmdlets
14+
### [Get-AzMonitorLogAnalyticsSolution](Get-AzMonitorLogAnalyticsSolution.md)
15+
Retrieves the user solution.
16+
17+
### [New-AzMonitorLogAnalyticsSolution](New-AzMonitorLogAnalyticsSolution.md)
18+
Creates a log analytics solution.
19+
20+
### [Remove-AzMonitorLogAnalyticsSolution](Remove-AzMonitorLogAnalyticsSolution.md)
21+
Deletes the solution in the subscription.
22+
23+
### [Update-AzMonitorLogAnalyticsSolution](Update-AzMonitorLogAnalyticsSolution.md)
24+
Update the tags of a solution.
25+

0 commit comments

Comments
 (0)