IT Management Suite

 View Only
  • 1.  Create a Client Job or Script Task using the SDK?

    Posted May 04, 2018 10:48 AM

    Does anyone have any information on creating a Client Job or a client script task using the SDK?

    ItemManagement exposes a number of options for executing tasks, cloning, etc. but there is nothing exposed to create a task or a job.

    The only option I can see is Import-ItemXmlFile:

     

    ImportItemXmlFile
    Imports an item definition Xml file into the NS
    ImportItemXmlFiles
    Imports all xml files within the a directory. Each of these xml files must contain valid xml item(s) defintions
    ImportItemXmlString
    Imports an item definition into the NS. 

     

    But the format of the XML is not well documented.

    I'm thinking I'll need to create a blank task, clone it and then manipulate the XML data in the SQL record in ItemVersionData but that is not an elligant solution.

    Any other ideas anyone? Anyone try scripting up creating client jobs and client script tasks before?

     



  • 2.  RE: Create a Client Job or Script Task using the SDK?

    Broadcom Employee
    Posted May 04, 2018 04:35 PM

    Hi,

    Please take a look at c# code used to create script tasks with schedules. I cannot guarantee it will work in all circumstances, but maybe you may find it useful somehow.

    Thank you,

    Alex.

     

    //reference Altiris.Common;
    //reference Altiris.NS;
    //reference Altiris.TaskManagement;
    //reference Altiris.TaskServerTasks;
    //reference Altiris.TaskManagement.Common;
    //reference Altiris.DotNetLib;
    //using Altiris.Common;
    //using Altiris.NS.Configuration;
    //using Altiris.NS.Security;
    //using Altiris.TaskManagement.UI;
    //using Altiris.TaskServerTasks.ScriptTask;
    //using Altiris.TaskManagement.Common;
    //using Altiris.TaskManagement.Common.ClientTask;
    //using Altiris.NS.ItemManagement;
    
    // number of tasks to generate
    const int n = 2;
    
    // number of tasks-schedules to generate
    const int x = 5;
    
    const string taskName = "task_";
    
    // create parent folder
    JobsAndTasksFolder folder = new JobsAndTasksFolder();
    folder.Name = "Folder " + n + " tasks and with " + x + "schedules for each task tasks . " + DateTime.Now;
    // Altiris Task Management
    folder.Create( Altiris.TaskManagement.Constants.Guids.Product );
    // Jobs and Tasks
    folder.MoveToFolder( new Guid( "455ae0db-ec74-455b-b262-89421c96908d" ) );
    Console.WriteLine("Folder: " + folder.Guid + " is created.");
    // common remote advanced properties
    RemoteExecClientTaskAdvancedProperties remoteExecClientTaskAdvancedProperties = new RemoteExecClientTaskAdvancedProperties();
    remoteExecClientTaskAdvancedProperties.Priority = ClientTaskPriority.Normal;
    remoteExecClientTaskAdvancedProperties.TaskCompatibility = ClientTaskCompatibility.Inclusive;
    remoteExecClientTaskAdvancedProperties.KillTaskAfterMaxMinutes = true;
    remoteExecClientTaskAdvancedProperties.MaxRunTimeInMinutes = 30;
    remoteExecClientTaskAdvancedProperties.Interruptable = RemoteExecClientTaskAdvancedProperties.TaskInterruptabilityStatus.DEFAULT;
    remoteExecClientTaskAdvancedProperties.ConfiguredPlatformProviderGuid = Guid.Empty;
    // assigned resources for schedule (add some or just leave it to run only on NS)
    GuidCollection assignedResources = new GuidCollection();
    // NS Guid
    //assignedResources.Add( Core.NSResourceGuid );
    assignedResources.Add( new Guid("5A338ADC-3101-4125-9AF6-5AA0F5F654D2" ));
    
    /*
    // add another resource Guids
    assignedResources.Add( new Guid( "6b44c53c-2c61-4fda-950f-2a38528ca743" );
    assignedResources.Add( new Guid( "4fd6ca28-f044-4ff1-85df-caa986ab25c7" );
    */
    // schedule Xml (modify it apporpriately)
    // Single Schedule
    string scheduleXml = "<schedule tz=\"Local\" start=\"2017-06-08 11:00:00 \"><trigger type=\"Once\" exact=\"False\" at=\"17:05:00\" /></schedule>";
    // Reapeat Schedule
    //string scheduleXml = "<schedule tz=\"Local\" start=\"2013-11-07 16:54:00 \"><trigger type=\"Once\" exact=\"True\" at=\"16:54:00\" duration=\"1.00:00:00\" repetition=\"00:01:00\" frequency=\"1\" /></schedule>";
    
    // create script tasks 
    for(int i = 1; i <= n; i++)
    {
          // create task
          ScriptTask scriptTask = Item.CreateItem<ScriptTask>( Altiris.TaskManagement.Constants.Guids.TaskServerTasksProduct );
          scriptTask.Name = taskName + i;
          scriptTask.ScriptText = "exit 0";
          scriptTask.RemoteAdvancedProperties = remoteExecClientTaskAdvancedProperties;
          scriptTask.Save();
          
          // Task Server Core Tasks
          scriptTask.MoveToFolder( folder.Guid );
          
          // Altiris Task Management
          for(int xx = 1; i <= x; xx++)
    	{
          TaskSchedule sched = Item.CreateItem<TaskSchedule>( Altiris.TaskManagement.Constants.Guids.Product );
          // setup
          sched.Name = scriptTask.Name + " Schedule";
          sched.TaskToRunGuid = new TaskVersionGuid( scriptTask.Guid );
          sched.ScheduleEnabled = true;
          //sched.ScheduleXml = scheduleXml;
          sched.UserRoles = SecurityTrusteeManager.GetCurrentUserMemberships();
          sched.TaskInputParameterValues.Add( "@AssignedResources", assignedResources );
          sched.ScheduleXml = scheduleXml;
          sched.Save();
         }
    }
    Console.WriteLine( n + " script tasks are created." );

     



  • 3.  RE: Create a Client Job or Script Task using the SDK?

    Posted May 05, 2018 04:31 PM
    One option is to use Workflow. There’s a great article which shows you the XML needed to build up your own task. Creating/Importing/Executing NS Tasks via Workflow https://www.symantec.com/connect/articles/creatingimportingexecuting-ns-tasks-workflow Even if you don’t use WF hopefully this should help you better understand the XML needed to pass to the Web service. Try right-click exporting (or view as XML) a Task from the NS to see the make up.