Video Screencast Help
Symantec to Separate Into Two Focused, Industry-Leading Technology Companies. Learn more.

Online PCs and Current Logged User - Web Console

Created: 25 Feb 2011 • Updated: 26 Feb 2011 | 1 comment
HHCORP's picture
5 Agree
0 Disagree
+5 5 Votes
Login to vote

There is a way to retrieve the list of PCs that are online and their respective locally logged in user (if any) in an “almost-real-time” fashion

To set it up you need to perform three major steps:

  1. Create a Custom Data Class that holds a list of computers and users with their last time of reporting
  2. Create a Scheduled Task that runs every 5 minutes or so, that continuously updates that Data Class
  3. Create a report that displays the PCs with their respective usernames that have reported in the past 5 minutes.

1.a. For the first step I created a Custom Data Class (Settings->All Settings) named PCOnline with three attributes (Hostname, Username and TimeReported) as shown below:

1.b. While still in the above screen, select PCOnline data class and click on the little hand icon (Details). Copy the highlighted GUID for later use.

2.a. For the second step I created a task called “Send Online Data” as a VBScript that is scheduled to run on ALL managed clients every  5 minutes. I used the following advanced settings:

  • Altiris Agent credentials
  • Show script: Hidden
  • Allow other tasks to run while running this task
  • End task after 5 minutes (minimum)

The screenshot should give you an idea:

2.b. The VBScript is the following. The only thing you need to modify is to replace the GUID bolded in the script with your own that you retrieved in first step:

On Error Resume Next

'Create instance of Wbem service object, connect to namespace and run wmi query

strComputer = "."

'Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set objCIMObj = objWMIService.ExecQuery("select * from win32_computersystem")

'Create instance of Altiris NSE component and set the header data of the NSEdim nse

' The Altiris.AeXNSEvent class is installed with the inventory plugin and can be referenced externally.

set nse = WScript.CreateObject ("Altiris.AeXNSEvent")

' Please don't modify this GUID. This is the 'Inventory Capture Item'.

nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"

nse.Priority = 1

'Create Inventory data block for this dataclass.

'Specify either the name or the guid of the associated dataclass. The name is recommended.

dim objDCInstance

set objDCInstance = nse.AddDataClass ("{8e7ac459-d661-4b6a-8b5b-08172a96ca3f}")

'set objDCInstance = nse.AddDataClass ("PCOnline")

dim objDataClass

set objDataClass = nse.AddDataBlock (objDCInstance)

For each objInfo in objCIMObj

'Add a new row and set column values

dim objDataRow

set objDataRow = objDataClass.AddRow

dim DateTime

DateTime = Date() & " " & Time()

objDataRow.SetField 0, objInfo.Name

objDataRow.SetField 1, objInfo.UserName

objDataRow.SetField 2, DateTime

Next

nse.SendQueued

2.c. Create a schedule for this task to run every 5 minutes. You can increase or decrease this amount based on how often you want the managed clients to report. The shorter the interval the more accurate data you get but this will increase the load on clients, server, database and of course, the network. Play with this time interval until it fits your needs and resources.

By this time, you should have a table in the database named Inv_PCOnline that is being filled with data on a regularly basis and the number of records should not exceed your maximum number of managed PCs. If it exceeds make sure that the box in the first screenshot marked as DO NOT CHECK is NOT checked.

3.a. Now lets monitor this data in the web console. Create a new Report (Reports->Al Reports) and switch the editing mode to SQL query.

3.b. Paste the following into the query. You do not need to change anything as long as you used the same names for Data Class and Attributes in step 1.a and scheduled the task for every 5 minutes:

DECLARE @v1_TrusteeScope nvarchar(max)

   SET @v1_TrusteeScope = N'%TrusteeScope%'

SELECT

   [vri2_Computer].[Guid] AS [_ItemGuid],

   [dca3_PCOnline].[Hostname],

   [dca3_PCOnline].[Username],

   [dca3_PCOnline].[TimeReported]

FROM

   [vRM_Computer_Item] AS [vri2_Computer]

      LEFT OUTER JOIN [Inv_PCOnline] AS [dca3_PCOnline]

         ON ([vri2_Computer].[Guid] = [dca3_PCOnline].[_ResourceGuid])

WHERE

   (

      (

         (DateDiff(SS,[dca3_PCOnline].[TimeReported],{fn NOW()}) <= 400)

      )

      AND

      ([vri2_Computer].[Guid] IN (SELECT [ResourceGuid] FROM [ScopeMembership] WHERE [ScopeCollectionGuid] IN (SELECT [ScopeCollectionGuid] FROM dbo.fnGetTrusteeScopeCollections(@v1_TrusteeScope))))

   )

ORDER BY ([dca3_PCOnline].[Hostname])

Save it and you’re good to go.

OBSERVATIONS.

  1. In the SQL query there is a “400” number. This may need to be tweaked if needed. 400 is the number of seconds while the PC is considered online. 400 = 5minutesX60 sec/minute + 100sec delay. You will find that you need to insert a delay so slower online PCs will not appear and disappear constantly in the report. This really has to do with speed of server.PCs/network.
  2. If (NOW-TimeReported) is more than 400 seconds, the PC is considered offline and not shown in the report anymore.
  3.  Refresh the report as needed.
  4. You can create a complementary report PCS Offline by simply changing “<=400” to “>400”.
  5. PCs have to report at least once before they will show up in either report.  

Comments 1 CommentJump to latest comment

PatrickLunn's picture

OR,

You can go into the Jobs and Tasks Pane,  and the PC's show up blue if active,  or Black if inactive,  they also show up in the respective active or inactive groups.

0
Login to vote