Changed folder name
This commit is contained in:
0
delete_old_clients_ds/package/LICENSE.txt
Normal file
0
delete_old_clients_ds/package/LICENSE.txt
Normal file
0
delete_old_clients_ds/package/README.txt
Normal file
0
delete_old_clients_ds/package/README.txt
Normal file
57
delete_old_clients_ds/package/app.manifest
Normal file
57
delete_old_clients_ds/package/app.manifest
Normal file
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"schemaVersion": "2.0.0",
|
||||
"info": {
|
||||
"title": "DS Add-on Delete old clients",
|
||||
"id": {
|
||||
"group": null,
|
||||
"name": "delete_old_clients_ds",
|
||||
"version": "0.0.1"
|
||||
},
|
||||
"author": [
|
||||
{
|
||||
"name": "",
|
||||
"email": null,
|
||||
"company": null
|
||||
}
|
||||
],
|
||||
"releaseDate": null,
|
||||
"description": "DS Add-on Delete old clients",
|
||||
"classification": {
|
||||
"intendedAudience": "IT Professionals",
|
||||
"categories": [
|
||||
"Security, Fraud & Compliance"
|
||||
],
|
||||
"developmentStatus": "Production/Stable"
|
||||
},
|
||||
"commonInformationModels": null,
|
||||
"license": {
|
||||
"name": null,
|
||||
"text": "LICENSE.txt",
|
||||
"uri": null
|
||||
},
|
||||
"privacyPolicy": {
|
||||
"name": null,
|
||||
"text": null,
|
||||
"uri": null
|
||||
},
|
||||
"releaseNotes": {
|
||||
"name": "README",
|
||||
"text": "README.txt",
|
||||
"uri": ""
|
||||
}
|
||||
},
|
||||
"dependencies": null,
|
||||
"tasks": null,
|
||||
"inputGroups": null,
|
||||
"incompatibleApps": null,
|
||||
"platformRequirements": null,
|
||||
"supportedDeployments": [
|
||||
"_standalone",
|
||||
"_distributed",
|
||||
"_search_head_clustering"
|
||||
],
|
||||
"targetWorkloads": [
|
||||
"_search_heads",
|
||||
"_indexers"
|
||||
]
|
||||
}
|
||||
39
delete_old_clients_ds/package/bin/delete_old_clients_ds.py
Normal file
39
delete_old_clients_ds/package/bin/delete_old_clients_ds.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import import_declare_test
|
||||
|
||||
import sys
|
||||
|
||||
from splunklib import modularinput as smi
|
||||
from delete_old_clients_ds_helper import stream_events, validate_input
|
||||
|
||||
|
||||
class DELETE_OLD_CLIENTS_DS(smi.Script):
|
||||
def __init__(self):
|
||||
super(DELETE_OLD_CLIENTS_DS, self).__init__()
|
||||
|
||||
def get_scheme(self):
|
||||
scheme = smi.Scheme('delete_old_clients_ds')
|
||||
scheme.description = 'demo_input input'
|
||||
scheme.use_external_validation = True
|
||||
scheme.streaming_mode_xml = True
|
||||
scheme.use_single_instance = False
|
||||
|
||||
scheme.add_argument(
|
||||
smi.Argument(
|
||||
'name',
|
||||
title='Name',
|
||||
description='Name',
|
||||
required_on_create=True
|
||||
)
|
||||
)
|
||||
return scheme
|
||||
|
||||
def validate_input(self, definition: smi.ValidationDefinition):
|
||||
return validate_input(definition)
|
||||
|
||||
def stream_events(self, inputs: smi.InputDefinition, ew: smi.EventWriter):
|
||||
return stream_events(inputs, ew)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
exit_code = DELETE_OLD_CLIENTS_DS().run(sys.argv)
|
||||
sys.exit(exit_code)
|
||||
@@ -0,0 +1,89 @@
|
||||
import json
|
||||
import logging
|
||||
|
||||
import import_declare_test
|
||||
from solnlib import conf_manager, log
|
||||
from splunklib import modularinput as smi
|
||||
|
||||
|
||||
ADDON_NAME = "detelete_old_clients_ds"
|
||||
|
||||
|
||||
def logger_for_input(input_name: str) -> logging.Logger:
|
||||
return log.Logs().get_logger(f"{ADDON_NAME.lower()}_{input_name}")
|
||||
|
||||
|
||||
def get_account_api_key(session_key: str, account_name: str):
|
||||
cfm = conf_manager.ConfManager(
|
||||
session_key,
|
||||
ADDON_NAME,
|
||||
realm=f"__REST_CREDENTIAL__#{ADDON_NAME}#configs/conf-detelete_old_clients_ds_account",
|
||||
)
|
||||
account_conf_file = cfm.get_conf("detelete_old_clients_ds_account")
|
||||
return account_conf_file.get(account_name).get("api_key")
|
||||
|
||||
|
||||
def get_data_from_api(logger: logging.Logger, api_key: str):
|
||||
logger.info("Getting data from an external API")
|
||||
dummy_data = [
|
||||
{
|
||||
"line1": "hello",
|
||||
},
|
||||
{
|
||||
"line2": "world",
|
||||
},
|
||||
]
|
||||
return dummy_data
|
||||
|
||||
|
||||
def validate_input(definition: smi.ValidationDefinition):
|
||||
return
|
||||
|
||||
|
||||
def stream_events(inputs: smi.InputDefinition, event_writer: smi.EventWriter):
|
||||
# inputs.inputs is a Python dictionary object like:
|
||||
# {
|
||||
# "delete_old_clients_ds://<input_name>": {
|
||||
# "account": "<account_name>",
|
||||
# "disabled": "0",
|
||||
# "host": "$decideOnStartup",
|
||||
# "index": "<index_name>",
|
||||
# "interval": "<interval_value>",
|
||||
# "python.version": "python3",
|
||||
# },
|
||||
# }
|
||||
for input_name, input_item in inputs.inputs.items():
|
||||
normalized_input_name = input_name.split("/")[-1]
|
||||
logger = logger_for_input(normalized_input_name)
|
||||
try:
|
||||
session_key = inputs.metadata["session_key"]
|
||||
log_level = conf_manager.get_log_level(
|
||||
logger=logger,
|
||||
session_key=session_key,
|
||||
app_name=ADDON_NAME,
|
||||
conf_name=f"{ADDON_NAME}_settings",
|
||||
)
|
||||
logger.setLevel(log_level)
|
||||
log.modular_input_start(logger, normalized_input_name)
|
||||
api_key = get_account_api_key(session_key, input_item.get("account"))
|
||||
data = get_data_from_api(logger, api_key)
|
||||
sourcetype = "dummy-data"
|
||||
for line in data:
|
||||
event_writer.write_event(
|
||||
smi.Event(
|
||||
data=json.dumps(line, ensure_ascii=False, default=str),
|
||||
index=input_item.get("index"),
|
||||
sourcetype=sourcetype,
|
||||
)
|
||||
)
|
||||
log.events_ingested(
|
||||
logger,
|
||||
normalized_input_name,
|
||||
sourcetype,
|
||||
len(data),
|
||||
input_item.get("index"),
|
||||
account=input_item.get("account"),
|
||||
)
|
||||
log.modular_input_end(logger, normalized_input_name)
|
||||
except Exception as e:
|
||||
log.log_exception(logger, e, "my custom error type", msg_before="Exception raised while ingesting data for demo_input: ")
|
||||
8
delete_old_clients_ds/package/bin/main.py
Normal file
8
delete_old_clients_ds/package/bin/main.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import requests
|
||||
|
||||
|
||||
class deleteClientDS():
|
||||
def __init__(self):
|
||||
deployment_server = os.getenv('SPLUNK_DS')
|
||||
splunk_username = os.getenv('SPLUNK_DS_USER')
|
||||
splunk_password = os.getenv('SPLUNK_DS_PASS')
|
||||
3
delete_old_clients_ds/package/lib/requirements.txt
Normal file
3
delete_old_clients_ds/package/lib/requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
splunktaucclib
|
||||
splunk-sdk
|
||||
solnlib
|
||||
Reference in New Issue
Block a user