Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

feat: improved the dynamic MIB loading #41

Merged
merged 25 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
71b32b4
fix: (semgrep) use yaml::safe_load instead of yaml::load
lstoppa Jul 16, 2021
a13e76e
fix: added unit-test for HOST-RESOURCES-MIB
lstoppa Jul 16, 2021
d057539
fix: partial fix for dynamic MIB loading
lstoppa Jul 16, 2021
13177d4
fix: partial fix for dynamic MIB loading
lstoppa Jul 16, 2021
19f829d
fix: partial fix for dynamic MIB loading
lstoppa Jul 16, 2021
fedde57
fix: removed unexpected argument for yaml.safe_load
lingy1028 Jul 19, 2021
0c995c4
fix: partial fix for dynamic MIB loading
lingy1028 Jul 20, 2021
d17cfc5
fix: partial fix for dynamic MIB loading
lingy1028 Jul 20, 2021
3d6e791
fix: partial fix for dynamic MIB loading
lingy1028 Jul 20, 2021
bed65bf
fix: fixed the cla-assistant version
lingy1028 Jul 20, 2021
cf9123c
fix: (semgrep) use yaml::safe_load instead of yaml::load
lstoppa Jul 16, 2021
d6a29b9
fix: added unit-test for HOST-RESOURCES-MIB
lstoppa Jul 16, 2021
b42ee99
fix: partial fix for dynamic MIB loading
lstoppa Jul 16, 2021
9d55d14
fix: partial fix for dynamic MIB loading
lstoppa Jul 16, 2021
50b19ca
fix: partial fix for dynamic MIB loading
lstoppa Jul 16, 2021
7dfb5b5
fix: removed unexpected argument for yaml.safe_load
lingy1028 Jul 19, 2021
c3380d6
fix: partial fix for dynamic MIB loading
lingy1028 Jul 20, 2021
e167cd7
fix: partial fix for dynamic MIB loading
lingy1028 Jul 20, 2021
f6cad57
fix: partial fix for dynamic MIB loading
lingy1028 Jul 20, 2021
4e14c84
Merge branch 'feature/fix-semgrep' of github.com:splunk/splunk-connec…
lingy1028 Jul 20, 2021
bd58ff3
fix: removed the failed CI step: Upload result to GitHub Code Scanning
lingy1028 Jul 20, 2021
8dab52a
refactor: refactor to remove the duplicate code
lingy1028 Jul 21, 2021
7e16d0a
fix: reformatted to pass the lint checks
lingy1028 Jul 21, 2021
e0a7249
fix: dummy commit to resolve lint issue by running suggested pip comm…
lingy1028 Jul 21, 2021
86f01db
fix: added types-PyYAML
lingy1028 Jul 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/agreements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: "CLA Assistant"
if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target'
# Alpha Release
uses: cla-assistant/github-action@v2.3.1-beta
uses: cla-assistant/github-action@v2.1.3-beta
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# the below token should have repo scope and must be manually added by you in the repository's secret
Expand All @@ -37,7 +37,7 @@ jobs:
- name: "COC Assistant"
if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the Code of Conduct and I hereby accept the Terms') || github.event_name == 'pull_request_target'
# Alpha Release
uses: cla-assistant/github-action@v2.3.1-beta
uses: cla-assistant/github-action@v2.1.3-beta
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# the below token should have repo scope and must be manually added by you in the repository's secret
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/build-test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ jobs:
uses: snyk/actions/python-3.8@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
- name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: snyk.sarif
# - name: Upload result to GitHub Code Scanning
# uses: github/codeql-action/upload-sarif@v1
# with:
# sarif_file: snyk.sarif
build:
name: Build Release
needs:
Expand Down Expand Up @@ -210,10 +210,10 @@ jobs:
with:
image: ${{ fromJSON(steps.docker_meta.outputs.json).tags[0] }}
args: --file=Dockerfile
- name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: snyk.sarif
# - name: Upload result to GitHub Code Scanning
# uses: github/codeql-action/upload-sarif@v1
# with:
# sarif_file: snyk.sarif

