إشعار
يتطلب الوصول إلى هذه الصفحة تخويلاً. يمكنك محاولة تسجيل الدخول أو تغيير الدلائل.
يتطلب الوصول إلى هذه الصفحة تخويلاً. يمكنك محاولة تغيير الدلائل.
ينشئ هذا البرنامج النصي اشتراكًا في شبكة الأحداث لأحداث في مجموعة موارد. يستخدم عامل تصفية للحصول على الأحداث فقط لمورد محدد في مجموعة الموارد.
إذا لم يكن لديك حساب Azure، فأنشئ حساباً مجانياً قبل أن تبدأ.
نموذج البرنامج النصي - مستقر
إشعار
نوصي باستخدام الوحدة النمطية Azure Az PowerShell للتفاعل مع Azure. للبدء، راجع تثبيت Azure PowerShell. لمعرفة كيفية الترحيل إلى الوحدة النمطية Az PowerShell، راجع ترحيل Azure PowerShell من AzureRM إلى Az.
# Provide an endpoint for handling the events. Must be formatted "https://your-endpoint-URL"
$myEndpoint = "<your-endpoint-URL>"
# Provide the name of the resource group to create. It will contain the network security group.
# You will subscribe to events for this resource group.
$myResourceGroup = "<resource-group-name>"
# Provide a name for the network security group to create.
$nsgName = "<your-nsg-name>"
# Create the resource group
New-AzResourceGroup -Name $myResourceGroup -Location westus2
# Create a network security group. You will filter events to only those that are related to this resource.
New-AzNetworkSecurityGroup -Name $nsgName -ResourceGroupName $myResourceGroup -Location westus2
# Get the resource ID to filter events. The name of the network security group must not be the same as the other resource names.
$resourceId = (Get-AzResource -ResourceName $nsgName -ResourceGroupName $myResourceGroup).ResourceId
# Subscribe to the resource group. Provide the name of the resource group you want to subscribe to.
New-AzEventGridSubscription `
-Endpoint $myEndpoint `
-EventSubscriptionName demoSubscriptionToResourceGroup `
-ResourceGroupName $myResourceGroup `
-SubjectBeginsWith $resourceId
نموذج البرنامج النصي - وحدة المعاينة
هام
يتطلب استخدام ميزة Azure هذه من PowerShell تثبيت الوحدة النمطية AzureRM . هذه وحدة نمطية قديمة متوفرة فقط في إصدار ويندوز PowerShell 5.1 التي لم تعد تتلقى ميزات جديدة.
الوحدتان AzوAzureRMغير متوافقتين عند تثبيتهما لنفس إصدارات PowerShell.
إذا كنت بحاجة إلى كلا الإصدارين:
- إلغاء تثبيت الوحدة النمطية Az من جلسة عمل PowerShell 5.1.
- تثبيت الوحدة النمطية AzureRM من جلسة عمل PowerShell 5.1.
- قم بتنزيل PowerShell Core 6.x أو أحدث وتثبيته.
- تثبيت الوحدة النمطية Az في جلسة عمل PowerShell Core.
نموذج البرنامج النصي للمعاينة يتطلب الوحدة النمطية "شبكة الأحداث". للتثبيت، ما عليك سوى التشغيل Install-Module -Name AzureRM.EventGrid -AllowPrerelease -Force -Repository PSGallery
# You must have the latest version of the Event Grid PowerShell module.
# To install:
# Install-Module -Name AzureRM.EventGrid -AllowPrerelease -Force -Repository PSGallery
# Provide an endpoint for handling the events. Must be formatted "https://your-endpoint-URL"
$myEndpoint = "<your-endpoint-URL>"
# Provide the name of the custom topic to create
$topicName = "<your-topic-name>"
# Provide the name of the resource group to create. It will contain the custom topic.
$myResourceGroup= "<resource-group-name>"
# Create the resource group
New-AzResourceGroup -Name $myResourceGroup -Location westus2
# Create custom topic
New-AzEventGridTopic -ResourceGroupName $myResourceGroup -Location westus2 -Name $topicName
# Get resource ID of custom topic
$topicid = (Get-AzEventGridTopic -ResourceGroupName $myResourceGroup -Name $topicName).Id
# Set the operator type, field and values for the filtering
$AdvFilter1=@{operator="StringIn"; key="Data.color"; Values=@('blue', 'red', 'green')}
# Subscribe to the custom topic. Filter based on a value in the event data.
New-AzEventGridSubscription `
-ResourceId $topicid `
-EventSubscriptionName demoSubWithFilter `
-Endpoint $myEndpoint `
-AdvancedFilter @($AdvFilter1)
شرح السيناريو
يستخدم هذا البرنامج النصي الأمر التالي لإنشاء اشتراك الحدث. يرتبط كل أمر في الجدول بالوثائق الخاصة بالأوامر.
| الأمر | ملاحظات |
|---|---|
| New-AzEventGridSubscription | إنشاء اشتراك Event Grid. |
الخطوات التالية
- للحصول على مقدمة للتطبيقات المدارة، راجع نظرة عامة حول التطبيقات المدارة من Azure.
- لمزيد من المعلومات حول PowerShell، راجع Azure PowerShell documentation".