6.9 KiB
How-to-fix-broken-SLT-data-via-Python-script_686074161
Introduction
This script will fix SLT issues for Request & Incident in the following 4 scenarios:
- Tickets have empty SLT information.
- Tickets have super large or negative SLT values.
- Tickets have been suspended but the SLT is still being calculated.
- Tickets have wrong/empty values for their SLA status.
Note: This script applies to SMAX versions from 2022.05 to 25.2. Back up your data before running this script.
Resolution
-
Install python v3.8 (https://www.python.org/downloads/source/) or above on the control plane node.
-
Run the following DB query in the xservices_ems database to collect any customized Enum Items in the customer’s environment. SELECT * FROM enum_value_ WHERE enumeration_descriptor_name in ('ImpactScopeEnum','SawPriority','SLTStatus','TargetType','AgreementUsage', 'DefinitionCalculationPolicy', 'RequestStatusEnum', 'IncidentStatusEnum');
-
Based on the result of step 2, update the script from Line 108 to 148. Pick up the customized content, then add them into the last line of each class. Here is the template script.fixslt2_20231129.zip
For example, in the following case, you can insert “P1_c=20129” into the last line of the SawPriority class.

-
Based on the result of step 2, check the result of 'RequestStatusEnum' & 'IncidentStatusEnum', go to web > Studio > Request/Incident > Process and Rules, use the response as a keyword and search them in the rules. If they are used in the rule related to suspend status, then they need to be added to Line 181 & 182 for each record type.
-
Prepare the following parameters for the environment, they will be used for input when you execute the script. SMAX web information.
Hostname;
Port;
Username;
Password;
DB Credential information.
DB username;
DB password;
DB host;
DB port;
Entity type(currently we only support Request & Incident);
Start time;
Tenant ID; -
Prepare the ticket IDs to be fixed by executing the following DB query in xservices_ems.
Use the “copy to” command to save the result into the target folder.
For example: copy (#1 SELECT COMMAND) to ‘/tmp/request_ids.txt
(Note: Fill in the record type and update the creation time value before execution.)-
The following query is to filter out all tickets without SLT target data. SELECT entity_id FROM entities_<tenant_id> where entity_type_id = (select distinct id from entity_descriptor where localization_key = '<entity_type>') and creation_time >= 1675180800000
EXCEPT
SELECT parent_id FROM slt_targets_<tenant_id> WHERE parent_id IN (SELECT entity_id FROM entities_<tenant_id> where entity_type_id = (SELECT distinct id FROM entity_descriptor WHERE localization_key = '<entity_type>') and creation_time >= 1675180800000) GROUP BY parent_id; 2. The following query is to filter out all tickets whose SLT calculations with super large values. SELECT parent_id from
(SELECT * from slt_targets_ where parent_id in (SELECT entity_id FROM entities_ where entity_type_id = (select distinct id from entity_descriptor where localization_key = '<entity_type>') and creation_time >= 1680278400000)) s
WHERE (elapsed_duration > 31536000 or elapsed_duration_min > 525600) group by parent_id; Note: The value of elapsed_duration is in seconds and elapsed_duration_min is in minutes. The example above filters out a duration that is longer than 365 days. You may set different values according to your business needs.
The following query is to filter out all tickets whose SLT calculations with negative values. SELECT parent_id from
(SELECT * from slt_targets_<tenant_id> WHERE parent_id in (SELECT entity_id FROM entities_<tenant_id> WHERE entity_type_id = (select distinct id from entity_descriptor WHERE localization_key = '<entity_type>') and creation_time >= 1675180800000)) s
WHERE (elapsed_duration < 0 or elapsed_duration_min < 0) group by parent_id; 3. The following query is to filter out all closed tickets but their SLT is still being calculated. SELECT distinct physical_type_name as close_time_field FROM entitydescriptor_mapping WHERE entity_type='<entity_type>' and logical_type_name='CloseTime';
note: query field name of 'CloseTime', and the query result will be applied to the <CloseTime_field>
SELECT parent_id FROM slt_record_status_<tenant_id> WHERE parent_id IN (SELECT entity_id FROM entities_ where entity_type_id = (select distinct id from entity_descriptor where localization_key = '') and creation_time >= 1675180800000 and <CloseTime_field> is not NUll) and status not in (100, 400); 4. The following query is to filter out all tickets whose SLA Overall status value is NULL. SELECT parent_id FROM slt_record_status_<tenant_id> WHERE parent_id IN (SELECT entity_id FROM entities_<tenant_id> where entity_type_id = (select distinct id from entity_descriptor where localization_key = '') and creation_time >= 1675180800000) and sla_status is null;
-
-
Copy the updated fixSlt script and the attached triageslt.py into the same folder with request_ids.txt and give the folder full permission via the following command: chmod 777 -R
-
Run the following command to execute the triageslt script to collect the SLT related tables data before the fixSlt script is run for the problematic request IDs given in the request_ids.txt and the results of the script execution is written into the triageslt.log file.
python3 triageslt.pyNOTE: On script run with the above command, it prompt the user to enter the required details. If we want to avoid entering the values each time, then we can hardcode the required parameter values in the script and then run which will then read the hardcoded values.
-
Run the following command to start the fix script and input the parameter in step 5. python3 fixslt2.py
-
After the fixing work is finished, save the log file “fix_slt.log” in the same level directory, it will record the operation with all tickets fixed by the script.
-
Run the following command to execute the triageslt script to collect the SLT related tables data after the fixSlt script is run for the problematic request IDs given in the request_ids.txt and the results of the script execution is appended into the triageslt.log file created in the step 8 above.
python3 triageslt.py -
Share the triageslt.log and fix_slt.log files to RnD via CPE engineer for the further troubleshooting of the SLT problem reported.