This repository has been archived by the owner on Dec 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from splunk/develop
Develop
- Loading branch information
Showing
13 changed files
with
384 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,3 +156,6 @@ dmypy.json | |
.pyre/ | ||
mibs/.DS_Store | ||
.DS_Store | ||
|
||
# Intellij | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
OID,Label | ||
1.3.6.1.6.3.1.1.4.1.0,paris | ||
1.3.6.1.2.1.1.3.0,london | ||
1.3.6.1.4.1.6141.2.60.37.0.2,splunk-test | ||
1.3.6.1.4.1.8072.2.3.0.1,mycustomNET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatNotification | ||
1.3.6.1.4.1.8072.2.3.2.1,mycustomNET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatRate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import logging.config | ||
|
||
logging.basicConfig(level=logging.INFO, format='%(asctime)s | %(name)s | %(levelname)s | %(message)s') | ||
logging.basicConfig( | ||
level=logging.INFO, format="%(asctime)s | %(name)s | %(levelname)s | %(message)s" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,53 @@ | ||
from flask import Flask, request, abort, jsonify, send_from_directory | ||
from flask import Flask, request | ||
from flask_autoindex import AutoIndex | ||
import os | ||
import yaml | ||
from splunk_connect_for_snmp_mib_server.mongo import MibsRepository, OidsRepository | ||
from splunk_connect_for_snmp_mib_server.translator import Translator | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class MibServer: | ||
def __init__(self, args, server_config): | ||
self._args = args | ||
self._server_config = server_config | ||
self._translator = Translator(server_config) | ||
self._flask_app = self.build_flask_app() | ||
def build_flask_app(self): | ||
|
||
def build_flask_app(self): | ||
app = Flask(__name__) | ||
# ppath = os.environ['MIBS_SERVER_URL'] | ||
ppath = self._server_config["snmp"]["mibs"]["mibs_path"] | ||
files_index = AutoIndex(app, ppath, add_url_rules=False) | ||
mibs_path = self._server_config["snmp"]["mibs"]["mibs_path"] | ||
files_index = AutoIndex(app, mibs_path, add_url_rules=False) | ||
|
||
@app.route('/') | ||
@app.route("/") | ||
def hello(): | ||
return "Hello, This is SNMP MIB server!" | ||
|
||
# Custom indexing | ||
@app.route('/files/') | ||
@app.route('/files/<path:path>') | ||
def autoindex(path='.'): | ||
@app.route("/files/") | ||
@app.route("/files/<path:path>") | ||
def autoindex(path="."): | ||
logger.debug(f"path: {path}") | ||
return files_index.render_autoindex(path) | ||
|
||
# Translate oid | ||
@app.route('/translation', methods=['POST']) | ||
@app.route("/translation", methods=["POST"]) | ||
def translator(): | ||
logger.debug(request.json) | ||
var_binds = request.json.get('var_binds') | ||
var_binds = request.json.get("var_binds") | ||
metric = request.args.get("metric") | ||
logger.debug(f"type of var_binds: {type(var_binds)}") | ||
logger.debug(f"var_binds: {var_binds}") | ||
logger.debug(f"type of metric: {str(metric)} -- metric: {metric}") | ||
if metric == "True": | ||
# TODO | ||
# If metric is true, var_binds just has one | ||
# if metric is true, var_binds has just one element | ||
var_bind = var_binds[0] | ||
result = self._translator.format_metric_data(var_bind) | ||
result = self._translator.format_metric_data(var_bind) | ||
else: | ||
result = self._translator.format_trap_event(var_binds) | ||
return result | ||
|
||
return app | ||
|
||
def run_mib_server(self): | ||
# TODO poetry run fails when debug=True | ||
self._flask_app.run(host="0.0.0.0",port=self._args.port) | ||
|
||
def run_mib_server(self): | ||
# poetry run fails when debug=True | ||
self._flask_app.run(host="0.0.0.0", port=self._args.port) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.