How to find a task's execution status


Article ID: 181437


Updated On:


Management Platform (Formerly known as Notification Server) Inventory Solution for Unix/Linux Inventory Solution Inventory Solution for Mac





Overview of the relationships between the task item record and the tables showing the task execution status results: 
  1. The 'item' record contains the task name.
  2. Each task (item) record may have one or more versions in the 'itemversions' table. If a change is made to a task, a new version record is is created. The most recent (max) version may need to be identified in any sql script.
  3. Each 'itemversions' record is related to a 'taskinstances' record (the TaskInstances records contain a TaskVersionGuid). A task instance is created each time a task executes. The most recent instance may need to be identified in any sql script. 
  4. The taskinstances records contain the relationship to the 'taskinstancestatus' and 'taskinstanceresults', which indicate if a task succeeded, failed, etc.
Relationships among the various task-related tables: 
Item.Guid        -> ItemVersions.ItemGuid
Item.Guid         -> ItemClass.Guid
ItemClass.Guid         -> Class.Guid
ItemVersions.VersionGuid          -> TaskInstances.TaskVersionGuid
TaskInstances.ResourceGuid -> vcomputer.Guid
TaskInstances.ResourceGuid -> inv_aex_ac_identification._ResourceGuid
TaskInstances.TaskInstanceGuid -> TaskInstanceStatus.TaskInstanceGuid 
TaskInstances.TaskInstanceGuid -> TaskInstanceResults.TaskInstanceGuid
Sample SQL query to find task status for two specific classes of tasks: 



 -- Find tasks by class type; show instances, versions, end times and statuses

Declare @TaskName varchar(255)
Declare @ComputerName varchar(255)
Set @TaskName = '%'
Set @ComputerName = '%'
select  vc.guid 'Client GUID'
, 'Client Name'
, c.type 'Class Type'
, i.guid 'Task Guid'
, 'Task name'
, ti.TaskInstanceGuid 'Instance Guid'
, iv.Version 'Instance Version'
, tir.endtime 'Instance EndTime'
, case tis.instancestatus
when 0 then 'Not started'
when 1 then 'Started'
when 2 then 'Completed'
when 3 then 'Failed'
when 4 then 'Stop Requested'
else 'unknown'
 end 'Instance Status'
  from ItemClass ic
  join class c on ic.guid = c.guid 
  join item i on i.guid = ic.guid
  join itemversions iv on iv.itemguid = i.guid
  join taskinstances ti on ti.taskversionguid = iv.versionguid
  join vcomputer vc on ti.resourceguid = vc.guid
  left join taskinstancestatus tis on tis.taskinstanceguid = ti.taskinstanceguid
  left join taskinstanceresults tir on tir.taskinstanceguid = ti.taskinstanceguid
  where [classGuid] in 
('3CB6424C-6B59-4C19-8ACE-1E12D265CEC3', -- Altiris.Inventory.InventoryTask
'4F1B9B32-B5C6-4D83-8992-F73582217AAC')  -- Altiris.TaskServerTasks.ScriptTask.ScriptTask
    and like @TaskName
    and like @ComputerName
  order by,, iv.version, tir.endtime
For Unix, Linux and Mac (ULM) tasks, the following commands will show the task version and instance IDs for use in SQL queries: 
aex-cta list --show-task-id     
      -->  This command returns the "Task Definition Version ID"
aex-cta list C34A7A27-AD28-4481-B1AB-24C62944F118  
     --> The guid here is the "Task Definition Version ID". This command returns each "Task Execution instance ID"
aex-cta info C34A7A27-AD28-4481-B1AB-24C62944F118 C164DDB0-FE90-4346-BC59-B543FAE235F1  
     --> The guids here are the "Task Definition Version ID" and one specific "Task Execution instance ID". This command returns task instance execution dates, statuses, etc. 
The "Task Definition Version ID", from the output of the above commands, may be found in the ItemVersions.VersionGuid field in the database. The corresponding ItemVersions.ItemGuid is the actual task guid which corresponds to the Item.ItemGuid value. 
Once the 'Task Definition Version ID" is found, the following query will show the task guid and name: 
select i.guid,
  from item i
  join itemversions iv on iv.itemguid = i.guid
  where iv.versionguid = '<Task Definition Version ID>'