diff --git a/.circleci/config.yml b/.circleci/config.yml index 827d534f1..0a1c43f97 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -63,6 +63,44 @@ jobs: name: Install Tools command: | pip install /tmp/workspace/dist/* --use-deprecated=legacy-resolver + + semgrep: + environment: + SEMGREP_REPO_URL: << pipeline.project.git_url >> + SEMGREP_BRANCH: << pipeline.git.branch >> + docker: + - image: returntocorp/semgrep-agent:v1 + user: root + resource_class: large + steps: + - checkout + - run: + name: "Install Dependencies" + command: | + pip3 install --upgrade semgrep + - run: + name: "Semgrep Scan" + no_output_timeout: 2h + command: | + export SEMGREP_REPO_NAME=splunk/${CIRCLE_PROJECT_REPONAME} + python -m semgrep_agent --publish-deployment ${SEMGREP_DEPLOYMENT_ID} --publish-token ${SEMGREP_PUBLISH_TOKEN} + # Generate the Semgrep Dashboard URL + export REPO_BRANCH=$(echo "<< pipeline.git.branch >>") + DASHBOARD_URL=$(python3 -c "from urllib.parse import quote; import os; print('https://semgrep.dev/manage/findings?repo=' + quote(os.environ['SEMGREP_REPO_NAME'], safe='') + '&tab=findings&ref_type=branch&ref=' + quote(os.environ['REPO_BRANCH'], safe=''))") + echo "View Result at Semgrep Dashboard: $DASHBOARD_URL" + + # Semgrep Exclude files + dos2unix .semgrepignore + SEMGREP_EXCLUDE=$(sed "/^#/d" .semgrepignore | sed "/^:/d" | sed -r '/^\s*$/d' | sed ':a;N;$!ba;s/\n/ --exclude /g') + echo "Excluding Semgrep Files: --exclude $SEMGREP_EXCLUDE" + # Generate xml file + semgrep --config="p/r2c-ci" --config="p/r2c-security-audit" --config="p/bandit" --error --strict --timeout=0 --junit-xml -o /root/project/test-results/semgrep-scan.xml --exclude $SEMGREP_EXCLUDE + - store_artifacts: + path: test-results + destination: test-results + - store_test_results: + path: test-results + release: docker: - image: circleci/node:12 @@ -124,6 +162,12 @@ workflows: build_test: jobs: - build + - semgrep: + context: + - gdi-semgrep + filters: + branches: + only: /.*/ - test: requires: - build diff --git a/.semgrepignore b/.semgrepignore new file mode 100644 index 000000000..76b15b0d7 --- /dev/null +++ b/.semgrepignore @@ -0,0 +1,30 @@ +## Default semgrep ignore +# Ignore git items +.gitignore +.git/ +:include .gitignore + +# Common large directories +node_modules/ +build/ +dist/ +vendor/ +env/ +.env/ +venv/ +.venv/ +*.min.js + +# Common test directories +test/ +tests/ + +# Semgrep rules folder +.semgrep + +## Additional files to be ignored +.circleci/ +.github/ +.reuse/ +.vscode/ +.idea/ diff --git a/deps/build/addonfactory_test_matrix_splunk b/deps/build/addonfactory_test_matrix_splunk index a1fb9747b..2d51a1ded 160000 --- a/deps/build/addonfactory_test_matrix_splunk +++ b/deps/build/addonfactory_test_matrix_splunk @@ -1 +1 @@ -Subproject commit a1fb9747b30ac7357d767c23208d925244ffd13d +Subproject commit 2d51a1ded1dda479aba8e054b80dc43fde2f0c1d diff --git a/poetry.lock b/poetry.lock index 2865aa9b7..a9b769b38 100644 --- a/poetry.lock +++ b/poetry.lock @@ -96,7 +96,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [[package]] name = "dunamai" -version = "1.5.0" +version = "1.5.4" description = "Dynamic version generation" category = "main" optional = false @@ -408,7 +408,7 @@ dev = ["pre-commit", "tox"] [[package]] name = "poetry-dynamic-versioning" -version = "0.12.0" +version = "0.12.4" description = "Plugin for Poetry to enable dynamic versioning based on VCS tags" category = "dev" optional = false @@ -479,22 +479,34 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" py = "*" pytest = ">=3.10" +[[package]] +name = "pytest-ordering" +version = "0.6" +description = "pytest plugin to run your tests in a specific order" +category = "dev" +optional = false +python-versions = "*" + +[package.dependencies] +pytest = "*" + [[package]] name = "pytest-splunk-addon" -version = "1.3.12" +version = "1.6.0" description = "A Dynamic test tool for Splunk Apps and Add-ons" category = "dev" optional = false python-versions = ">=3.7,<4.0" [package.dependencies] -faker = ">=4.1,<5.0" +faker = ">=4.1,<6.0" filelock = ">=3.0,<4.0" httplib2 = "*" jsonschema = ">=3.2,<4.0" -junitparser = "*" +junitparser = "<2.0.0" lovely-pytest-docker = {version = ">=0,<1", optional = true, markers = "extra == \"docker\""} pytest = ">5.4.0,<6.1" +pytest-ordering = "*" pytest-xdist = "*" requests = ">=2,<3" splunk_appinspect = ">=2,<3" @@ -587,7 +599,7 @@ socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"] [[package]] name = "reuse" -version = "0.11.1" +version = "0.12.1" description = "reuse is a tool for compliance with the REUSE recommendations." category = "main" optional = false @@ -699,7 +711,7 @@ sortedcontainers = ">=2.2,<3.0" [[package]] name = "splunktaucclib" -version = "4.0.12" +version = "4.1.0" description = "" category = "main" optional = false @@ -763,7 +775,7 @@ testing = ["pytest (>=3.5,!=3.7.3)", "pytest-checkdocs (>=1.2.3)", "pytest-flake [metadata] lock-version = "1.1" python-versions = "^3.7" -content-hash = "2d0b830e44b1f4e5e3ce42d45e826b214a3f8127c1ec1bb9826ade6f08ec55cb" +content-hash = "e415acff7634d30a4701566b7c5cf2e1d7872afc81ab29e28e04c27cf3b2500f" [metadata.files] apipkg = [ @@ -808,8 +820,8 @@ colorama = [ {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, ] dunamai = [ - {file = "dunamai-1.5.0-py3-none-any.whl", hash = "sha256:1f256e09537986a8b413ee0de9e7f1f264608407429fe17031b71c733b197ce4"}, - {file = "dunamai-1.5.0.tar.gz", hash = "sha256:0424b86ae37a6f23c480adb985b89866b71b3d9bde221bbd119060eef48315ed"}, + {file = "dunamai-1.5.4-py3-none-any.whl", hash = "sha256:0edbc8c37484b2db7c54b70de88c2b6ce866890440fc4bea6470cb1b88b75058"}, + {file = "dunamai-1.5.4.tar.gz", hash = "sha256:82eb8dbdad6734a6ad475a2e8d0d5167fde7b0ae0d9529da0042129ca3736523"}, ] execnet = [ {file = "execnet-1.7.1-py2.py3-none-any.whl", hash = "sha256:d4efd397930c46415f62f8a31388d6be4f27a91d7550eb79bc64a756e0056547"}, @@ -935,20 +947,39 @@ markupsafe = [ {file = "MarkupSafe-1.1.1-cp35-cp35m-win32.whl", hash = "sha256:6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1"}, {file = "MarkupSafe-1.1.1-cp35-cp35m-win_amd64.whl", hash = "sha256:9add70b36c5666a2ed02b43b335fe19002ee5235efd4b8a89bfcf9005bebac0d"}, {file = "MarkupSafe-1.1.1-cp36-cp36m-macosx_10_6_intel.whl", hash = "sha256:24982cc2533820871eba85ba648cd53d8623687ff11cbb805be4ff7b4c971aff"}, + {file = "MarkupSafe-1.1.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:d53bc011414228441014aa71dbec320c66468c1030aae3a6e29778a3382d96e5"}, {file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:00bc623926325b26bb9605ae9eae8a215691f33cae5df11ca5424f06f2d1f473"}, {file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:717ba8fe3ae9cc0006d7c451f0bb265ee07739daf76355d06366154ee68d221e"}, + {file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:3b8a6499709d29c2e2399569d96719a1b21dcd94410a586a18526b143ec8470f"}, + {file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:84dee80c15f1b560d55bcfe6d47b27d070b4681c699c572af2e3c7cc90a3b8e0"}, + {file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:b1dba4527182c95a0db8b6060cc98ac49b9e2f5e64320e2b56e47cb2831978c7"}, {file = "MarkupSafe-1.1.1-cp36-cp36m-win32.whl", hash = "sha256:535f6fc4d397c1563d08b88e485c3496cf5784e927af890fb3c3aac7f933ec66"}, {file = "MarkupSafe-1.1.1-cp36-cp36m-win_amd64.whl", hash = "sha256:b1282f8c00509d99fef04d8ba936b156d419be841854fe901d8ae224c59f0be5"}, {file = "MarkupSafe-1.1.1-cp37-cp37m-macosx_10_6_intel.whl", hash = "sha256:8defac2f2ccd6805ebf65f5eeb132adcf2ab57aa11fdf4c0dd5169a004710e7d"}, + {file = "MarkupSafe-1.1.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:bf5aa3cbcfdf57fa2ee9cd1822c862ef23037f5c832ad09cfea57fa846dec193"}, {file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:46c99d2de99945ec5cb54f23c8cd5689f6d7177305ebff350a58ce5f8de1669e"}, {file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6"}, + {file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:6fffc775d90dcc9aed1b89219549b329a9250d918fd0b8fa8d93d154918422e1"}, + {file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:a6a744282b7718a2a62d2ed9d993cad6f5f585605ad352c11de459f4108df0a1"}, + {file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:195d7d2c4fbb0ee8139a6cf67194f3973a6b3042d742ebe0a9ed36d8b6f0c07f"}, {file = "MarkupSafe-1.1.1-cp37-cp37m-win32.whl", hash = "sha256:b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2"}, {file = "MarkupSafe-1.1.1-cp37-cp37m-win_amd64.whl", hash = "sha256:9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c"}, {file = "MarkupSafe-1.1.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6788b695d50a51edb699cb55e35487e430fa21f1ed838122d722e0ff0ac5ba15"}, {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:cdb132fc825c38e1aeec2c8aa9338310d29d337bebbd7baa06889d09a60a1fa2"}, {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:13d3144e1e340870b25e7b10b98d779608c02016d5184cfb9927a9f10c689f42"}, + {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:acf08ac40292838b3cbbb06cfe9b2cb9ec78fce8baca31ddb87aaac2e2dc3bc2"}, + {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:d9be0ba6c527163cbed5e0857c451fcd092ce83947944d6c14bc95441203f032"}, + {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:caabedc8323f1e93231b52fc32bdcde6db817623d33e100708d9a68e1f53b26b"}, {file = "MarkupSafe-1.1.1-cp38-cp38-win32.whl", hash = "sha256:596510de112c685489095da617b5bcbbac7dd6384aeebeda4df6025d0256a81b"}, {file = "MarkupSafe-1.1.1-cp38-cp38-win_amd64.whl", hash = "sha256:e8313f01ba26fbbe36c7be1966a7b7424942f670f38e666995b88d012765b9be"}, + {file = "MarkupSafe-1.1.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:d73a845f227b0bfe8a7455ee623525ee656a9e2e749e4742706d80a6065d5e2c"}, + {file = "MarkupSafe-1.1.1-cp39-cp39-manylinux1_i686.whl", hash = "sha256:98bae9582248d6cf62321dcb52aaf5d9adf0bad3b40582925ef7c7f0ed85fceb"}, + {file = "MarkupSafe-1.1.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:2beec1e0de6924ea551859edb9e7679da6e4870d32cb766240ce17e0a0ba2014"}, + {file = "MarkupSafe-1.1.1-cp39-cp39-manylinux2010_i686.whl", hash = "sha256:7fed13866cf14bba33e7176717346713881f56d9d2bcebab207f7a036f41b850"}, + {file = "MarkupSafe-1.1.1-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:6f1e273a344928347c1290119b493a1f0303c52f5a5eae5f16d74f48c15d4a85"}, + {file = "MarkupSafe-1.1.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:feb7b34d6325451ef96bc0e36e1a6c0c1c64bc1fbec4b854f4529e51887b1621"}, + {file = "MarkupSafe-1.1.1-cp39-cp39-win32.whl", hash = "sha256:22c178a091fc6630d0d045bdb5992d2dfe14e3259760e713c490da5323866c39"}, + {file = "MarkupSafe-1.1.1-cp39-cp39-win_amd64.whl", hash = "sha256:b7d644ddb4dbd407d31ffb699f1d140bc35478da613b441c582aeb7c43838dd8"}, {file = "MarkupSafe-1.1.1.tar.gz", hash = "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b"}, ] more-itertools = [ @@ -996,8 +1027,8 @@ pluggy = [ {file = "pluggy-0.13.1.tar.gz", hash = "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0"}, ] poetry-dynamic-versioning = [ - {file = "poetry-dynamic-versioning-0.12.0.tar.gz", hash = "sha256:6bab4b62125bdc8feb3cb6420d10732df1bf769f6ee06412c72c2b0bbf19e2e2"}, - {file = "poetry_dynamic_versioning-0.12.0-py3-none-any.whl", hash = "sha256:3f33ca7f5ec047d4909e3e77390d47711ffd6f70a2ad7e5efc98a389b468bbf0"}, + {file = "poetry-dynamic-versioning-0.12.4.tar.gz", hash = "sha256:8bc15c31c5cc095c1a5c9bc42582387ba2cbefa3ae230bda5a84cc834c8b28b1"}, + {file = "poetry_dynamic_versioning-0.12.4-py3-none-any.whl", hash = "sha256:29a3670de4682ef7830e99d9f5a7e179f98c85d78a332af5f6b5385b4400cb20"}, ] py = [ {file = "py-1.9.0-py2.py3-none-any.whl", hash = "sha256:366389d1db726cd2fcfc79732e75410e5fe4d31db13692115529d34069a043c2"}, @@ -1018,9 +1049,14 @@ pytest-forked = [ {file = "pytest-forked-1.3.0.tar.gz", hash = "sha256:6aa9ac7e00ad1a539c41bec6d21011332de671e938c7637378ec9710204e37ca"}, {file = "pytest_forked-1.3.0-py2.py3-none-any.whl", hash = "sha256:dc4147784048e70ef5d437951728825a131b81714b398d5d52f17c7c144d8815"}, ] +pytest-ordering = [ + {file = "pytest-ordering-0.6.tar.gz", hash = "sha256:561ad653626bb171da78e682f6d39ac33bb13b3e272d406cd555adb6b006bda6"}, + {file = "pytest_ordering-0.6-py2-none-any.whl", hash = "sha256:27fba3fc265f5d0f8597e7557885662c1bdc1969497cd58aff6ed21c3b617de2"}, + {file = "pytest_ordering-0.6-py3-none-any.whl", hash = "sha256:3f314a178dbeb6777509548727dc69edf22d6d9a2867bf2d310ab85c403380b6"}, +] pytest-splunk-addon = [ - {file = "pytest-splunk-addon-1.3.12.tar.gz", hash = "sha256:746c10e3b8394a3af7edc85737995cf805e06f0d1efcdd8da69bf8d7ce4ad38d"}, - {file = "pytest_splunk_addon-1.3.12-py3-none-any.whl", hash = "sha256:37366951b7f8d338017bba95edbb60649d45ef721a3b35fea27fbdabf5e74049"}, + {file = "pytest-splunk-addon-1.6.0.tar.gz", hash = "sha256:df6e7f50839315b58f55f8ea52a071960d5a461fdd20e00c1b54be084aff57d8"}, + {file = "pytest_splunk_addon-1.6.0-py3-none-any.whl", hash = "sha256:07ada0c34e4aebee2be7ed737e430c932aa3eee86d290c6c4641d3f1a06aa7b3"}, ] pytest-xdist = [ {file = "pytest-xdist-2.1.0.tar.gz", hash = "sha256:82d938f1a24186520e2d9d3a64ef7d9ac7ecdf1a0659e095d18e596b8cbd0672"}, @@ -1070,8 +1106,8 @@ requests = [ {file = "requests-2.24.0.tar.gz", hash = "sha256:b3559a131db72c33ee969480840fff4bb6dd111de7dd27c8ee1f820f4f00231b"}, ] reuse = [ - {file = "reuse-0.11.1-py3-none-any.whl", hash = "sha256:fb15e9c605d815cc816bec690d3ecf88ecba50968b6d41d558d95e54e80bbcc4"}, - {file = "reuse-0.11.1.tar.gz", hash = "sha256:a5c539a3ccf46eff16c85590b4cc158fc614ce434b7d9dff5120ef441c591227"}, + {file = "reuse-0.12.1-py3-none-any.whl", hash = "sha256:a07fce3a43eefa2e3140a7510b6171788cc95a3c9cc840517c10d6de28c42d6d"}, + {file = "reuse-0.12.1.tar.gz", hash = "sha256:4ed065f24c5fc929ebf8853663e14ca486fe4108d7aebceebf51e2c597ec2186"}, ] schematics = [ {file = "schematics-2.1.0-py2.py3-none-any.whl", hash = "sha256:8fcc6182606fd0b24410a1dbb066d9bbddbe8da9c9509f47b743495706239283"}, @@ -1105,8 +1141,8 @@ splunktalib = [ {file = "splunktalib-1.1.4.tar.gz", hash = "sha256:c336272381509e96ab63348bb46852b0562d2e16a6cfa3ac399c346c5d1e2b65"}, ] splunktaucclib = [ - {file = "splunktaucclib-4.0.12-py2.py3-none-any.whl", hash = "sha256:cb30a6e741a2a0257e7ba9f232ddcd06da9fc96ae3c3d6899a832f105b8d1f57"}, - {file = "splunktaucclib-4.0.12.tar.gz", hash = "sha256:88b9c898b45fc3dce4caaf2ae428a53ead564788c4df207edcce05c0e8bde2f3"}, + {file = "splunktaucclib-4.1.0-py2.py3-none-any.whl", hash = "sha256:d1eae73fd81f132c81eaf20e818358a59708e788a9a97f6e73273a8133a7032f"}, + {file = "splunktaucclib-4.1.0.tar.gz", hash = "sha256:44021f251cd9aea362cc2474184903661c437626cc65fa66fdca81948693837d"}, ] text-unidecode = [ {file = "text-unidecode-1.3.tar.gz", hash = "sha256:bad6603bb14d279193107714b288be206cac565dfa49aa5b105294dd5c4aab93"}, diff --git a/pyproject.toml b/pyproject.toml index 628e6cc44..1b1a21fa8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,7 +61,7 @@ reuse = "*" [tool.poetry.dev-dependencies] pytest = "^6.0" -pytest-splunk-addon = { version = "^1.3", extras = [ "docker" ] } +pytest-splunk-addon = { version = "^1.6", extras = [ "docker" ] } poetry-dynamic-versioning = "^0.12" [tool.poetry-dynamic-versioning] diff --git a/splunk_add_on_ucc_framework/templates/input_with_helper.template b/splunk_add_on_ucc_framework/templates/input_with_helper.template new file mode 100644 index 000000000..669239240 --- /dev/null +++ b/splunk_add_on_ucc_framework/templates/input_with_helper.template @@ -0,0 +1,134 @@ +{{import_declare}} +import sys +import json + +from splunklib import modularinput as smi + +import os +import traceback +import requests +from splunklib import modularinput as smi +from solnlib import conf_manager +from solnlib import log +from solnlib.modular_input import checkpointer +from splunktaucclib.modinput_wrapper import base_modinput as base_mi + +bin_dir = os.path.basename(__file__) +app_name = os.path.basename(os.path.dirname(os.getcwd())) + +class ModInput{{class_name}}(base_mi.BaseModInput): + + def __init__(self): + use_single_instance = False + super(ModInput{{class_name}}, self).__init__(app_name, "{{class_name|lower}}", use_single_instance) + self.global_checkbox_fields = None + + def get_scheme(self): + scheme = smi.Scheme('{{input_name}}') + scheme.description = '{{description}}' + 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 + ) + ) + {%- for ent in entity %} + {%- if ent.get("field") != "interval" %} + scheme.add_argument( + smi.Argument( + '{{ent.get("field")}}', + required_on_create={{True if ent.get("required") else False}}, + ) + ) + {%- endif %} + {% endfor %} + return scheme + + def validate_input(self, definition): + """validate the input stanza""" + """Implement your own validation logic to validate the input stanza configurations""" + pass + + def get_app_name(self): + return "app_name" + + def collect_events(helper, ew): + + # Get the CloudConnect json file .cc.json + script_name = __file__ + script_name = script_name[:-3] + config_file_name = '.'.join([script_name, 'cc.json']) + + # Extract the url, method and headers for this input from the .cc.json file + with open(config_file_name) as f: + data = json.load(f) + + url = data["requests"][0]["request"]["url"] + method = data["requests"][0]["request"]["method"] + headers= json.dumps(data["requests"][0]["request"]["headers"]) + + # insert input values into the url and/or header (helper class handles credential store) + {%- for ent in entity %} + {%- if ent.get("field") != "interval" %} + opt_{{ent.get("field")}} = helper.get_arg('{{ent.get("field")}}') + url = url.replace("{% raw %}{{{% endraw %}"+'{{ent.get("field")}}'+"{% raw %}}}{% endraw %}",opt_{{ent.get("field")}}) + headers = headers.replace("{% raw %}{{{% endraw %}"+'{{ent.get("field")}}'+"{% raw %}}}{% endraw %}",opt_{{ent.get("field")}}) + {% endif %} + {%- endfor %} + # Now execute the api call + headers=json.loads(headers) + response = helper.send_http_request(url, method, headers=headers, parameters="", payload=None, cookies=None, verify=True, cert=None, timeout=None, use_proxy=True) + + try: + response.raise_for_status() + + except: + helper.log_error (response.text) + + if response.status_code == 200: + try: + data = json.dumps(response.json()) + sourcetype= "{{input_name}}" + "://" + helper.get_input_stanza_names() + event = helper.new_event(source="{{input_name}}", index=helper.get_output_index(), sourcetype=sourcetype , data=data) + ew.write_event(event) + except: + helper.log_info("Error inserting event") + + + def get_account_fields(self): + account_fields = [] + return account_fields + + + def get_checkbox_fields(self): + checkbox_fields = [] + return checkbox_fields + + + def get_global_checkbox_fields(self): + if self.global_checkbox_fields is None: + checkbox_name_file = os.path.join(bin_dir, 'global_checkbox_param.json') + try: + if os.path.isfile(checkbox_name_file): + with open(checkbox_name_file, 'r') as fp: + self.global_checkbox_fields = json.load(fp) + else: + self.global_checkbox_fields = [] + except Exception as e: + self.log_error('Get exception when loading global checkbox parameter names. ' + str(e)) + self.global_checkbox_fields = [] + return self.global_checkbox_fields + + +if __name__ == '__main__': + exit_code = ModInput{{class_name}}().run(sys.argv) + sys.exit(exit_code) + + +