Python programs are typically stored under the following folders:
/usr/share/saltworks/saltminer-2.5.0/Utility/ : General purpose utilities that ship with SaltMiner.
The following should be done under the account svc-saltminer (using sudo su as shown below):
$ sudo su svc-saltminer
Running a custom Python Script:
From the /usr/share/saltworks/saltminer-2.5.0 su to become svc-saltminersudo su svc-saltminer
set the config_pathexport SALTMINER_2_CONFIG_PATH=/etc/saltworks/saltminer-2.5.0/
Put your python script in the the appropriate folder, for example ./Custom/Grace if the customer name was Grace
Your python script should be written as a class file that following the following pattern. It will be called from a “runner” in the next step so there won’t be any code directly executed from your python script, it will be called as part of the Run method.
#Sample Utility code showing key parts of a class file you create.
import logging
from Core.Application import Application
class SnapshotsScansHistory(object):
def __init__(self, appSettings):
'''
Setup the class
Ensure the mappings are correct
'''
self.app = Application()
logging.info("SnapshotsScansHistory starting")
self.snapshotIndex = 'app_version_snapshot_violet'
self.ESUtils = self.app.GetElasticClient()
self.__Settings = appSettings
#self.ESUtils = ElasticSearchUtils(self.app.Settings)
Create a runner like “RunCustom.py”
# Copyright (C) Saltworks Security, LLC - All Rights Reserved
# Unauthorized copying of this file, via any medium is strictly prohibited
# Proprietary and confidential
# Written by Saltworks Security, LLC (www.saltworks.io) , 2021
import logging
import traceback
from Utility.SnapshotsHistory import SnapshotsHistory
from Core.Application import Application
# Add imports here, ex:
# import Custom.SW.AppVulsWidget
try:
app = Application()
# If elastic client needed:
# es = app.GetElasticClient()
# Add custom calls here, ex:
# w = AppVulsWidget()
# w.PopulateVulsWidget()
history = SnapshotsHistory(app)
history.Run(app)
except Exception as e:
error_msg = traceback.format_exc()
print(error_msg)
logging.critical(error_msg)
Now execute the runnerpython3 RunSnapshotsHistory.py