Skip to content

Commit

Permalink
Merge debb589 into 59b0403
Browse files Browse the repository at this point in the history
  • Loading branch information
road-cycling committed May 14, 2020
2 parents 59b0403 + debb589 commit 476e7c2
Show file tree
Hide file tree
Showing 3 changed files with 276 additions and 1 deletion.
204 changes: 204 additions & 0 deletions tests/plugins/polling/interface/data/results_enabled.json
@@ -0,0 +1,204 @@
[
{
"dimensions": [
{
"dimension_name": "parent_interface_media_type",
"dimension_value": "<not set>"
},
{
"dimension_name": "alias",
"dimension_value": "Gi0"
},
{
"dimension_name": "parent_interface_port_speed",
"dimension_value": "<not set>"
},
{
"dimension_name": "port_speed",
"dimension_value": "<not set>"
},
{
"dimension_name": "interface_name",
"dimension_value": "GigabitEthernet0"
},
{
"dimension_name": "parent_interface_configured_speed",
"dimension_value": "<not set>"
},
{
"dimension_name": "media_type",
"dimension_value": "ethernetCsmacd"
},
{
"dimension_name": "parent_interface_name",
"dimension_value": "<not set>"
},
{
"dimension_name": "configured_speed",
"dimension_value": "10"
},
{
"dimension_name": "description",
"dimension_value": "GigabitEthernet0"
},
{
"dimension_name": "interface_index",
"dimension_value": "5"
}
],
"metrics": [
{
"metric_name": "broadcast_packets_out",
"metric_type": "counter",
"metric_value": 0
},
{
"metric_name": "errors_giants",
"metric_type": "counter",
"metric_value": 0
},
{
"metric_name": "errors_crc",
"metric_type": "counter",
"metric_value": 0
},
{
"metric_name": "mtu",
"metric_type": "gauge",
"metric_value": 1500
},
{
"metric_name": "unicast_packets_out",
"metric_type": "counter",
"metric_value": 0
},
{
"metric_name": "oper_admin_state_mismatch",
"metric_type": "gauge",
"metric_value": 1
},
{
"metric_name": "bits_in",
"metric_type": "counter",
"metric_value": 0
},
{
"metric_name": "broadcast_packets_in",
"metric_type": "counter",
"metric_value": 0
},
{
"metric_name": "bits_out",
"metric_type": "counter",
"metric_value": 0
},
{
"metric_name": "total_packets_out",
"metric_type": "counter",
"metric_value": 0
},
{
"metric_name": "total_packets_in",
"metric_type": "counter",
"metric_value": 0
},
{
"metric_name": "admin_state",
"metric_type": "gauge",
"metric_value": 1
},
{
"metric_name": "errors_frame",
"metric_type": "counter",
"metric_value": 0
},
{
"metric_name": "unicast_packets_in",
"metric_type": "counter",
"metric_value": 0
},
{
"metric_name": "discards_out",
"metric_type": "counter",
"metric_value": 0
},
{
"metric_name": "oper_state",
"metric_type": "gauge",
"metric_value": 2
},
{
"metric_name": "multicast_packets_out",
"metric_type": "counter",
"metric_value": 0
},
{
"metric_name": "errors_in",
"metric_type": "counter",
"metric_value": 0
},
{
"metric_name": "multicast_packets_in",
"metric_type": "counter",
"metric_value": 0
},
{
"metric_name": "configured_speed",
"metric_type": "gauge",
"metric_value": 10
},
{
"metric_name": "discards_in",
"metric_type": "counter",
"metric_value": 0
},
{
"metric_name": "errors_out",
"metric_type": "counter",
"metric_value": 0
}
],
"metrics_group_interval": 60,
"metrics_group_schema_version": "0.2",
"metrics_group_type": "interface",
"resource": {
"resource_class": "network",
"resource_endpoint": "127.0.0.1",
"resource_id": "test_id",
"resource_metadata": {
"_resource_ttl": "604800",
"model": "model"
},
"resource_plugin": "dummy",
"resource_site": "test_site",
"resource_subclass": "test_subclass",
"resource_type": "test_type"
}
},
{
"dimensions": [],
"metrics": [
{
"metric_name": "interface_polling_status",
"metric_type": "gauge",
"metric_value": 0
}
],
"metrics_group_interval": 60,
"metrics_group_schema_version": "0.2",
"metrics_group_type": "status",
"resource": {
"resource_class": "network",
"resource_endpoint": "127.0.0.1",
"resource_id": "test_id",
"resource_metadata": {
"_resource_ttl": "604800",
"model": "model"
},
"resource_plugin": "dummy",
"resource_site": "test_site",
"resource_subclass": "test_subclass",
"resource_type": "test_type"
}
}
]
Expand Up @@ -38,7 +38,12 @@ class TestPluginPollingDeviceInterfaceMetrics(SNMPPollingPluginTestFramework, un
u'enrichment': {
u'preload': u'self:interface'
},
u'x509': {u'x509_secured_requests': 0}
u'x509': {
u'x509_secured_requests': 0
},
u'dimension': {
'include_interface_index': 0
}
}

