How does Purge Maintenance work in NS 6.0 SP2?

book

Article ID: 180397

calendar_today

Updated On:

Products

Management Platform (Formerly known as Notification Server)

Issue/Introduction

 

Resolution

Question

How does Purge Maintenance work in NS 6.0 SP2?

Answer

Event purging section

 

In purge maintenance, these lines are run from the information stored in XML format. Also stored are the parameters that are set by you on the Purge Maintenance page (@Count, @Time). The parameter @Count is the value for "Limit computer events to [XXXX] rows". The parameter @Time is set two times. One for Purge Saved Reports, and the second is for Purge Resource Events.

delete from dbo.SavedReport where CreatedDate < @Time
exec spPurgeResourceEvent  'D0E33520-C160-11D2-8612-00104B74A9DF', @Count, @Time
exec spPurgeResourceEvent  'E81A4114-5D09-45DC-97F6-4B06F08C9AB0', @Count, @Time

This Purge Maintenance page can be found in the state column from the item table. This page information comes from the CoreSolution.config file. The stored procedure comes from the CoreDatabase.config file. Both files can be found under the Program Files\Altiris\Notification Server\Config folder.

The itemguid for Purge Maintenance is DE4A3A7C-2147-463E-8A06-A23B6C6E719B, so if you use the URL to see View as XML and replace the itemguid with this one, you can see the purge maintenance page.

http://<%NS Name%>/Altiris/NS/ItemAsXml.aspx?ItemGuid=DE4A3A7C-2147-463E-8A06-A23B6C6E719B

 

This SQL query will show you the event tables where the entries are being deleted from.

 

-- SQL query to show the event tables used in Purge Maintenance

select

vp.[Name],

ec.[DataTableName]

from [vEventClass] ec

join [vItem] it on it.[Guid] = ec.[Guid]

join [vProduct] vp on it.[ProductGuid] = vp.[guid]

where it.[ProductGuid] in (

  'D0E33520-C160-11D2-8612-00104B74A9DF',

  'E81A4114-5D09-45DC-97F6-4B06F08C9AB0'
)

order by it.[ProductGuid], ec.[DataTableName]

--

 

These are the results received when it was run:

 

Notification Server          Evt_NS_Security_Descriptor_Change

Notification Server          Evt_Push_Agent_Install_Service

Resource Management   Evt_AeX_Client_LogOn

Resource Management   Evt_AeX_Package_Server_IIS_Status

Resource Management   Evt_AeX_Package_Server_Package_Event

Resource Management   Evt_AeX_Push_Status

Resource Management   Evt_AeX_RapidInstall

Resource Management   Evt_AeX_SWD_Execution

Resource Management   Evt_AeX_SWD_Package

Resource Management   Evt_AeX_SWD_Status

Resource Management   Evt_Client_Transport_Status

Resource Management   Evt_NS_Client_Config_Generation

Resource Management   Evt_NS_Client_Config_Request

Resource Management   Evt_NS_Client_Pkg_Info_Request

Resource Management   Evt_NS_Event_History

Resource Management   Evt_NS_Event_Machine_Usage_Summary

Resource Management   Evt_NS_Event_Primary_User_Summary

Resource Management   Evt_NS_Event_Queue_Status



If you have a malformed purge maintenance page...
  1. Import the attached XML file called, "Purge Maintenance for NS6 SP2," but remember to change the extension back to XML. This is the safe method and requires that you have the permission to import an item
  2. Running the following SQL script will change the state column for the Purge Maintenance page. If you do not have the permission required to import an item, then this method can do, but this method is not as safe as the first choice. If you use this method, back up the database.

update item
set state = '<
item>
  <scheduling>
    <enabled>True</enabled><schedule><Trigger Type="1" Duration="0" Interval="0" KillAtEnd="0" Disabled="0" Description="At 2:30 AM every day, starting Wednesday, 1 January 2003"><BeginDate>2003-01-01 02:30:00</BeginDate><DaysInterval>1</DaysInterval></Trigger></schedule><sharedSchedule>{00000000-0000-0000-0000-000000000000}</sharedSchedule></scheduling>
  <purgeComputers enabled="True">
    <purgeType>Delete</purgeType>
    <duration>6</duration>
    <unit>Months</unit>
  </purgeComputers>
  <purgeEntries>
    <purgeEntry>
      <purgeConditions>Time</purgeConditions>
      <enabledPurgeConditions>None</enabledPurgeConditions>
      <count>-1</count>
      <duration>6</duration>
      <units>Months</units>
      <query><![CDATA[ delete from dbo.SavedReport where CreatedDate < @Time ]]></query>
      <textRef>Delete Saved Reports</textRef>
      <textRefLabel1>Delete Saved Reports 1</textRefLabel1>
      <textRefLabel2>Delete Saved Reports 2</textRefLabel2>
      <textRefLabel3>Delete Saved Reports 3</textRefLabel3>
      <enabled>False</enabled>
    </purgeEntry>
    <purgeEntry>
      <purgeConditions>Time, Count</purgeConditions>
      <enabledPurgeConditions>None</enabledPurgeConditions>
      <count>1000000</count>
      <duration>6</duration>
      <units>Months</units>
      <query><![CDATA[
               exec spPurgeResourceEvent ''D0E33520-C160-11D2-8612-00104B74A9DF'', @Count, @Time
               exec spPurgeResourceEvent ''E81A4114-5D09-45DC-97F6-4B06F08C9AB0'', @Count, @Time
      ]]></query>
      <textRef>Delete Resource Events</textRef>
      <textRefLabel1>Delete Resource Events 1</textRefLabel1>
      <textRefLabel2>Delete Resource Events 2</textRefLabel2>
      <textRefLabel3>Delete Resource Events 3</textRefLabel3>
      <enabled>False</enabled>
    </purgeEntry>
  </purgeEntries>
