Skip to content

Commit

Permalink
Merge pull request #23 from votdev/issue_22
Browse files Browse the repository at this point in the history
  • Loading branch information
votdev authored May 14, 2020
2 parents 838b50a + 47ad8c0 commit 08cd07e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v1.4
* Issue #22: Prevent Python type errors when sending an SNMP trap.

v1.3

* Add 'trap-default-severity' configuration option.
Expand Down
2 changes: 1 addition & 1 deletion prometheus-webhook-snmp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import click
from prometheus_webhook_snmp import utils


__version__ = "1.3"
__version__ = "1.4"


pass_context = click.make_pass_decorator(utils.Context, ensure=True)
Expand Down
2 changes: 1 addition & 1 deletion prometheus-webhook-snmp.spec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Please submit bugfixes or comments via http://bugs.opensuse.org/

Name: prometheus-webhook-snmp
Version: 1.3
Version: 1.4
Release: 0
Summary: Prometheus Alertmanager receiver for SNMP traps
License: GPL-3.0
Expand Down
8 changes: 4 additions & 4 deletions prometheus_webhook_snmp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ def send_snmp_trap(config, trap_data):
var_binds = hlapi.NotificationType(hlapi.ObjectIdentity(trap_data['oid']))
var_binds.addVarBinds(
hlapi.ObjectType(hlapi.ObjectIdentity(oids['alertname']),
hlapi.OctetString(trap_data['alertname'])),
hlapi.OctetString(trap_data['alertname'] or '')),
hlapi.ObjectType(hlapi.ObjectIdentity(oids['status']),
hlapi.OctetString(trap_data['status'])),
hlapi.ObjectType(hlapi.ObjectIdentity(oids['severity']),
hlapi.OctetString(trap_data['severity'])),
hlapi.ObjectType(hlapi.ObjectIdentity(oids['instance']),
hlapi.OctetString(trap_data['instance'])),
hlapi.OctetString(trap_data['instance'] or '')),
hlapi.ObjectType(hlapi.ObjectIdentity(oids['job']),
hlapi.OctetString(trap_data['job'])),
hlapi.OctetString(trap_data['job'] or '')),
hlapi.ObjectType(hlapi.ObjectIdentity(oids['description']),
hlapi.OctetString(trap_data['description'])),
hlapi.OctetString(trap_data['description'] or '')),
hlapi.ObjectType(hlapi.ObjectIdentity(oids['labels']),
hlapi.OctetString(json.dumps(trap_data['labels']))),
hlapi.ObjectType(hlapi.ObjectIdentity(oids['timestamp']),
Expand Down
19 changes: 18 additions & 1 deletion tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from pyfakefs import fake_filesystem

from prometheus_webhook_snmp.utils import parse_notification, Config
from prometheus_webhook_snmp.utils import parse_notification, Config, \
send_snmp_trap

NOTIFICATION_FIRING = {
'receiver': 'test-01',
Expand Down Expand Up @@ -116,6 +117,22 @@ def test_parse_notification_no_oid(self):
self.assertEqual(trap_data['timestamp'], 1554110387)
self.assertIsInstance(trap_data['rawdata'], dict)

def test_send_snmp_trap(self):
config = Config()
self.assertIsInstance(config['trap_default_severity'], str)
send_snmp_trap(config, {
'oid': '1.3.6.1.4.1.50495.15.1.2.1',
'alertname': None,
'status': 'resolved',
'severity': config['trap_default_severity'],
'instance': None,
'job': None,
'description': None,
'labels': {},
'timestamp': 1554110387,
'rawdata': {}
})


class ConfigTestCase(unittest.TestCase):
fs = fake_filesystem.FakeFilesystem()
Expand Down

0 comments on commit 08cd07e

Please sign in to comment.