From dc19515e1d2969d2eb70a4d7de3990194ca57877 Mon Sep 17 00:00:00 2001 From: weliasz Date: Wed, 10 Nov 2021 13:37:49 +0100 Subject: [PATCH 1/5] feat: notify scheduler when MIB starts --- splunk_connect_for_snmp_mib_server/mib_server.py | 10 ++++++++++ splunk_connect_for_snmp_mib_server/snmp_mib_server.py | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/splunk_connect_for_snmp_mib_server/mib_server.py b/splunk_connect_for_snmp_mib_server/mib_server.py index fa262d88..84390995 100644 --- a/splunk_connect_for_snmp_mib_server/mib_server.py +++ b/splunk_connect_for_snmp_mib_server/mib_server.py @@ -14,6 +14,11 @@ # limitations under the License. # ######################################################################## import logging +import os + +from checksumdir import dirhash + +import requests from flask import Flask, request from flask_autoindex import AutoIndex @@ -80,3 +85,8 @@ def get_profiles(): def run_mib_server(self): # poetry run fails when debug=True self._flask_app.run(host="0.0.0.0", port=self._args.port) + + def notify_startup(self): + profiles_hash = dirhash("profiles") + params = {"profiles_hash": profiles_hash} + requests.get(os.environ["SCHEDULER_REFRESH_URI"], params=params) diff --git a/splunk_connect_for_snmp_mib_server/snmp_mib_server.py b/splunk_connect_for_snmp_mib_server/snmp_mib_server.py index ed68dc4f..e796030c 100644 --- a/splunk_connect_for_snmp_mib_server/snmp_mib_server.py +++ b/splunk_connect_for_snmp_mib_server/snmp_mib_server.py @@ -15,6 +15,7 @@ # ######################################################################## import argparse import logging +import threading import time import yaml @@ -77,7 +78,9 @@ def main(): upload_mibs(server_config) mib_server = MibServer(args, server_config) - mib_server.run_mib_server() + threading.Thread(target=mib_server.run_mib_server).start() + time.sleep(5) + mib_server.notify_startup() if __name__ == "__main__": From 40c77002fa9089b471095e8309dd7c0d04c694de Mon Sep 17 00:00:00 2001 From: weliasz Date: Wed, 10 Nov 2021 13:46:48 +0100 Subject: [PATCH 2/5] fix: added dependency --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index d81b879e..49db737f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,6 +29,7 @@ PyYAML = "^5.4.1" Flask = "^1.1.2" Flask-AutoIndex = "^0.6.6" types-PyYAML = "^5.4.3" +checksumdir = "^1.2.0" [tool.poetry.dev-dependencies] mongomock = "^3.22.1" From 29090f05d8cebb4a281cdb8d9bb8e104e2f48f01 Mon Sep 17 00:00:00 2001 From: weliasz Date: Wed, 10 Nov 2021 13:59:05 +0100 Subject: [PATCH 3/5] fix: build --- poetry.lock | 30 +++++++++++-------- .../mib_server.py | 6 ++-- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/poetry.lock b/poetry.lock index 4c7ddef9..1b61aa14 100644 --- a/poetry.lock +++ b/poetry.lock @@ -39,6 +39,14 @@ python-versions = ">=3.5.0" [package.extras] unicode_backport = ["unicodedata2"] +[[package]] +name = "checksumdir" +version = "1.2.0" +description = "Compute a single hash of the file contents of a directory." +category = "main" +optional = false +python-versions = ">=3.6,<4.0" + [[package]] name = "click" version = "7.1.2" @@ -220,11 +228,11 @@ python-versions = "*" [[package]] name = "py" -version = "1.10.0" +version = "1.11.0" description = "library with cross-python path, ini-parsing, io, code, log facilities" category = "dev" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [[package]] name = "pyasn1" @@ -418,7 +426,7 @@ watchdog = ["watchdog"] [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "f4931a0f1de0a5abde947979419cd11eaf375cb92e9389e4a70e6c73a2fb130d" +content-hash = "91cdc37412d7e8599b456a1f0fe892bb8cbb873c11b9e882b769410d9de7284e" [metadata.files] atomicwrites = [ @@ -437,6 +445,10 @@ charset-normalizer = [ {file = "charset-normalizer-2.0.7.tar.gz", hash = "sha256:e019de665e2bcf9c2b64e2e5aa025fa991da8720daa3c1138cadd2fd1856aed0"}, {file = "charset_normalizer-2.0.7-py3-none-any.whl", hash = "sha256:f7af805c321bfa1ce6714c51f254e0d5bb5e5834039bc17db7ebe3a4cec9492b"}, ] +checksumdir = [ + {file = "checksumdir-1.2.0-py3-none-any.whl", hash = "sha256:77687e16da95970c94061c74ef2e13666c4b6e0e8c90a5eaf0c8f7591332cf01"}, + {file = "checksumdir-1.2.0.tar.gz", hash = "sha256:10bfd7518da5a14b0e9ac03e9ad105f0e70f58bba52b6e9aa2f21a3f73c7b5a8"}, +] click = [ {file = "click-7.1.2-py2.py3-none-any.whl", hash = "sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"}, {file = "click-7.1.2.tar.gz", hash = "sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a"}, @@ -579,8 +591,8 @@ ply = [ {file = "ply-3.11.tar.gz", hash = "sha256:00c7c1aaa88358b9c765b6d3000c6eec0ba42abca5351b095321aef446081da3"}, ] py = [ - {file = "py-1.10.0-py2.py3-none-any.whl", hash = "sha256:3b80836aa6d1feeaa108e046da6423ab8f6ceda6468545ae8d02d9d58d18818a"}, - {file = "py-1.10.0.tar.gz", hash = "sha256:21b81bda15b66ef5e1a777a21c4dcd9c20ad3efd0b3f817e7a809035269e1bd3"}, + {file = "py-1.11.0-py2.py3-none-any.whl", hash = "sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378"}, + {file = "py-1.11.0.tar.gz", hash = "sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719"}, ] pyasn1 = [ {file = "pyasn1-0.4.8-py2.4.egg", hash = "sha256:fec3e9d8e36808a28efb59b489e4528c10ad0f480e57dcc32b4de5c9d8c9fdf3"}, @@ -787,26 +799,18 @@ pyyaml = [ {file = "PyYAML-5.4.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:bb4191dfc9306777bc594117aee052446b3fa88737cd13b7188d0e7aa8162185"}, {file = "PyYAML-5.4.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:6c78645d400265a062508ae399b60b8c167bf003db364ecb26dcab2bda048253"}, {file = "PyYAML-5.4.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:4e0583d24c881e14342eaf4ec5fbc97f934b999a6828693a99157fde912540cc"}, - {file = "PyYAML-5.4.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:72a01f726a9c7851ca9bfad6fd09ca4e090a023c00945ea05ba1638c09dc3347"}, - {file = "PyYAML-5.4.1-cp36-cp36m-manylinux2014_s390x.whl", hash = "sha256:895f61ef02e8fed38159bb70f7e100e00f471eae2bc838cd0f4ebb21e28f8541"}, {file = "PyYAML-5.4.1-cp36-cp36m-win32.whl", hash = "sha256:3bd0e463264cf257d1ffd2e40223b197271046d09dadf73a0fe82b9c1fc385a5"}, {file = "PyYAML-5.4.1-cp36-cp36m-win_amd64.whl", hash = "sha256:e4fac90784481d221a8e4b1162afa7c47ed953be40d31ab4629ae917510051df"}, {file = "PyYAML-5.4.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:5accb17103e43963b80e6f837831f38d314a0495500067cb25afab2e8d7a4018"}, {file = "PyYAML-5.4.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:e1d4970ea66be07ae37a3c2e48b5ec63f7ba6804bdddfdbd3cfd954d25a82e63"}, - {file = "PyYAML-5.4.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:cb333c16912324fd5f769fff6bc5de372e9e7a202247b48870bc251ed40239aa"}, - {file = "PyYAML-5.4.1-cp37-cp37m-manylinux2014_s390x.whl", hash = "sha256:fe69978f3f768926cfa37b867e3843918e012cf83f680806599ddce33c2c68b0"}, {file = "PyYAML-5.4.1-cp37-cp37m-win32.whl", hash = "sha256:dd5de0646207f053eb0d6c74ae45ba98c3395a571a2891858e87df7c9b9bd51b"}, {file = "PyYAML-5.4.1-cp37-cp37m-win_amd64.whl", hash = "sha256:08682f6b72c722394747bddaf0aa62277e02557c0fd1c42cb853016a38f8dedf"}, {file = "PyYAML-5.4.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d2d9808ea7b4af864f35ea216be506ecec180628aced0704e34aca0b040ffe46"}, {file = "PyYAML-5.4.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:8c1be557ee92a20f184922c7b6424e8ab6691788e6d86137c5d93c1a6ec1b8fb"}, - {file = "PyYAML-5.4.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:fd7f6999a8070df521b6384004ef42833b9bd62cfee11a09bda1079b4b704247"}, - {file = "PyYAML-5.4.1-cp38-cp38-manylinux2014_s390x.whl", hash = "sha256:bfb51918d4ff3d77c1c856a9699f8492c612cde32fd3bcd344af9be34999bfdc"}, {file = "PyYAML-5.4.1-cp38-cp38-win32.whl", hash = "sha256:fa5ae20527d8e831e8230cbffd9f8fe952815b2b7dae6ffec25318803a7528fc"}, {file = "PyYAML-5.4.1-cp38-cp38-win_amd64.whl", hash = "sha256:0f5f5786c0e09baddcd8b4b45f20a7b5d61a7e7e99846e3c799b05c7c53fa696"}, {file = "PyYAML-5.4.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:294db365efa064d00b8d1ef65d8ea2c3426ac366c0c4368d930bf1c5fb497f77"}, {file = "PyYAML-5.4.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:74c1485f7707cf707a7aef42ef6322b8f97921bd89be2ab6317fd782c2d53183"}, - {file = "PyYAML-5.4.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:d483ad4e639292c90170eb6f7783ad19490e7a8defb3e46f97dfe4bacae89122"}, - {file = "PyYAML-5.4.1-cp39-cp39-manylinux2014_s390x.whl", hash = "sha256:fdc842473cd33f45ff6bce46aea678a54e3d21f1b61a7750ce3c498eedfe25d6"}, {file = "PyYAML-5.4.1-cp39-cp39-win32.whl", hash = "sha256:49d4cdd9065b9b6e206d0595fee27a96b5dd22618e7520c33204a4a3239d5b10"}, {file = "PyYAML-5.4.1-cp39-cp39-win_amd64.whl", hash = "sha256:c20cfa2d49991c8b4147af39859b167664f2ad4561704ee74c1de03318e898db"}, {file = "PyYAML-5.4.1.tar.gz", hash = "sha256:607774cbba28732bfa802b54baa7484215f530991055bb562efbed5b2f20a45e"}, diff --git a/splunk_connect_for_snmp_mib_server/mib_server.py b/splunk_connect_for_snmp_mib_server/mib_server.py index 84390995..0bfea5a4 100644 --- a/splunk_connect_for_snmp_mib_server/mib_server.py +++ b/splunk_connect_for_snmp_mib_server/mib_server.py @@ -15,11 +15,9 @@ # ######################################################################## import logging import os - -from checksumdir import dirhash - import requests +from checksumdir import dirhash from flask import Flask, request from flask_autoindex import AutoIndex @@ -89,4 +87,4 @@ def run_mib_server(self): def notify_startup(self): profiles_hash = dirhash("profiles") params = {"profiles_hash": profiles_hash} - requests.get(os.environ["SCHEDULER_REFRESH_URI"], params=params) + requests.get(os.environ["SCHEDULER_REFRESH_URI"], params=params, timeout=3) From e81f9d1626551cae63264dcc5a7756ce6b84581b Mon Sep 17 00:00:00 2001 From: weliasz Date: Wed, 10 Nov 2021 14:03:43 +0100 Subject: [PATCH 4/5] fix: build --- splunk_connect_for_snmp_mib_server/mib_server.py | 1 + 1 file changed, 1 insertion(+) diff --git a/splunk_connect_for_snmp_mib_server/mib_server.py b/splunk_connect_for_snmp_mib_server/mib_server.py index 0bfea5a4..8610d54d 100644 --- a/splunk_connect_for_snmp_mib_server/mib_server.py +++ b/splunk_connect_for_snmp_mib_server/mib_server.py @@ -15,6 +15,7 @@ # ######################################################################## import logging import os + import requests from checksumdir import dirhash From 549b89d7fcba4d203687bbc53f04e7937fe7baf1 Mon Sep 17 00:00:00 2001 From: weliasz Date: Wed, 10 Nov 2021 14:07:27 +0100 Subject: [PATCH 5/5] fix: build --- splunk_connect_for_snmp_mib_server/mib_server.py | 1 - 1 file changed, 1 deletion(-) diff --git a/splunk_connect_for_snmp_mib_server/mib_server.py b/splunk_connect_for_snmp_mib_server/mib_server.py index 8610d54d..bbd1552f 100644 --- a/splunk_connect_for_snmp_mib_server/mib_server.py +++ b/splunk_connect_for_snmp_mib_server/mib_server.py @@ -17,7 +17,6 @@ import os import requests - from checksumdir import dirhash from flask import Flask, request from flask_autoindex import AutoIndex