</item>'
where guid = 'DE4A3A7C-2147-463E-8A06-A23B6C6E719B'



 

Computer Purging

 

Computer purging is accomplished by a call to a .DLL and not a SQL delete statement. How NS determines what computers are to be purged is the use of a stored procedure spGetComputersToPurge. There is a SQL datetime parameter that is passed to spGetComputersToPurge, named @Time. The following is an approximate SQL query used by purge maintenance to determine what is to be purged.

 

/*

/    This is an approximate SQL query used by purge maintenance to determine which agents have not reported in x days

/    Be sure to modify the @days parameter. The default is set a 30 days.

*/

declare @days int

set @days = 30

 

select rx.[Name], cr.[Guid], dt.[LatestInventoryDate]

from [vComputerResource] cr

inner join (

            select [ResourceGuid], max([ModifiedDate]) as LatestInventoryDate

from dbo.ResourceUpdateSummary

            group by [ResourceGuid]

            ) as dt on cr.[Guid] = dt.[ResourceGuid]

inner join vResourceEx rx on rx.[Guid] = cr.[Guid]

where rx.[IsManaged] = 1

    and dt.[LatestInventoryDate] < dateadd(dd, @days * -1, getdate())

order by LatestInventoryDate desc

 But if you need to do the same thing by a script, the following can help you.

 



Note: This is an unsupported method

This is an nsscript and must be run in the Program Files\Altiris\Notification Server\bin folder.

The command line: NScript.exe %File_Name.cs%

// Delete Computers that have not reported inventory in 30 days

using System;

using System.Data;

using System.Data.SqlClient;

using System.Collections;

 

using Altiris.NS.Utilities;

using Altiris.NS.ContextManagement;

using Altiris.NS.ItemManagement;

 

class Class1

{

 

            static void Main(string[] args)

            {

                        Altiris.NS.Security.SecurityContextManager.SetContextData();

 

                        using (DatabaseContext context = DatabaseContext.GetContext())

                        {

                                    string sql = @"

                                                            declare @days int

                                                            set @days = 30

                                                            select cr.[Guid], dt.[LatestInventoryDate]

                                                            from [vComputerResource] cr

                                                            inner join (

                                                                        select [ResourceGuid], max([ModifiedDate]) as LatestInventoryDate

                                                                        from dbo.ResourceUpdateSummary

                                                                        group by [ResourceGuid]

                                                                        ) as dt on cr.[Guid] = dt.[ResourceGuid]

                                                            inner join vResourceEx rx on rx.[Guid] = cr.[Guid]

                                                            where rx.[IsManaged] = 1

                                                            and dt.[LatestInventoryDate] < dateadd(dd, @days * -1, getdate())

                                                            order by LatestInventoryDate desc";

 

                                    ArrayList list = new ArrayList();

 

                                    using (IDataReader reader = context.CreateCommand(sql).ExecuteReader())

                                    {

                                                while (reader.Read())

                                                {

                                                            list.Add(reader.GetGuid(0));

                                                }

                                    }

 

                                    IItem item = new Item();

                                    Console.WriteLine("Found " + list.Count + " Resources");

 

                                    foreach (Guid guid in list)

                                    {

                                                try

                                                {

                                                            item = Item.GetItem(guid);

                                                            Console.WriteLine("Deleting " + item.Name);

                                                            item.Delete();

                                                }

                                                catch (Exception ex)

                                                {

                                                            Console.WriteLine("Error deleting " + item.Name);

                                                            Console.WriteLine(ex.Message);

                                                }

                                    }

                        }

            }

}

Attachments

Purging Maintenance for NS6 SP2.txt get_app
PurgeEventClassTables.txt get_app
DeleteComputersFromTheNS.txt get_app
Purging Maintenance for NS6 SP2.txt get_app
PurgeEventClassTables.txt get_app
DeleteComputersFromTheNS.txt get_app