END_TEST START_TEST (test_riemann_simple_query) { riemann_client_t *client; riemann_message_t *response; ck_assert (riemann_query (NULL, "service = \"test-simple\"") == NULL); ck_assert_errno (-errno, ENOTCONN); client = riemann_client_create (RIEMANN_CLIENT_TCP, "127.0.0.1", 5555); riemann_send (client, RIEMANN_EVENT_FIELD_SERVICE, "test-simple", RIEMANN_EVENT_FIELD_STATE, "ok", RIEMANN_EVENT_FIELD_NONE); response = riemann_query (client, "service = \"test-simple\""); ck_assert (response != NULL); ck_assert_int_eq (response->ok, 1); riemann_message_free (response); riemann_client_free (client); }
static int riemann_notification(const notification_t *n, user_data_t *ud) /* {{{ */ { int status; struct riemann_host *host = ud->data; Msg *msg; msg = riemann_notification_to_protobuf (host, n); if (msg == NULL) return (-1); status = riemann_send (host, msg); if (status != 0) ERROR ("write_riemann plugin: riemann_send failed with status %i", status); riemann_msg_protobuf_free (msg); return (status); } /* }}} int riemann_notification */
static int riemann_write(const data_set_t *ds, /* {{{ */ const value_list_t *vl, user_data_t *ud) { int status; struct riemann_host *host = ud->data; Msg *msg; msg = riemann_value_list_to_protobuf (host, ds, vl); if (msg == NULL) return (-1); status = riemann_send (host, msg); if (status != 0) ERROR ("write_riemann plugin: riemann_send failed with status %i", status); riemann_msg_protobuf_free (msg); return status; } /* }}} int riemann_write */
END_TEST START_TEST (test_riemann_simple_communicate_event) { riemann_client_t *client; riemann_message_t *response; client = riemann_client_create (RIEMANN_CLIENT_TCP, "127.0.0.1", 5555); response = riemann_communicate_event (client, RIEMANN_EVENT_FIELD_HOST, "localhost", RIEMANN_EVENT_FIELD_SERVICE, "test_riemann_simple_communicate_event", RIEMANN_EVENT_FIELD_STATE, "ok", RIEMANN_EVENT_FIELD_NONE); ck_assert (response != NULL); ck_assert_int_eq (response->ok, 1); ck_assert_int_eq (response->n_events, 0); riemann_message_free (response); response = riemann_communicate_event (client, 256, RIEMANN_EVENT_FIELD_NONE); ck_assert (response == NULL); ck_assert_errno (-errno, EPROTO); riemann_send (client, RIEMANN_EVENT_FIELD_HOST, "localhost", RIEMANN_EVENT_FIELD_SERVICE, "test_riemann_simple_communicate_event", RIEMANN_EVENT_FIELD_STATE, "ok", RIEMANN_EVENT_FIELD_NONE); response = riemann_communicate_event (client, RIEMANN_EVENT_FIELD_NONE); ck_assert (response != NULL); ck_assert (response->has_ok == 1); ck_assert (response->ok == 1); riemann_message_free (response); riemann_client_free (client); }