Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/MonitoringSolutions/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
16 changes: 16 additions & 0 deletions src/MonitoringSolutions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
bin
obj
.vs
generated
internal
exports
custom/*.psm1
test/*-TestResults.xml
/*.ps1
/*.ps1xml
/*.psm1
/*.snk
/*.csproj
/*.nuspec
/*.psd1
tools
132 changes: 132 additions & 0 deletions src/MonitoringSolutions/custom/New-AzMonitorLogAnalyticsSolution.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@

# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

<#
.Synopsis
Creates a log analytics solution.
.Description
Creates a log analytics solution.
.Outputs
Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Models.Api20151101Preview.ISolution
.Link
https://docs.microsoft.com/en-us/powershell/module/az.monitoringsolutions/new-azmonitorloganalyticssolution
.LINK
[Get-AzOperationalInsightsWorkspace](https://docs.microsoft.com/en-us/powershell/module/az.operationalinsights/get-azoperationalinsightsworkspace)
#>
function New-AzMonitorLogAnalyticsSolution {
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Models.Api20151101Preview.ISolution])]
[CmdletBinding(DefaultParameterSetName = 'CreateExpanded', PositionalBinding = $false, SupportsShouldProcess, ConfirmImpact = 'Medium')]
param(
[Parameter(Mandatory)]
[Alias('SolutionType')]
[System.String]
# Type of the solution to be created. For example "Container".
${Type},

[Parameter(Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Path')]
[System.String]
# The name of the resource group to get.
# The name is case insensitive.
${ResourceGroupName},

[Parameter()]
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Runtime.DefaultInfo(Script = '(Get-AzContext).Subscription.Id')]
[System.String]
# Gets subscription credentials which uniquely identify Microsoft Azure subscription.
# The subscription ID forms part of the URI for every service call.
${SubscriptionId},

[Parameter(Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Body')]
[System.String]
# Resource location. Must be the same as the log analytic workspace.
${Location},

[Parameter()]
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Body')]
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Runtime.Info(PossibleTypes = ([Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Models.Api20151101Preview.ISolutionTags]))]
[System.Collections.Hashtable]
# Resource tags
${Tag},

[Parameter(Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Body')]
[System.String]
# The Azure resource ID for the workspace where the solution will be deployed/enabled.
${WorkspaceResourceId},

[Parameter()]
[Alias('AzureRMContext', 'AzureCredential')]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Azure')]
[System.Management.Automation.PSObject]
# The credentials, account, tenant, and subscription used for communication with Azure.
${DefaultProfile},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Runtime')]
[System.Management.Automation.SwitchParameter]
# Wait for .NET debugger to attach
${Break},

[Parameter(DontShow)]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Runtime')]
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Runtime.SendAsyncStep[]]
# SendAsync Pipeline Steps to be appended to the front of the pipeline
${HttpPipelineAppend},

[Parameter(DontShow)]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Runtime')]
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Runtime.SendAsyncStep[]]
# SendAsync Pipeline Steps to be prepended to the front of the pipeline
${HttpPipelinePrepend},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Runtime')]
[System.Uri]
# The URI for the proxy server to use
${Proxy},

[Parameter(DontShow)]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Runtime')]
[System.Management.Automation.PSCredential]
# Credentials for a proxy server to use for the remote call
${ProxyCredential},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Category('Runtime')]
[System.Management.Automation.SwitchParameter]
# Use the default credentials for the proxy
${ProxyUseDefaultCredentials}
)

process {
$resourceIdentifier = [Microsoft.Azure.Management.Internal.Resources.Utilities.Models.ResourceIdentifier]::new($WorkspaceResourceId)
$workspaceName = $resourceIdentifier.ResourceName
$solutionName = "$Type($workspaceName)"
$PSBoundParameters.Add('Name', $solutionName) | Out-Null
$PSBoundParameters.Add('PlanName', $solutionName) | Out-Null
$PSBoundParameters.Add('PlanProduct', "OMSGallery/$Type") | Out-Null
$PSBoundParameters.Add('PlanPublisher', "Microsoft") | Out-Null
$PSBoundParameters.Add('PlanPromotionCode', "") | Out-Null
$PSBoundParameters.Remove('Type') | Out-Null
Az.MonitoringSolutions.internal\New-AzMonitorLogAnalyticsSolution @PSBoundParameters
}
}
41 changes: 41 additions & 0 deletions src/MonitoringSolutions/custom/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Custom
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.

## Info
- Modifiable: yes
- Generated: partial
- Committed: yes
- Packaged: yes

## Details
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*.

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.

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.

## Purpose
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.

## Usage
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:
- Break
- DefaultProfile
- HttpPipelineAppend
- HttpPipelinePrepend
- Proxy
- ProxyCredential
- ProxyUseDefaultCredentials

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.

### Attributes
For processing the cmdlets, we've created some additional attributes:
- `Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Models.DescriptionAttribute`
- 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.
- `Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Models.DoNotExportAttribute`
- Used in C# and script cmdlets to suppress creating an exported cmdlet at build-time. These cmdlets will *not be exposed* by `Az.MonitoringSolutions`.
- `Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Models.InternalExportAttribute`
- 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.
- `Microsoft.Azure.PowerShell.Cmdlets.MonitoringSolutions.Models.ProfileAttribute`
- Used in C# and script cmdlets to define which Azure profiles the cmdlet supports. This is only supported for Azure (`--azure`) modules.
25 changes: 25 additions & 0 deletions src/MonitoringSolutions/docs/Az.MonitoringSolutions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
Module Name: Az.MonitoringSolutions
Module Guid: ea677a1c-aecd-4441-8953-7881b5cfc8a6
Download Help Link: https://docs.microsoft.com/en-us/powershell/module/az.monitoringsolutions
Help Version: 1.0.0.0
Locale: en-US
---

# Az.MonitoringSolutions Module
## Description
Microsoft Azure PowerShell: MonitoringSolutions cmdlets

## Az.MonitoringSolutions Cmdlets
### [Get-AzMonitorLogAnalyticsSolution](Get-AzMonitorLogAnalyticsSolution.md)
Retrieves the user solution.

### [New-AzMonitorLogAnalyticsSolution](New-AzMonitorLogAnalyticsSolution.md)
Creates a log analytics solution.

### [Remove-AzMonitorLogAnalyticsSolution](Remove-AzMonitorLogAnalyticsSolution.md)
Deletes the solution in the subscription.

### [Update-AzMonitorLogAnalyticsSolution](Update-AzMonitorLogAnalyticsSolution.md)
Update the tags of a solution.

Loading