Event
Applies To: System Center 2012 - Orchestrator, System Center 2012 R2 Orchestrator, System Center 2012 SP1 - Orchestrator
The Event entity represents events on an Orchestrator Runbook server or written by runbook instances. The Events collection includes all of the events from all of the Runbook servers in the Orchestrator environment. You can use the Events collection on a RunbooksServer entity to retrieve the events for a single Runbook server.
Properties
The following table lists the properties of the Event entity.
Name | Type | Key | Description |
---|---|---|---|
CreationTime |
DateTime |
No |
The date and time that the event was created. |
Description |
String |
No |
Detailed text included in the event. |
Id |
GUID |
Yes |
Unique identifier of the activity instance data item. |
SourceId |
GUID |
No |
Unique identifier for the source of the event. This will typically be the GUID of the runbook server with the event. |
SourceName |
String |
No |
Name of the source of the event. This will typically be the name of the runbook server with the event. |
Summary |
String |
No |
Summary of the event. |
Type |
String |
No |
Severity of the event. This will Information, Warning, or Error. |
Relationships
The following table lists the entities that share a relationship with the Job entity and the key property in each entity used to define the relationship.
Collection | Entity | Relationship | Related Entity Property | Event Entity Property |
---|---|---|---|---|
RunbookServer |
RunbookServer |
Parent |
Id |
SourceId |
Code Samples
Getting Events using C#
The following code retrieves all events since a specific date using C#. It uses a Data Services query in order to step through the different pages of jobs that are returned from the service. For more information, see Paging in Orchestrator Web Service.
This example uses a service reference named SCOService and uses the credentials of the current user context. You can uncomment the line that specifies alternate credentials if the current user does not have appropriate permissions to the runbook being started. For more information see Programming in Visual Studio With the Orchestrator Web Service and Authentication and Authorization.
namespace CodeSample.Microsoft.SystemCenter.Orchestration.WebService
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Data.Services.Client;
using SCO.SCOService;
public class SingleRunbook
{
public static void Main()
{
// Path to Orchestrator web service
string serviceRoot = "http://server01.contoso.com:81/Orchestrator2012/Orchestrator.svc";
// Create Orchestrator context
SCOService.OrchestratorContext context = new SCOData.OrchestratorContext(new Uri(serviceRoot));
// Set credentials to default or to a specific user.
context.Credentials = System.Net.CredentialCache.DefaultCredentials;
//context.Credentials = new System.Net.NetworkCredential("user", "pwd", "domain");
// Setup Data Services query
DataServiceQueryContinuation<Event> nextEventsLink = null;
try
{
// Setup the query to retrieve the events
var eventsQuery = (from evt in context.Events
where (evt.CreationTime > new DateTime(2012,3,6))
select evt) as DataServiceQuery<Event>;
// Run the initial query
QueryOperationResponse<Event> queryResponse = eventsQuery.Execute() as QueryOperationResponse<Event>;
do
{
// Keep querying the next page of jobs until we reach the end
if (nextJobsLink != null)
{
queryResponse = context.Execute(nextEventsLink) as QueryOperationResponse<Event>;
}
// Output the properties of each job on the current page to the console
foreach (Event evt in queryResponse)
{
Console.WriteLine(
"Id = {0}\n\tType = {1}\n\tCreationTime = {2}\n\tSummary = {3}",
evt.Id,
evt.Type,
evt.CreationTime,
evt.Summary);
}
} while ((nextEventsLink = queryResponse.GetContinuation()) != null);
}
catch (DataServiceQueryException ex)
{
throw new ApplicationException("An error occurred during query execution.", ex);
}
}
}
}
Getting Events using Windows PowerShell
The following code retrieves all events since a specific date using Windows PowerShell. It pages through the result in case there are more than 50 entries in the result set. The example uses the credentials of the current user context. For more information, see Paging in Orchestrator Web Service. You can uncomment the line that specifies alternate credentials if the current user does not have appropriate permissions to the runbook being started. For more information see Authentication and Authorization.
# Base URL for Events collection
$baseUrl = "http://server01.contoso.com:81/Orchestrator2012/Orchestrator.svc/Events"
# Assume maximum entries on a page to be 50
$page = 0
$pageSize = 50
do {
# Setup filter and query options and add to end of base URL for request
$skip = $page * $pageSize
$filter = "`$filter=CreationTime gt datetime'2012-03-10'"
$queryOptions = "?$filter&`$skip=$skip&`$top=$pageSize&`$inlinecount=allpages"
$url = -join ($baseUrl,$queryOptions)
$request = [System.Net.HttpWebRequest]::Create($url)
# Set the credentials to default or prompt for credentials
$request.UseDefaultCredentials = $true
# $request.Credentials = Get-Credential
# Build the request header
$request.Method = "GET"
$request.UserAgent = "Microsoft ADO.NET Data Services"
# Get the response from the request
[System.Net.HttpWebResponse] $response = [System.Net.HttpWebResponse] $Request.GetResponse()
# Write the HttpWebResponse to String
$reader = [IO.StreamReader] $response.GetResponseStream()
$output = $reader.ReadToEnd()
[xml]$output = $output
$reader.Close()
# Setup namespaces for response
$ns = New-Object Xml.XmlNamespaceManager $output.NameTable
$ns.AddNamespace( "a", "http://www.w3.org/2005/Atom")
$ns.AddNamespace( "d", "https://schemas.microsoft.com/ado/2007/08/dataservices")
$ns.AddNamespace( "m", "https://schemas.microsoft.com/ado/2007/08/dataservices/metadata")
# Get total number of entries in results so we know how many pages we need to request
$totalCount = ($output.SelectSingleNode("//m:count",$ns)).InnerText
$page += 1
# Output properties of each job in page to host
foreach ($event in $output.feed.entry)
{
Write-Host "Type = " $event.content.properties.Type
Write-Host "Creation Time = " $event.content.properties.CreationTime.InnerText
Write-Host "Summary = " $event.content.properties.Summary
}
} until (($page*$pageSize) -ge $totalCount) # Continue until all events have been displayed
See Also
Concepts
Programming Using the Orchestrator Web Service
OData Queries Using the Orchestrator Web Service
Authentication and Authorization
Paging in Orchestrator Web Service