How to delete Retired Devices in Performance Management

Document ID : KB000126434
Last Modified Date : 08/02/2019
Show Technical Document Details
Introduction:
Once a Device is set to a Retired state, if the old historic data is unwanted, it is beneficial to system health to remove them from the system.

When also regularly running the remove_not_present_items.sh script to delete retired component items, first deleting retired devices may improve the time it takes for the  remove_not_present_items.sh script to complete. Deleting the device parent, deletes related items, and often will greatly reduce the retired item count pending deletion.
Background:
Provides a simple method to list the internal IDs representing Retired Devices to simply their removal via a deletion script.
Environment:
All supported Performance Management releases.
Instructions:
The steps involved are:
  1. Identify the Data Aggregator Data Source ID.
  2. Create the list of IDs for the Retired Devices.
  3. Run the script to delete the IDs in the resulting list.
To execute the steps complete the following:

1: Enter the CLI on the PC server and go to the (default path) /opt/CA/MySql/bin directory. Run the following command as the root, or sudo root user, that owns the installation:​​​​
./mysql -unetqos -pnetqos netqosportal -e "select sourceid from data_sources2 where sourcetype='262144';"
For example:
./mysql -unetqos -pnetqos netqosportal -e "select sourceid from data_sources2 where sourcetype='262144';"
mysql: [Warning] Using a password on the command line interface can be insecure.
+----------+
| sourceid |
+----------+
|        3 |
+----------+

2: Take the SourceID value from step 1 and run the following command. Change the directory, and filename the ID's are written to, as desired.

./mysql -unetqos -pnetqos netqosportal -e "select localid from dst_device where sourceid = '<ID>' and itemid in (select itemid from t_device where lifecyclestate='RETIRED');" > /tmp/retiredLocalIdsToDelete.out
 
HINT: To determine the number of ID values in the resulting file run "wc -l <filename>".

For example using the sample output from step 1 it might look like:
 
./mysql -unetqos -pnetqos netqosportal -e "select localid from dst_device where sourceid = '3' and itemid in (select itemid from t_device where lifecyclestate='RETIRED');" > /tmp/retiredLocalIdsToDelete.out


3: Place the script attached to this article, deleteAllDevicesInFile.pl, on the PC server where the ID list file was created in step 2. Make the script executable (chmod +x <fileName>). Run it as follows:
deleteAllDevicesInFile.pl [-da server] [-p httpsport] [-b batchsize] [-sl sleepSeconds] -f file

For example for DA named myda.company.com, using default non-https configs it might be:
 
deleteAllDevicesInFile.pl -da myda.company.com -f /tmp/retiredLocalIdsToDelete.out

Using SSL enabled DA it might be (example port):
 
deleteAllDevicesInFile.pl -da myda.company.com -p 8443 -f /tmp/retiredLocalIdsToDelete.out

By default the script will delete the items in batches of 500.
Additional Information:
  1. The script supports HTTPS enabled Data Aggregator servers running r3.6 or newer releases.
  2. The deletions take place on the Data Repository via the Data Aggregator REST Services. Before we can expect to see results in PC Inventory a DA Update Sync cycle, followed by a subsequent PC Global Sync Cycle must be completed.
  3. Run this before remove_not_present_items to lower the number of items it must work with and speed it's execution.
File Attachments:
deleteAllDevicesInFile.zip