Origen de datos de sesiones inactivas de Citrix

Citrix.PresentationServer.CitrixSessionIdle.DataSource (DataSourceModuleType)

Se ocupa de detectar sesiones inactivas de Citrix cuya inactividad supera el periodo de tiempo predefinido en un equipo que ejecuta Citrix Presentation Server

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.CommandExecuterPropertyBagSource Default

Overrideable Parameters:

IDParameterTypeSelector
IntervalInSecondsint$Config/IntervalInSeconds$
MinutesIdleint$Config/MinutesIdle$

Source Code:

<DataSourceModuleType ID="Citrix.PresentationServer.CitrixSessionIdle.DataSource" Accessibility="Public" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalInSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="MinutesIdle" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalInSeconds" Selector="$Config/IntervalInSeconds$" ParameterType="int"/>
<OverrideableParameter ID="MinutesIdle" Selector="$Config/MinutesIdle$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.CommandExecuterPropertyBagSource">
<IntervalSeconds>$Config/IntervalInSeconds$</IntervalSeconds>
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//d $file/CitrixSessionIdle.js$ $Config/MinutesIdle$</CommandLine>
<TimeoutSeconds>3600</TimeoutSeconds>
<RequireOutput>false</RequireOutput>
<Files>
<File>
<Name>CitrixSessionIdle.js</Name>
<Contents><Script>
/*************************************************************************
*
*
*
*
* Copyright 2006 Citrix Systems, Inc. All Rights Reserved.
*
*************************************************************************/

var SCRIPT_NAME = "Citrix Session Idle Too Long";
CITRIX_WMI_CONNECT = "WINMGMTS:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}\\\\.\\root\\Citrix";

// event constants
var EVENT_TYPE_SUCCESS = 0;
var EVENT_TYPE_ERROR = 1;
var EVENT_TYPE_WARNING = 2;
var EVENT_TYPE_INFORMATION = 4;

var EVENT_ID = 11;

// Citrix WMI constants
var SESSION_ACTIVE = 0;

var MinutesIdle;

if ( WScript.Arguments.Unnamed.Count == 1 )
{
MinutesIdle = WScript.Arguments(0);
}
else
{
WScript.quit()
}

//Logs an error event to the event log
function logError(message, error)
{
var str = SCRIPT_NAME + ":\n" + message;

if (error)
{
var num = (error.number &lt; 0) ? (error.number + 0x100000000) : error.number;
var estr = error.description;

if (num == 0x80010105)
estr += " [RPC_E_SERVERFAULT: The server threw an exception.]";
else if (num == 0x80041001)
estr += " [WBEM_E_FAILED]";
else if (num == 0x80010108)
estr += " [RPC_E_DISCONNECTED]";
else if (num == 0x8007007e)
estr += " [ERROR_MOD_NOT_FOUND: The specified module could not be found.]";
else if (num == 0x80041010)
estr += " [WBEM_E_INVALID_CLASS]";
else if (num == 0x8004100e)
estr += " [WBEM_E_INVALID_NAMESPACE]";

if (estr == "")
estr = "&lt;error description not given&gt;";

str += ":\n\tReceived error: 0x" + num.toString(16) + ": " + estr;
}

var WshShell = new ActiveXObject("WScript.Shell");
WshShell.LogEvent(EVENT_TYPE_ERROR, str);
}

function ConvertWMITime(wmitime)
{
var year = wmitime.substring(0, 4);
var month = wmitime.substring(4, 6) - 1;
var day = wmitime.substring(6, 8);
var hour = wmitime.substring(8, 10);
var minute = wmitime.substring(10, 12);
var second = wmitime.substring(12, 14);
var UTCoffset = parseInt(wmitime.substring(21, 25), 10);

// Avoid the local time zone from confusing the issue by using the UTC
// functions to set it up.
var date = new Date(NaN);

date.setUTCFullYear(year, month, day);
date.setUTCHours(hour, minute, second, 0);

// Ensure time is actually in UTC by adjusting from their timezone.
date = new Date(date.getTime() - UTCoffset*60*1000);

return date;
}

function Main()
{
try
{
var oWMIService = GetObject(CITRIX_WMI_CONNECT);
}
catch(ex)
{
logError("Error connecting to Citrix WMI service", ex);
return;
}

try
{
var oSessions = oWMIService.ExecQuery("SELECT * FROM MetaFrame_Session");
}
catch (ex)
{
logError("WMI error retrieving Citrix session array", ex);
return;
}

var oAPI = new ActiveXObject("MOM.ScriptAPI");

// next check the idle time of active sessions and raise an event
// if it exceeds the limit given in the parameter
try
{
var idleSessions = false;
var e = new Enumerator( oSessions );
for (; !e.atEnd(); e.moveNext())
{
var session = e.item();

if (session.SessionState != SESSION_ACTIVE)
continue;

var last = ConvertWMITime(session.LastInputTime);
var now = ConvertWMITime(session.CurrentTime);

var diff = (now.getTime() - last.getTime()) / (1000 * 60);

if (diff &gt; MinutesIdle)
{
idleSessions = true;
var user = "(unknown user)";
try
{
var userobj = oWMIService.Get(session.SessionUser);
user = userobj.UserName;
}
catch (ex)
{
// Citrix WMI provider only enumerates users for local authority
// If no user found, see if can extract user info from the ref string
if ( session.SessionUser != "")
{
var wmiAuth = "AuthorityName=\\\"", wmiUser = "UserName=\"";
var sessionUser = session.SessionUser;

var userName = sessionUser.substring(sessionUser.indexOf(wmiUser) + wmiUser.length, sessionUser.indexOf("\","));
var authName = sessionUser.substring(sessionUser.indexOf(wmiAuth) + wmiAuth.length, sessionUser.indexOf("\\\","));

user = authName + "\\" + userName;
}
}

try
{
var msg = "Session " + session.SessionID + " for user " +
user + " has been idle for too long."

oAPI.LogScriptEvent(SCRIPT_NAME, EVENT_ID, EVENT_TYPE_WARNING, msg);
}
catch(ex)
{
logError("Error logging a script event", ex);
return;
}
}
}
}
catch (ex)
{
logError("WMI error retrieving Citrix session information", ex);
}

try
{
var oBag = oAPI.CreatePropertyBag();
oBag.AddValue("IdleSessions", idleSessions);
oAPI.Return(oBag);
}
catch(ex)
{
logError("Error creating property bag", ex);
return;
}
}

Main();
</Script></Contents>
<Unicode>true</Unicode>
</File>
</Files>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>