154 lines
5.9 KiB
C#
154 lines
5.9 KiB
C#
//----------------------------------------------------------------------------
|
|
//
|
|
// Copyright (c) Intel Corporation, 2011-2014 All Rights Reserved.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
using System;
|
|
using Intel.Manageability.Events;
|
|
using Intel.Manageability.Exceptions;
|
|
using System.Collections.ObjectModel;
|
|
using Intel.Manageability;
|
|
|
|
namespace PETEventsSample
|
|
{
|
|
class PETEventsFunctionality
|
|
{
|
|
/// <summary>
|
|
/// Subscribe for events
|
|
/// </summary>
|
|
/// <param name="amt">The Intel AMT instance</param>
|
|
public static void Subscribe(IAMTInstance amt)
|
|
{
|
|
//Subscribe for all events by providing the filter values
|
|
try
|
|
{
|
|
//Definition the filter values of all events
|
|
Filter filter = new Filter(255, 255, 15, 255, 0, 255, 0, 0, 28, 255);
|
|
PETSubscription subscription = new PETSubscription("192.168.0.1", filter, SenderIDType.FQDN);
|
|
amt.Events.PETEvents.Subscribe(subscription);
|
|
Console.WriteLine("\nSubscription operation by providing its filter values completed successfully");
|
|
}
|
|
catch (ManageabilityException ex)
|
|
{
|
|
Console.WriteLine("\n" + ex.Message);
|
|
}
|
|
|
|
//Subscribe for Battery_level_is_critically_low event by providig its name
|
|
try
|
|
{
|
|
|
|
//Choose the event name from Events class.
|
|
Filter filter = new Filter(Events.Battery.Battery_Level_is_Critically_Low);
|
|
PETSubscription subscription = new PETSubscription("192.168.0.1", filter, "MyAMT");
|
|
amt.Events.PETEvents.Subscribe(subscription);
|
|
Console.WriteLine("\nSubscription operation by providing the event name completed successfully.");
|
|
}
|
|
catch (ManageabilityException ex)
|
|
{
|
|
Console.WriteLine("\n" + ex.Message);
|
|
}
|
|
|
|
//Subscribe for an existing event by providig its policy ID value.
|
|
try
|
|
{
|
|
PETSubscription subscription = new PETSubscription("192.168.0.10", 28);
|
|
amt.Events.PETEvents.Subscribe(subscription);
|
|
Console.WriteLine("\nSubscription operation by providing an event policy ID completed successfully.");
|
|
}
|
|
catch (ManageabilityException ex)
|
|
{
|
|
Console.WriteLine("\n" + ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Get the number of existing subscriptions
|
|
/// </summary>
|
|
/// <param name="amt">The Intel Amt instance</param>
|
|
public static void GetNumOfSubscription(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
uint num = amt.Events.PETEvents.GetNumOfSubscriptions();
|
|
Console.WriteLine("\nThere are {0} subscribers", num);
|
|
}
|
|
catch (ManageabilityException ex)
|
|
{
|
|
Console.WriteLine("\n" + ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Get the subscriptions list
|
|
/// </summary>
|
|
/// <param name="amt">The Intel Amt instance</param>
|
|
public static void EnumerateSubscriptions(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
int index = 1;
|
|
Collection<PETSubscription> PETSubscriptionsCollection = amt.Events.PETEvents.EnumerateSubscriptions();
|
|
Console.WriteLine("\nSubscribers details:");
|
|
Console.WriteLine("---------------------");
|
|
foreach (PETSubscription PETSubscriptionItem in PETSubscriptionsCollection)
|
|
{
|
|
//Was subscribed with an event filter values / event name
|
|
if(PETSubscriptionItem.Filter != null)
|
|
Console.WriteLine("{0}-> Listener address:{1} Event ID:{2} Community string:{3}", index++,
|
|
PETSubscriptionItem.ListenerAddress.ToString(), PETSubscriptionItem.Filter.PolicyID.ToString(), PETSubscriptionItem.Sender.ToString());
|
|
//Was subscribed with an event policy ID
|
|
else
|
|
Console.WriteLine("{0}-> Listener address:{1} Event ID:{2} Community string:{3}", index++,
|
|
PETSubscriptionItem.ListenerAddress.ToString(), PETSubscriptionItem.FilterID.ToString(), PETSubscriptionItem.Sender.ToString());
|
|
}
|
|
|
|
}
|
|
catch (ManageabilityException ex)
|
|
{
|
|
Console.WriteLine("\n" + ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// UnSubscribe for specific event
|
|
/// </summary>
|
|
/// <param name="amt">The Intel AMT instance</param>
|
|
public static void UnSubscribe(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
Filter filter = new Filter(255, 255, 15, 255, 0, 255, 0, 0, 28, 255);
|
|
PETSubscription subscription = new PETSubscription("192.168.0.1", filter, SenderIDType.FQDN);
|
|
amt.Events.PETEvents.UnSubscribe(subscription);
|
|
Console.WriteLine("\nUnSubscription operation completed successfully.");
|
|
}
|
|
catch (ManageabilityException ex)
|
|
{
|
|
Console.WriteLine("\n" + ex.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Unsubscribe all exsiting subscriptions
|
|
/// </summary>
|
|
/// <param name="amt">The Intel AMT instance</param>
|
|
public static void UnSubscribeAll(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
amt.Events.PETEvents.UnSubscribeAll();
|
|
Console.WriteLine("\nUnSubscription all existing subscriptions completed successfully.");
|
|
|
|
}
|
|
catch (ManageabilityException ex)
|
|
{
|
|
Console.WriteLine("\n" + ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|