def write_log(events): try: with riemann_client.client.QueuedClient(riemann_client.transport.TCPTransport("localhost", 5555)) as client: for event in events: client.event(**event) client.flush() except Exception as exc: pass
def handle_stat(client, container, line): data = json.loads(line.decode('utf-8')) events = riemann.handle_stat(data, container._info) for event in events: client.event(**event) client.flush()
def check(cmd, match): with Popen(cmd, stdout=PIPE, shell=False).stdout as stdout: output = stdout.readlines() if re.match(match, output[0]): state = "ok" else: state = "critical" description = ''.join(output) service = service="%s %s: %s" % (cmd[0], cmd[1], ZPOOL) client.event(service=service, state=state, description=description, tags=["raid"], ttl=TTL)
def handle_log(client, container, line): if len(line) == 8: container.logs_stream = 'stdout' if line[0] == 1 else 'stderr' return events = riemann.handle_log(line, container._info, container.logs_stream) for event in events: client.event(**event) client.flush()
def publish_events(events, client): for event in events: try: client.event(**event) print "SENT:", event except riemann_client.transport.RiemannError as ex: print "Riemann FAILED:", ex, event except Exception as ex: print "FAILED:", ex, event raise ex
def send_function(args, client): """Sends a single command to Riemann""" event = client.event( time=args.time, state=args.state, host=args.event_host, description=args.description, service=args.service, tags=args.tags, ttl=args.ttl, metric_f=args.metric) if args.print_message: print(str(event).strip())
def test_attributes(self, client, unique): client.event(attributes={'key': unique}) assert unique in client.transport.string.getvalue()
def test_tags(self, client, unique): client.event(tags=[unique]) assert unique in client.transport.string.getvalue()
def test_custom_hostname(self, client): event = client.event(host="test.example.com").events[0] assert "test.example.com" == event.host assert "test.example.com" in client.transport.string.getvalue()
def test_default_hostname(self, client, event): event = client.event().events[0] assert socket.gethostname() == event.host assert socket.gethostname() in client.transport.string.getvalue()
def test_service(self, client): client.event(service='test event') assert 'test event' in client.transport.string.getvalue()
def test_tags(self, client): client.event(tags=['tag-1', 'tag-2']) assert "tag-1" in client.transport.string.getvalue()
def event(client): """Send and return a blank event""" message = client.event() return message.events[0]