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 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- initial commit
- Loading branch information
Showing
6 changed files
with
174 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# | ||
# 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. | ||
# |
48 changes: 48 additions & 0 deletions
48
splunk_connect_for_snmp_poller/manager/static/interface_mib_utililities.py
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,48 @@ | ||
# | ||
# 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 logging | ||
|
||
from splunk_connect_for_snmp_poller.manager.realtime.interface_mib import InterfaceMib | ||
from splunk_connect_for_snmp_poller.utilities import multi_key_lookup | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def __network_interface_enricher_attributes(config_as_dict): | ||
# TODO: we just assume here the whole structre of the poller's configuration | ||
# main file. If such section does not exist we simply do not anything. | ||
return "IF-MIB", multi_key_lookup( | ||
config_as_dict, ("enricher", "oidFamily", "IF-MIB") | ||
) | ||
|
||
|
||
def extract_network_interface_data_from_config(config_as_dict): | ||
parent_oid, splunk_dimensions = __network_interface_enricher_attributes( | ||
config_as_dict | ||
) | ||
result = [] | ||
if splunk_dimensions: | ||
for splunk_dimension in splunk_dimensions: | ||
for key in splunk_dimension.keys(): | ||
result.append( | ||
{ | ||
"oid_name": f"{InterfaceMib.IF_MIB_METRIC_SUFFIX}{key}", | ||
"splunk_dimension_name": splunk_dimension[key], | ||
} | ||
) | ||
logger.info(f"IF-MIB additional attributes for Splunk: {result}") | ||
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
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,99 @@ | ||
# | ||
# 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_poller.manager.realtime.interface_mib import InterfaceMib | ||
from splunk_connect_for_snmp_poller.manager.static.interface_mib_utililities import ( | ||
extract_network_interface_data_from_config, | ||
) | ||
|
||
parsed_config_root_with_error = { | ||
"enricher_with_error": { | ||
"oidFamily": { | ||
"IF-MIB": [ | ||
{"ifIndex": "interface_index"}, | ||
{"ifDescr": "interface_desc"}, | ||
] | ||
} | ||
} | ||
} | ||
|
||
parsed_config_family_with_error = { | ||
"enricher": { | ||
"oidFamily_with_error": { | ||
"IF-MIB": [ | ||
{"ifIndex": "interface_index"}, | ||
{"ifDescr": "interface_desc"}, | ||
] | ||
} | ||
} | ||
} | ||
|
||
parsed_config_if_mib_with_error = { | ||
"enricher": { | ||
"oidFamily": { | ||
"IF-MIB_with_error": [ | ||
{"ifIndex": "interface_index"}, | ||
{"ifDescr": "interface_desc"}, | ||
] | ||
} | ||
} | ||
} | ||
|
||
parsed_config_if_mib_without_elements = {"enricher": {"oidFamily": {"IF-MIB": []}}} | ||
|
||
parsed_config_correct = { | ||
"enricher": { | ||
"oidFamily": { | ||
"IF-MIB": [ | ||
{"ifIndex": "interface_index"}, | ||
{"ifDescr": "interface_desc"}, | ||
] | ||
} | ||
} | ||
} | ||
|
||
|
||
class ExtractEnricherDataFromConfigTest(TestCase): | ||
def test_config_does_not_exist(self): | ||
result = extract_network_interface_data_from_config(None) | ||
self.assertIsNotNone(result) | ||
self.assertTrue(len(result) == 0) | ||
|
||
def test_config_does_not_have_the_required_key(self): | ||
for test_config in ( | ||
parsed_config_root_with_error, | ||
parsed_config_family_with_error, | ||
parsed_config_if_mib_with_error, | ||
parsed_config_if_mib_without_elements, | ||
): | ||
result = extract_network_interface_data_from_config(test_config) | ||
self.assertTrue(len(result) == 0) | ||
|
||
def test_correct_config(self): | ||
result = extract_network_interface_data_from_config(parsed_config_correct) | ||
self.assertTrue(len(result) == 2) | ||
expected_result = [ | ||
{ | ||
"oid_name": f"{InterfaceMib.IF_MIB_METRIC_SUFFIX}ifIndex", | ||
"splunk_dimension_name": "interface_index", | ||
}, | ||
{ | ||
"oid_name": f"{InterfaceMib.IF_MIB_METRIC_SUFFIX}ifDescr", | ||
"splunk_dimension_name": "interface_desc", | ||
}, | ||
] | ||
self.assertEqual(result, expected_result) |