plugin_metrics_function = "get_results"
Expand Down Expand Up @@ -118,3 +123,58 @@ def test_invalid_resource_endpoint(self):
self._snmp_conf['timeout'] = self.snmp_timeout
self.set_panoptes_resource()
self.set_plugin_context()


class TestPluginPollingDeviceInterfaceMetricsDimensionConfExcluded(TestPluginPollingDeviceInterfaceMetrics):
plugin_conf = {
u'Core': {
u'name': u'Test Plugin',
u'module': u'test_plugin'
},
u'main': {
u'execute_frequency': 60,
u'resource_filter': u'resource_class = "network"'
},
u'snmp': {
u'timeout': 10,
u'retries': 1,
u'non_repeaters': 0,
u'max_repetitions': 25
},
u'enrichment': {
u'preload': u'self:interface'
},
u'x509': {
u'x509_secured_requests': 0
}
}


class TestPluginPollingDeviceInterfaceMetricsEnabled(TestPluginPollingDeviceInterfaceMetrics):
plugin_conf = {
u'Core': {
u'name': u'Test Plugin',
u'module': u'test_plugin'
},
u'main': {
u'execute_frequency': 60,
u'resource_filter': u'resource_class = "network"'
},
u'snmp': {
u'timeout': 10,
u'retries': 1,
u'non_repeaters': 0,
u'max_repetitions': 25
},
u'enrichment': {
u'preload': u'self:interface'
},
u'x509': {
u'x509_secured_requests': 0
},
u'dimension': {
'include_interface_index': 1
}
}

results_data_file = "results_enabled.json"
Expand Up @@ -328,6 +328,7 @@ def _smart_add_dimension(self, method, dimension_name, index):
_DEFAULT_DIMENSION_VALUE))

def get_results(self):

self._polling_status = PanoptesPollingStatus(resource=self.resource,
execute_frequency=self.execute_frequency,
logger=self.logger,
Expand All @@ -351,6 +352,16 @@ def get_results(self):
if_interface_metrics = self._getif_table_stats()
ifx_interface_metrics = self._getifx_table_stats()

if self._plugin_config.get('dimension', {}).get('include_interface_index', 0):
"""
#Interface indexes are ephemeral and can change after the restart of a device or the snmp agent.
To add this field as a dimension include the following in the .panoptes-plugin configuration file.
[dimension]
include_interface_index = 1
"""
self._DIMENSION_MAP.update({'interface_index': lambda x: str(x)})

# https://github.com/PyCQA/pylint/issues/1694
for i in self.interface_indices: # pylint: disable=E1133
if i not in interface_metrics:
Expand Down

0 comments on commit 476e7c2

Please sign in to comment.