| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Log PSRule analysis results to Azure Monitor.
Note
This module is being migrated into https://github.com/microsoft/PSRule and this repository will be archived in the future. The functionality of this module will be included PSRule in a future release. This repository currently reflects functionality as a standalone module.
You may still continue to download and use this module from source or the PowerShell Gallery, but it will not receive any further updates or support.
Please log any new issues at https://github.com/microsoft/PSRule/issues
This project requires the PSRule PowerShell module. For detail on installation and dependencies see install.
You can download and install these modules from the PowerShell Gallery.
| Module | Description | Downloads / instructions |
|---|---|---|
| PSRule.Monitor | Log PSRule analysis results to Azure Monitor. | latest / instructions |
A convention can be used to upload the results of a PSRule analysis to Azure Monitor. To use the convention:
For example:
include:
module:
- 'PSRule.Monitor'
convention:
include:
- 'Monitor.LogAnalytics.ImportWhen using the convention a Log Analytics workspace must be specified. This can be done by setting the following environment variables:
For example:
# PowerShell: Setting environment variable
$Env:PSRULE_CONFIGURATION_MONITOR_WORKSPACE_ID = '00000000-0000-0000-0000-000000000000'
$Env:PSRULE_CONFIGURATION_MONITOR_WORKSPACE_KEY = Get-Secret -Name 'WORKSPACE_KEY' -AsPlainText# GitHub Actions: Setting environment variable with microsoft/ps-rule action
- name: Run PSRule analysis
uses: microsoft/ps-rule@main
env:
PSRULE_CONFIGURATION_MONITOR_WORKSPACE_ID: 00000000-0000-0000-0000-000000000000
PSRULE_CONFIGURATION_MONITOR_WORKSPACE_KEY: ${{ secrets.WORKSPACE_KEY }}# Azure Pipelines: Setting environment variable with ps-rule-assert task
- task: ps-rule-assert@0
displayName: Run PSRule analysis
inputs:
inputType: repository
env:
PSRULE_CONFIGURATION_MONITOR_WORKSPACE_ID: 00000000-0000-0000-0000-000000000000
PSRULE_CONFIGURATION_MONITOR_WORKSPACE_KEY: $(WORKSPACE_KEY)To upload results from PSRule to Azure Monitor, use the Send-PSRuleMonitorRecord cmdlet. Results can by piped directly from Invoke-PSRule or stored and piped from a variable.
The Send-PSRuleMonitorRecord cmdlet requires a Log Analytics workspace to send data to. A workspace can be specified by using the -WorkspaceId and -SharedKey parameters.
For example:
$data | Invoke-PSRule | Send-PSRuleMonitorRecord -WorkspaceId <workspaceId> -SharedKey <primaryKey>;The following example shows using analysis results from a pre-built module:
$results = Invoke-PSRule -InputPath .\*.json -Module 'PSRule.Rules.Azure';
$results | Send-PSRuleMonitorRecord -WorkspaceId <workspaceId> -SharedKey <primaryKey>;By default, PSRule results are stored in the PSRule_CL table. The results can be queries from the Log Analytics workspace using Kusto.
The following query returns all rule records from the last hour that failed:
PSRule_CL
| where Outcome_s == "Fail" and TimeGenerated > ago(1h)To query these results from PowerShell use:
Invoke-AzOperationalInsightsQuery -WorkspaceId <workspaceId> -Query 'PSRule_CL | where Outcome_s == "Fail" and TimeGenerated > ago(1h)'The following commands exist in the PSRule.Monitor module:
This project welcomes contributions and suggestions. If you are ready to contribute, please visit the contribution guide.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
This project is licensed under the MIT License.
| Back | FazBrowse Home | New Git URL |