def test_riemann_protobuf(self): proto = riemann.RiemannProtocol() event = Event('ok', 'sky', 'Sky has not fallen', 1.0, 60.0) # Well, I guess we'll just assume this is right message = proto.encodeMessage([event])
def test_udp_riemann(self): event = Event('ok', 'sky', 'Sky has not fallen', 1.0, 60.0) protocol = riemann.RiemannUDP('127.0.0.1', 5555) self.endpoint = reactor.listenUDP(0, protocol) yield protocol.sendEvents([event])
def _aggregator_test(self, m1, m2, aggregator, delta): service = self.make_service({}) ev1 = Event('ok', 'num', 'Number', m1, delta, hostname='localhost', aggregation=aggregator) ev2 = Event('ok', 'num', 'Number', m2, delta, hostname='localhost', aggregation=aggregator) ev1.time = 1 ev2.time = delta+1 q1 = service._aggregateQueue([ev1]) ev = service._aggregateQueue([ev2])[0] self.assertEqual(q1, []) return ev.metric
def test_state_match(self): service = self.make_service({ 'interval': 1.0, 'ttl': 60.0, 'sources': [{ 'source': 'tensor.sources.linux.basic.Network', 'interval': 2.0, 'critical': { 'network.\\w+.tx_bytes': '> 500' }, 'warning': { 'network.\\w+.tx_bytes': '> 100' }, 'service': 'network' }] }) ev1 = Event('ok', 'network.foo.tx_bytes', 'net1', 50, 1, hostname='localhost') ev2 = Event('ok', 'network.foo.tx_bytes', 'net1', 1000, 1, hostname='localhost') ev3 = Event('ok', 'network.foo.tx_bytes', 'net1', 200, 1, hostname='localhost') service.setStates(service.sources[0], [ev1, ev2, ev3]) self.assertEqual(ev1.state, 'ok') self.assertEqual(ev2.state, 'critical') self.assertEqual(ev3.state, 'warning')
def test_tcp_riemann(self): event = Event('ok', 'sky', 'Sky has not fallen', 1.0, 60.0) end = TCP4ClientEndpoint(reactor, "localhost", 5555) p = yield connectProtocol(end, riemann.RiemannProtocol()) yield p.sendEvents([event]) p.transport.loseConnection()
def test_riemann_protobuf_with_attributes(self): proto = riemann.RiemannProtocol() event = Event('ok', 'sky', 'Sky has not fallen', 1.0, 60.0, attributes={"chicken": "little"}) e = proto.encodeEvent(event) attrs = e.attributes self.assertEqual(len(attrs), 1) self.assertEqual(attrs[0].key, "chicken") self.assertEqual(attrs[0].value, "little")
def _aggregator_test(self, m1, m2, aggregator, delta): service = self.make_service({}) ev1 = Event('ok', 'num', 'Number', m1, delta, hostname='localhost', aggregation=aggregator) ev2 = Event('ok', 'num', 'Number', m2, delta, hostname='localhost', aggregation=aggregator) ev1.time = 1 ev2.time = delta + 1 q1 = service._aggregateQueue([ev1]) ev = service._aggregateQueue([ev2])[0] self.assertEqual(q1, []) return ev.metric
def test_service_sends_event_after_reconnect(self): self.patch(RiemannClientFactory, 'initialDelay', 0.1) factory = yield self.start_riemann_server() service = self.make_service({"port": factory.get_host().port}) yield service.startService() # Send an event to make sure everything's happy [] = yield factory.wait_for_messages(0) source = self.make_source(service) event = Event('ok', 'sky', 'Sky has not fallen', 1.0, 60.0, hostname='localhost') service.sendEvent(source, event) [msg] = yield factory.wait_for_messages(1) [event] = msg.events self.assertEqual(event.description, 'Sky has not fallen') # Disconnect and hope we reconnect [output] = service.outputs[None] yield output.connector.disconnect() yield wait(0.2) # Send another event to make sure everything's still happy [_] = yield factory.wait_for_messages(1) event = Event('ok', 'sky', 'Sky has not fallen', 1.0, 60.0, hostname='localhost') service.sendEvent(source, event) [_, msg2] = yield factory.wait_for_messages(2) [event] = msg.events self.assertEqual(event.description, 'Sky has not fallen')
def test_service_sends_event(self): factory = yield self.start_riemann_server() service = self.make_service({"port": factory.get_host().port}) yield service.startService() [] = yield factory.wait_for_messages(0) event = Event('ok', 'sky', 'Sky has not fallen', 1.0, 60.0, hostname='localhost') service.sendEvent(event) [msg] = yield factory.wait_for_messages(1) [event] = msg.events self.assertEqual(event.description, 'Sky has not fallen')
def test_source_routing(self): service = self.make_service({ 'interval': 1.0, 'ttl': 60.0, 'sources': [{ 'source': 'tensor.sources.linux.basic.LoadAverage', 'interval': 2.0, 'route': 'out1', 'service': 'load' }] }) output1 = FakeOutput({}, service) output2 = FakeOutput({}, service) [source] = service.sources service.outputs = {'out1': [output1], 'out2': [output2]} event = Event('ok', 'load', 'load', 1, 1, hostname='localhost') service.sendEvent(source, event) yield wait(0.2) self.assertEqual(len(output1.events), 1) self.assertEqual(output2.events, None) output1.events = None source.config['route'] = ['out1', 'out2'] service.sendEvent(source, event) yield wait(0.2) self.assertEqual(len(output1.events), 1) self.assertEqual(len(output2.events), 1)