Beispiel #1
0
    def test_publish_snmpv3(self, mock_snmp):
        mock_snmp.return_value = SnmpHandler('user',
                                             '1.3.6.1.4.1.3375.2.100',
                                             port=TEST_PORT)
        with UdpReceiver(TEST_PORT) as server:
            with patch.dict('os.environ'):
                os.environ['OBSRVBL_SNMP_ENABLED'] = 'True'
                os.environ['OBSRVBL_SNMP_OBJECTID'] = '1.3.6.1.4.1.3375.2.100'
                os.environ['OBSRVBL_SNMP_SERVER'] = 'localhost'
                os.environ['OBSRVBL_SNMP_USER'] = '******'
                os.environ['OBSRVBL_SNMP_VERSION'] = '3'
                os.environ['OBSRVBL_SNMPV3_ENGINEID'] = '01020304'
                os.environ['OBSRVBL_SNMPV3_PASSPHRASE'] = 'opensesame'

                pub = NotificationPublisher()

                messages = []
                messages.append('foobar')
                pub.publish(messages, 'error')

            msg = server.pop()
            self.assertRegexpMatches(msg, 'foobar')

        self.assertEquals(mock_snmp.call_args_list, [
            call(objectID='1.3.6.1.4.1.3375.2.100',
                 port=162,
                 host='localhost',
                 user='******',
                 version='3',
                 passcode='opensesame',
                 engineID='01020304'),
        ])
Beispiel #2
0
    def test_v2_params(self, mock_cmd):
        handler = SnmpHandler('user1',
                              '1.3.6.1.4.1.3375.2.100',
                              host='127.0.0.1',
                              port='9001')
        self.logger.addHandler(handler)

        self.logger.error('{"hello, my name is json": true}')

        self.assertEquals(len(mock_cmd.call_args_list), 1)
        self.assertEquals(
            mock_cmd.call_args_list[0][0][0],
            [
                'snmptrap',
                '-v',
                '2c',
                '-c',
                'user1',
                '127.0.0.1:9001',
                "''",  # empty for uptime
                '.1.3.6.1.4.1.3375.2.100',
                '.1.3.6.1.4.1.3375.2.100.0',
                's',
                "'{\"hello, my name is json\": true}'",
            ])
Beispiel #3
0
    def test_wont_log_warning(self, mock_cmd):
        handler = SnmpHandler('user', '1.3.6.1.4.1.3375.2.100')
        self.logger.addHandler(handler)

        self.logger.warn("onoes!")
        self.logger.warn("what!!")
        self.logger.warn("huh?")

        self.assertEquals(len(mock_cmd.call_args_list), 0)
Beispiel #4
0
    def test_v3_params(self, mock_cmd):
        handler = SnmpHandler('user1',
                              '1.3.6.1.4.1.3375.2.100',
                              version='3',
                              host='127.0.0.1',
                              port='9001',
                              passcode='passcode1',
                              engineID='0607080910',
                              authentication='MD5')
        self.logger.addHandler(handler)

        self.logger.error('{"hello, my name is json": true}')

        self.assertEquals(len(mock_cmd.call_args_list), 1)
        self.assertEquals(
            mock_cmd.call_args_list[0][0][0],
            [
                'snmptrap',
                '-v',
                '3',
                '-e',
                '0x0607080910',
                '-u',
                'user1',
                '-a',
                'MD5',
                '-x',
                'AES',
                '-A',
                'passcode1',
                '-l',
                'authNoPriv',
                '127.0.0.1:9001',
                "''",  # empty for uptime
                '.1.3.6.1.4.1.3375.2.100',
                '.1.3.6.1.4.1.3375.2.100.0',
                's',
                "'{\"hello, my name is json\": true}'",
            ])
Beispiel #5
0
    def test_defaults(self, mock_cmd):
        handler = SnmpHandler('user', '1.3.6.1.4.1.3375.2.100')
        self.logger.addHandler(handler)

        self.logger.error("onoes!")

        self.assertEquals(len(mock_cmd.call_args_list), 1)
        self.assertEquals(
            mock_cmd.call_args_list[0][0][0],
            [
                'snmptrap',
                '-v',
                '2c',
                '-c',
                'user',
                'localhost:162',
                "''",  # empty for uptime
                '.1.3.6.1.4.1.3375.2.100',
                '.1.3.6.1.4.1.3375.2.100.0',
                's',
                "'onoes!'",
            ])