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

Commit ed7d8e8

Browse files
authored
feat: create default profile definition in MIB server (#56)
* feat: create default profile definition in MIB server * fix: fix failing build * fix: fix failing build * fix: fix failing build * fix: fix failing build * feat: PR comments * fix: build fix * fix: build fix
1 parent f3ddfb1 commit ed7d8e8

File tree

15 files changed

+457
-3
lines changed

15 files changed

+457
-3
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ COPY dist/*.whl /tmp
2626
COPY config.yaml /work/config.yaml
2727
COPY lookups /work/lookups
2828
COPY mibs /work/mibs
29+
COPY profiles /work/profiles
2930
RUN pip3.8 install $(ls /tmp/*.whl); rm -f /tmp/*.whl
3031

3132
EXPOSE 5000

config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ snmp:
1818
dir: "/work/mibs/pysnmp"
1919
load_list: "lookups/mibs_list.csv"
2020
mibs_path: "/work/mibs"
21+
profiles_path: "/work/profiles"
2122
mongo:
2223
oid:
2324
database: "mib_server"
2425
collection: "oids"
2526
mib:
2627
database: "files"
27-
collection: "mib_files"
28+
collection: "mib_files"

profiles/default.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2021 Splunk Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
profiles:
17+
basev1:
18+
frequency: 10
19+
varBinds:
20+
# Syntax: [ "MIB-Files", "MIB object name" "MIB index number"]
21+
- ['SNMPv2-MIB', 'sysDescr']
22+
- ['SNMPv2-MIB', 'sysUpTime',0]
23+
- ['SNMPv2-MIB', 'sysName']
24+
- '1.3.6.1.2.1.2.*'
25+
basev1l2:
26+
frequency: 20
27+
varBinds:
28+
# Syntax: [ "MIB-Files", "MIB object name" "MIB index number"]
29+
- ['SNMPv2-MIB', 'sysDescr']
30+
- ['SNMPv2-MIB', 'sysUpTime',0]
31+
- ['SNMPv2-MIB', 'sysName']
32+
- ['IF-MIB','ifHCInOctets']
33+
- ['IF-MIB','ifHCOutOctets']
34+
- ['IF-MIB','ifInErrors']
35+
- ['IF-MIB','ifOutErrors']
36+
- ['IF-MIB','ifInDiscards']
37+
- ['IF-MIB','ifOutDiscards']

splunk_connect_for_snmp_mib_server/mib_server.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
# ########################################################################
16-
1716
import logging
1817

1918
from flask import Flask, request
2019
from flask_autoindex import AutoIndex
2120

21+
from splunk_connect_for_snmp_mib_server.profiles import merge_profiles
2222
from splunk_connect_for_snmp_mib_server.translator import Translator
2323

2424
logger = logging.getLogger(__name__)
@@ -39,6 +39,7 @@ def __init__(self, args, server_config):
3939
def build_flask_app(self):
4040
app = Flask(__name__)
4141
mibs_path = self._server_config["snmp"]["mibs"]["mibs_path"]
42+
profiles_path = self._server_config["snmp"]["mibs"]["profiles_path"]
4243
files_index = AutoIndex(app, mibs_path, add_url_rules=False)
4344

4445
@app.route("/")
@@ -68,6 +69,10 @@ def translator():
6869
result = self._translator.format_text_event(var_binds)
6970
return result
7071

72+
@app.route("/profiles", methods=["GET"])
73+
def get_profiles():
74+
return merge_profiles(profiles_path, "profiles")
75+
7176
return app
7277

7378
def run_mib_server(self):
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# ########################################################################
2+
# Copyright 2021 Splunk Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ########################################################################
16+
import logging
17+
import os
18+
19+
import yaml
20+
from yaml.parser import ParserError
21+
22+
logger = logging.getLogger(__name__)
23+
24+
25+
def merge_profiles(directory, root_name):
26+
result = {}
27+
merged_profiles = {}
28+
for root, directories, files in os.walk(directory, topdown=False):
29+
for name in sorted(files):
30+
with open(os.path.join(root, name), "r") as stream:
31+
try:
32+
data = yaml.safe_load(stream)
33+
merged_profiles.update(data[root_name])
34+
except ParserError as pe:
35+
logger.warning(
36+
f"Error while parsing file {os.path.join(root, name)} : {pe}"
37+
)
38+
39+
result[root_name] = merged_profiles
40+
return result

tests/local-config.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Copyright 2021 Splunk Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
snmp:
17+
mibs:
18+
dir: "mibs/pysnmp"
19+
load_list: "lookups/mibs_list.csv"
20+
mibs_path: "mibs"
21+
profiles_path: "profiles"
22+
mongo:
23+
oid:
24+
database: "mib_server"
25+
collection: "oids"
26+
mib:
27+
database: "files"
28+
collection: "mib_files"
29+
profile:
30+
database: "profiles"
31+
collection: "profiles"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2021 Splunk Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
profiles:
17+
basev1:
18+
frequency: 10
19+
varBinds:
20+
# Syntax: [ "MIB-Files", "MIB object name" "MIB index number"]
21+
- ['SNMPv2-MIB', 'sysDescr']
22+
- ['SNMPv2-MIB', 'sysUpTime',0]
23+
- ['SNMPv2-MIB', 'sysName']
24+
- '1.3.6.1.2.1.2.*'
25+
basev1l2:
26+
frequency: 20
27+
varBinds:
28+
# Syntax: [ "MIB-Files", "MIB object name" "MIB index number"]
29+
- ['SNMPv2-MIB', 'sysDescr']
30+
- ['SNMPv2-MIB', 'sysUpTime',0]
31+
- ['SNMPv2-MIB', 'sysName']
32+
- ['IF-MIB','ifHCInOctets']
33+
- ['IF-MIB','ifHCOutOctets']
34+
- ['IF-MIB','ifInErrors']
35+
- ['IF-MIB','ifOutErrors']
36+
- ['IF-MIB','ifInDiscards']
37+
- ['IF-MIB','ifOutDiscards']
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2021 Splunk Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
profiles:
17+
basev2:
18+
patterns:
19+
- '*MY_DEFAULT_DEVICE_3*'
20+
frequency: 60
21+
varBinds:
22+
# Syntax: [ "MIB-Files", "MIB object name" "MIB index number"]
23+
- ['SNMPv2-MIB', 'sysDescr']
24+
- ['SNMPv2-MIB', 'sysUpTime',0]
25+
- ['SNMPv2-MIB', 'sysName']
26+
- '1.3.6.1.2.1.2.*'
27+
basev2l2:
28+
patterns:
29+
- '*MY_DEFAULT_DEVICE_3*'
30+
- '*MY_DEFAULT_DEVICE_NAME_3*'
31+
frequency: 120
32+
varBinds:
33+
# Syntax: [ "MIB-Files", "MIB object name" "MIB index number"]
34+
- ['SNMPv2-MIB', 'sysDescr']
35+
- ['SNMPv2-MIB', 'sysUpTime',0]
36+
- ['SNMPv2-MIB', 'sysName']
37+
- ['IF-MIB','ifHCInOctets']
38+
- ['IF-MIB','ifHCOutOctets']
39+
- ['IF-MIB','ifInErrors']
40+
- ['IF-MIB','ifOutErrors']
41+
- ['IF-MIB','ifInDiscards']
42+
- ['IF-MIB','ifOutDiscards']
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2021 Splunk Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
profiles:
17+
basev1:
18+
frequency: 10
19+
varBinds:
20+
# Syntax: [ "MIB-Files", "MIB object name" "MIB index number"]
21+
- ['SNMPv2-MIB', 'sysDescr']
22+
- ['SNMPv2-MIB', 'sysUpTime',0]
23+
- ['SNMPv2-MIB', 'sysName']
24+
- '1.3.6.1.2.1.2.*'
25+
basev1l2:
26+
frequency: 20
27+
varBinds:
28+
# Syntax: [ "MIB-Files", "MIB object name" "MIB index number"]
29+
- ['SNMPv2-MIB', 'sysDescr']
30+
- ['SNMPv2-MIB', 'sysUpTime',0]
31+
- ['SNMPv2-MIB', 'sysName']
32+
- ['IF-MIB','ifHCInOctets']
33+
- ['IF-MIB','ifHCOutOctets']
34+
- ['IF-MIB','ifInErrors']
35+
- ['IF-MIB','ifOutErrors']
36+
- ['IF-MIB','ifInDiscards']
37+
- ['IF-MIB','ifOutDiscards']
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2021 Splunk Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
profiles:
17+
basev1:
18+
frequency: 10
19+
varBinds:
20+
# Syntax: [ "MIB-Files", "MIB object name" "MIB index number"]
21+
- ['SNMPv2-MIB', 'sysDescr']
22+
- ['SNMPv2-MIB', 'sysUpTime',0]
23+
- ['SNMPv2-MIB', 'sysName']
24+
- '1.3.6.1.2.1.2.*'
25+
basev1l2:
26+
frequency: 20
27+
varBinds:
28+
# Syntax: [ "MIB-Files", "MIB object name" "MIB index number"]
29+
- ['SNMPv2-MIB', 'sysDescr']
30+
- ['SNMPv2-MIB', 'sysUpTime',0]
31+
- ['SNMPv2-MIB', 'sysName']
32+
- ['IF-MIB','ifHCInOctets']
33+
- ['IF-MIB','ifHCOutOctets']
34+
- ['IF-MIB','ifInErrors']
35+
- ['IF-MIB','ifOutErrors']
36+
- ['IF-MIB','ifInDiscards']
37+
- ['IF-MIB','ifOutDiscards']

0 commit comments

Comments
 (0)