- uses: actions/download-artifact@v2
with:
Expand Down
2 changes: 0 additions & 2 deletions lookups/mibs_list.csv
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,3 @@ HPR-IP-MIB
PYSNMP-MIB
PYSNMP-SOURCE-MIB
PYSNMP-USM-MIB
VMSTORE-MIB
VERITAS-APPLIANCE-MONITORING-MIB
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ requests = "^2.25.1"
PyYAML = "^5.4.1"
Flask = "^1.1.2"
Flask-AutoIndex = "^0.6.6"
types-PyYAML = "^5.4.3"

[tool.poetry.dev-dependencies]
mongomock = "^3.22.1"
Expand All @@ -41,3 +42,7 @@ sc4snmp-mib-server = "splunk_connect_for_snmp_mib_server.snmp_mib_server:main"
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
log_cli = true
log_cli_level = "INFO"

34 changes: 17 additions & 17 deletions splunk_connect_for_snmp_mib_server/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ########################################################################
import pymongo
import os
import logging
import os

import pymongo

logger = logging.getLogger(__name__)


class MibsRepository:
class MongoRepository:
def __init__(self, mongo_config):
self._client = pymongo.MongoClient(
os.environ["MONGO_SERVICE_SERVICE_HOST"],
Expand All @@ -32,6 +33,11 @@ def __init__(self, mongo_config):
os.environ["MONGO_PASS"],
mechanism="SCRAM-SHA-1",
)


class MibsRepository(MongoRepository):
def __init__(self, mongo_config):
super().__init__(mongo_config)
self._mibs = self._client[mongo_config["database"]][mongo_config["collection"]]

def upload_files(self, mib_files_dir):
Expand All @@ -48,31 +54,25 @@ def upload_files(self, mib_files_dir):
)

def search_oid(self, oid):
data = self._mibs.find_one({"content": {"$regex": oid}})
data = self._mibs.find({"content": {"$regex": oid}})
if data:
return data["filename"]
mib_list = []
for item in data:
mib_list.append(item["filename"])
return mib_list
else:
return None

def delete_mib(self, filename):
self._mibs.delete_many({"filename": {"$regex": filename}})

def clear(self):
self._mibs.remove()
self._mibs.delete_many({})


class OidsRepository:
class OidsRepository(MongoRepository):
def __init__(self, mongo_config):
self._client = pymongo.MongoClient(
os.environ["MONGO_SERVICE_SERVICE_HOST"],
int(os.environ["MONGO_SERVICE_SERVICE_PORT"]),
)
if os.environ.get("MONGO_USER"):
self._client.admin.authenticate(
os.environ["MONGO_USER"],
os.environ["MONGO_PASS"],
mechanism="SCRAM-SHA-1",
)
super().__init__(mongo_config)
self._oids = self._client[mongo_config["database"]][mongo_config["collection"]]

def contains_oid(self, oid):
Expand Down
9 changes: 5 additions & 4 deletions splunk_connect_for_snmp_mib_server/snmp_mib_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
# limitations under the License.
# ########################################################################
import argparse
import logging

import yaml
from splunk_connect_for_snmp_mib_server.mongo import MibsRepository
from splunk_connect_for_snmp_mib_server.mib_server import MibServer
import logging
from splunk_connect_for_snmp_mib_server.mongo import MibsRepository

logger = logging.getLogger(__name__)

Expand All @@ -35,7 +36,7 @@ def upload_mibs(server_config):


def main():
logger.info(f"Startup Config")
logger.info("Startup Config")
parser = argparse.ArgumentParser()
parser.add_argument(
"-l",
Expand All @@ -60,7 +61,7 @@ def main():
logger.info("Completed Argument parsing")

with open(config_file, "r") as yamlfile:
server_config = yaml.load(yamlfile, Loader=yaml.FullLoader)
server_config = yaml.safe_load(yamlfile)

upload_mibs(server_config)
mib_server = MibServer(args, server_config)
Expand Down
Loading