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
feat: create default profile definition in MIB server #56
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a770351
feat: create default profile definition in MIB server
weliasz 55871bf
fix: fix failing build
weliasz 1364f56
fix: fix failing build
weliasz a86393a
fix: fix failing build
weliasz 4528553
fix: fix failing build
weliasz f33a02e
feat: PR comments
weliasz 44dbdb6
fix: build fix
weliasz c465e9b
fix: build fix
weliasz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,37 @@ | ||||||||||||||||||||||||||||||||||
# Copyright 2021 Splunk Inc. | ||||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||||||||
# you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||||||||
# You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||||
# http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||||
# Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||||||
# distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||||||||
# See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||||||
# limitations under the License. | ||||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
profiles: | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
basev1: | ||||||||||||||||||||||||||||||||||
frequency: 10 | ||||||||||||||||||||||||||||||||||
varBinds: | ||||||||||||||||||||||||||||||||||
# Syntax: [ "MIB-Files", "MIB object name" "MIB index number"] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysDescr'] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysUpTime',0] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysName'] | ||||||||||||||||||||||||||||||||||
- '1.3.6.1.2.1.2.*' | ||||||||||||||||||||||||||||||||||
basev1l2: | ||||||||||||||||||||||||||||||||||
frequency: 20 | ||||||||||||||||||||||||||||||||||
varBinds: | ||||||||||||||||||||||||||||||||||
# Syntax: [ "MIB-Files", "MIB object name" "MIB index number"] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysDescr'] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysUpTime',0] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysName'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifHCInOctets'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifHCOutOctets'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifInErrors'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifOutErrors'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifInDiscards'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifOutDiscards'] |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# ######################################################################## | ||
# Copyright 2021 Splunk Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ######################################################################## | ||
|
||
import os | ||
|
||
import yaml | ||
|
||
|
||
def merge_profiles(directory, root_name): | ||
result = {} | ||
merged_profiles = {} | ||
for root, directories, files in os.walk(directory, topdown=False): | ||
okuzhel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for name in files: | ||
with open(os.path.join(root, name), "r") as stream: | ||
data = yaml.safe_load(stream) | ||
merged_profiles.update(data[root_name]) | ||
result[root_name] = merged_profiles | ||
return result |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# | ||
# Copyright 2021 Splunk Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
snmp: | ||
mibs: | ||
dir: "mibs/pysnmp" | ||
load_list: "lookups/mibs_list.csv" | ||
mibs_path: "mibs" | ||
profiles_path: "profiles" | ||
mongo: | ||
oid: | ||
database: "mib_server" | ||
collection: "oids" | ||
mib: | ||
database: "files" | ||
collection: "mib_files" | ||
profile: | ||
database: "profiles" | ||
collection: "profiles" |
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 | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,37 @@ | ||||||||||||||||||||||||||||||||||
# Copyright 2021 Splunk Inc. | ||||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||||||||
# you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||||||||
# You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||||
# http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||||
# Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||||||
# distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||||||||
# See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||||||
# limitations under the License. | ||||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
profiles: | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
basev1: | ||||||||||||||||||||||||||||||||||
frequency: 10 | ||||||||||||||||||||||||||||||||||
varBinds: | ||||||||||||||||||||||||||||||||||
# Syntax: [ "MIB-Files", "MIB object name" "MIB index number"] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysDescr'] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysUpTime',0] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysName'] | ||||||||||||||||||||||||||||||||||
- '1.3.6.1.2.1.2.*' | ||||||||||||||||||||||||||||||||||
basev1l2: | ||||||||||||||||||||||||||||||||||
frequency: 20 | ||||||||||||||||||||||||||||||||||
varBinds: | ||||||||||||||||||||||||||||||||||
# Syntax: [ "MIB-Files", "MIB object name" "MIB index number"] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysDescr'] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysUpTime',0] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysName'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifHCInOctets'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifHCOutOctets'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifInErrors'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifOutErrors'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifInDiscards'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifOutDiscards'] |
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 | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,42 @@ | ||||||||||||||||||||||||||||||||||
# Copyright 2021 Splunk Inc. | ||||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||||||||
# you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||||||||
# You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||||
# http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||||
# Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||||||
# distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||||||||
# See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||||||
# limitations under the License. | ||||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
profiles: | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
basev2: | ||||||||||||||||||||||||||||||||||
patterns: | ||||||||||||||||||||||||||||||||||
- '*MY_DEFAULT_DEVICE_3*' | ||||||||||||||||||||||||||||||||||
frequency: 60 | ||||||||||||||||||||||||||||||||||
varBinds: | ||||||||||||||||||||||||||||||||||
# Syntax: [ "MIB-Files", "MIB object name" "MIB index number"] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysDescr'] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysUpTime',0] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysName'] | ||||||||||||||||||||||||||||||||||
- '1.3.6.1.2.1.2.*' | ||||||||||||||||||||||||||||||||||
basev2l2: | ||||||||||||||||||||||||||||||||||
patterns: | ||||||||||||||||||||||||||||||||||
- '*MY_DEFAULT_DEVICE_3*' | ||||||||||||||||||||||||||||||||||
- '*MY_DEFAULT_DEVICE_NAME_3*' | ||||||||||||||||||||||||||||||||||
frequency: 120 | ||||||||||||||||||||||||||||||||||
varBinds: | ||||||||||||||||||||||||||||||||||
# Syntax: [ "MIB-Files", "MIB object name" "MIB index number"] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysDescr'] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysUpTime',0] | ||||||||||||||||||||||||||||||||||
- ['SNMPv2-MIB', 'sysName'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifHCInOctets'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifHCOutOctets'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifInErrors'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifOutErrors'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifInDiscards'] | ||||||||||||||||||||||||||||||||||
- ['IF-MIB','ifOutDiscards'] |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# ######################################################################## | ||
# Copyright 2021 Splunk Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ######################################################################## | ||
|
||
from unittest import TestCase | ||
|
||
from splunk_connect_for_snmp_mib_server.profiles import merge_profiles | ||
|
||
|
||
class ProfileLoaderTest(TestCase): | ||
def test_multiple_files_merging(self): | ||
okuzhel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
merged_profiles = merge_profiles("tests/profiles", "profiles")["profiles"] | ||
|
||
assert len(merged_profiles.keys()) == 4 | ||
assert "basev1" in merged_profiles.keys() | ||
assert "basev2" in merged_profiles.keys() | ||
assert "basev1l2" in merged_profiles.keys() | ||
assert "basev2l2" in merged_profiles.keys() |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.