Skip to content

Commit 3b4fbab

Browse files
author
Anze
committed
Test for Handling missing values
1 parent ca9b95a commit 3b4fbab

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

snmpcollector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _apply_expression_to_results(snmp_results, methods, expression, output_path)
5757
'v': value,
5858
})
5959
except NoValueForOid:
60-
log.warn(f'Missing value for oid index: {oid_index}')
60+
log.warning(f'Missing value for oid index: {oid_index}')
6161
return result
6262

6363
else:

test_snmpcollector.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,24 @@ def test_expression_add():
6464
{ 'p': 'snmp.test123.asdf.3', 'v': 62500.0 },
6565
]
6666
assert _apply_expression_to_results(results, methods, expression, output_path) == expected_result
67+
68+
def test_snmpwalk_missing_value():
69+
results = [
70+
[
71+
SNMPVariable(oid='1.3.6.1.4.1.2021.13.16.2.1.3', oid_index='1', value=60000, snmp_type='GAUGE'),
72+
SNMPVariable(oid='1.3.6.1.4.1.2021.13.16.2.1.3', oid_index='2', value=61000, snmp_type='GAUGE'),
73+
SNMPVariable(oid='1.3.6.1.4.1.2021.13.16.2.1.3', oid_index='3', value=62000, snmp_type='GAUGE'),
74+
],
75+
[
76+
SNMPVariable(oid='1.3.6.1.4.1.2021.13.16.2.2.2', oid_index='1', value=10, snmp_type='GAUGE'),
77+
SNMPVariable(oid='1.3.6.1.4.1.2021.13.16.2.2.2', oid_index='2', value=10, snmp_type='GAUGE'),
78+
],
79+
]
80+
methods = ['walk' if isinstance(x, list) else 'get' for x in results]
81+
expression = '$1 / $2'
82+
output_path = 'snmp.test123.asdf'
83+
expected_result = [
84+
{ 'p': 'snmp.test123.asdf.1', 'v': 6000.0 },
85+
{ 'p': 'snmp.test123.asdf.2', 'v': 6100.0 },
86+
]
87+
assert _apply_expression_to_results(results, methods, expression, output_path) == expected_result

0 commit comments

Comments
 (0)