Go to the table of contents Go to the previous page You are at the end of the document View or print as PDF
Code samples
Creating Remediation Scripts | Data Protection | Version 8.3.x
This section provides some code samples; some samples use DiscoveryIncidentProcessing, while some don't.
1.
2.
3.
4.
5.
6.
7.
8.
9.
This example is one of the 3 scripts that come with TRITON AP-DATA and reside in the %dss_home%/RunCommands folder. It is an example of using the DiscoveryIncidentProcessing module and is self-explanatory.
The following example is a little more involved and does the XML parsing without using the helper module - the module is useful only for discovery incidents:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
Please note several important aspects of this example:
*
*
*
*
*
*
The following example is short but very useful:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
This short piece of code simply copies the provided XML file to a temporary location - usually for debugging or further examination.
 
Note 
Lines 7-13 demonstrate how to write a remediation script that is valid on both Windows and Linux. It uses the sys.platform facility to determine the file system structure. Note that the complete string in sys.platform may be linux2, win32, etc - but the script only looks at the first few characters to make a determination.
Additional note: If you want to write multi-platform code in Python, it's best to avoid making assumptions about the environment if possible. Python helps you quite a bit in that regard by providing facilities that performs certain actions regardless of the platform you are on. A very common example is concatenating filenames and folders.
The following code is not cross-platform because it will fail on a Linux machine.
if not folderName[-1:]=='\\':
folderName+=r'\\'
pathName=folderName+fileName
Python provides a comprehensive library of path handling routines - os.path - that works regardless of the operating system the script runs on:
pathName = os.path.join(folderName,fileName)
The same applies to other operations such as splitting a path. For example, the following script:
pathParts = pathName.rsplit('/',1)
if len(pathParts)==2:
folderName,fileName=pathParts
would work just as well using:
folderName,fileName = os.path.split(pathName)
These scripts would work on both operating systems, and also cover corner cases you may not have considered (for example the input is just a folder and not a filename).

Go to the table of contents Go to the previous page You are at the end of the document View or print as PDF
Copyright 2016 Forcepoint LLC. All rights reserved.