2 * collectd - src/zeromq.c
3 * Copyright (C) 2005-2009 Florian octo Forster
4 * Copyright (C) 2009 Aman Gupta
5 * Copyright (C) 2010 Julien Ammous
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; only version 2 of the License is applicable.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 * Florian octo Forster <octo at verplant.org>
22 * Aman Gupta <aman at tmm1.net>
27 #include "common.h" /* auxiliary functions */
28 #include "plugin.h" /* plugin_register_*, plugin_dispatch_values */
33 // copy/paste from network.c ...
35 static value_list_t send_buffer_vl = VALUE_LIST_STATIC;
37 // we do not want to crypt here
40 static int network_dispatch_values (value_list_t *vl, /* {{{ */
46 || (strlen (vl->host) <= 0)
47 || (strlen (vl->plugin) <= 0)
48 || (strlen (vl->type) <= 0))
51 if (!check_receive_okay (vl))
54 char name[6*DATA_MAX_NAME_LEN];
55 FORMAT_VL (name, sizeof (name), vl);
56 name[sizeof (name) - 1] = 0;
57 DEBUG ("network plugin: network_dispatch_values: "
58 "NOT dispatching %s.", name);
60 stats_values_not_dispatched++;
64 assert (vl->meta == NULL);
66 vl->meta = meta_data_create ();
69 ERROR ("network plugin: meta_data_create failed.");
73 status = meta_data_add_boolean (vl->meta, "network:received", true);
76 ERROR ("network plugin: meta_data_add_boolean failed.");
77 meta_data_destroy (vl->meta);
84 status = meta_data_add_string (vl->meta, "network:username", username);
87 ERROR ("network plugin: meta_data_add_string failed.");
88 meta_data_destroy (vl->meta);
94 plugin_dispatch_values (vl);
95 stats_values_dispatched++;
97 meta_data_destroy (vl->meta);
101 } /* }}} int network_dispatch_values */
103 static int write_part_values (char **ret_buffer, int *ret_buffer_len, const data_set_t *ds, const value_list_t *vl)
109 part_header_t pkg_ph;
110 uint16_t pkg_num_values;
111 uint8_t *pkg_values_types;
117 num_values = vl->values_len;
118 packet_len = sizeof (part_header_t) + sizeof (uint16_t)
119 + (num_values * sizeof (uint8_t))
120 + (num_values * sizeof (value_t));
122 if (*ret_buffer_len < packet_len)
125 pkg_values_types = (uint8_t *) malloc (num_values * sizeof (uint8_t));
126 if (pkg_values_types == NULL)
128 ERROR ("network plugin: write_part_values: malloc failed.");
132 pkg_values = (value_t *) malloc (num_values * sizeof (value_t));
133 if (pkg_values == NULL)
135 free (pkg_values_types);
136 ERROR ("network plugin: write_part_values: malloc failed.");
140 pkg_ph.type = htons (TYPE_VALUES);
141 pkg_ph.length = htons (packet_len);
143 pkg_num_values = htons ((uint16_t) vl->values_len);
145 for (i = 0; i < num_values; i++)
147 pkg_values_types[i] = (uint8_t) ds->ds[i].type;
148 switch (ds->ds[i].type)
150 case DS_TYPE_COUNTER:
151 pkg_values[i].counter = htonll (vl->values[i].counter);
155 pkg_values[i].gauge = htond (vl->values[i].gauge);
159 pkg_values[i].derive = htonll (vl->values[i].derive);
162 case DS_TYPE_ABSOLUTE:
163 pkg_values[i].absolute = htonll (vl->values[i].absolute);
167 free (pkg_values_types);
169 ERROR ("network plugin: write_part_values: "
170 "Unknown data source type: %i",
173 } /* switch (ds->ds[i].type) */
174 } /* for (num_values) */
177 * Use `memcpy' to write everything to the buffer, because the pointer
178 * may be unaligned and some architectures, such as SPARC, can't handle
181 packet_ptr = *ret_buffer;
183 memcpy (packet_ptr + offset, &pkg_ph, sizeof (pkg_ph));
184 offset += sizeof (pkg_ph);
185 memcpy (packet_ptr + offset, &pkg_num_values, sizeof (pkg_num_values));
186 offset += sizeof (pkg_num_values);
187 memcpy (packet_ptr + offset, pkg_values_types, num_values * sizeof (uint8_t));
188 offset += num_values * sizeof (uint8_t);
189 memcpy (packet_ptr + offset, pkg_values, num_values * sizeof (value_t));
190 offset += num_values * sizeof (value_t);
192 assert (offset == packet_len);
194 *ret_buffer = packet_ptr + packet_len;
195 *ret_buffer_len -= packet_len;
197 free (pkg_values_types);
201 } /* int write_part_values */
203 static int write_part_number (char **ret_buffer, int *ret_buffer_len,
204 int type, uint64_t value)
209 part_header_t pkg_head;
214 packet_len = sizeof (pkg_head) + sizeof (pkg_value);
216 if (*ret_buffer_len < packet_len)
219 pkg_head.type = htons (type);
220 pkg_head.length = htons (packet_len);
221 pkg_value = htonll (value);
223 packet_ptr = *ret_buffer;
225 memcpy (packet_ptr + offset, &pkg_head, sizeof (pkg_head));
226 offset += sizeof (pkg_head);
227 memcpy (packet_ptr + offset, &pkg_value, sizeof (pkg_value));
228 offset += sizeof (pkg_value);
230 assert (offset == packet_len);
232 *ret_buffer = packet_ptr + packet_len;
233 *ret_buffer_len -= packet_len;
236 } /* int write_part_number */
238 static int write_part_string (char **ret_buffer, int *ret_buffer_len,
239 int type, const char *str, int str_len)
249 buffer_len = 2 * sizeof (uint16_t) + str_len + 1;
250 if (*ret_buffer_len < buffer_len)
253 pkg_type = htons (type);
254 pkg_length = htons (buffer_len);
256 buffer = *ret_buffer;
258 memcpy (buffer + offset, (void *) &pkg_type, sizeof (pkg_type));
259 offset += sizeof (pkg_type);
260 memcpy (buffer + offset, (void *) &pkg_length, sizeof (pkg_length));
261 offset += sizeof (pkg_length);
262 memcpy (buffer + offset, str, str_len);
264 memset (buffer + offset, '\0', 1);
267 assert (offset == buffer_len);
269 *ret_buffer = buffer + buffer_len;
270 *ret_buffer_len -= buffer_len;
273 } /* int write_part_string */
275 static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len,
276 value_t **ret_values, int *ret_num_values)
278 char *buffer = *ret_buffer;
279 size_t buffer_len = *ret_buffer_len;
294 NOTICE ("network plugin: packet is too short: "
295 "buffer_len = %zu", buffer_len);
299 memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
300 buffer += sizeof (tmp16);
301 pkg_type = ntohs (tmp16);
303 memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
304 buffer += sizeof (tmp16);
305 pkg_length = ntohs (tmp16);
307 memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
308 buffer += sizeof (tmp16);
309 pkg_numval = ntohs (tmp16);
311 assert (pkg_type == TYPE_VALUES);
313 exp_size = 3 * sizeof (uint16_t)
314 + pkg_numval * (sizeof (uint8_t) + sizeof (value_t));
315 if ((buffer_len < 0) || (buffer_len < exp_size))
317 WARNING ("network plugin: parse_part_values: "
319 "Chunk of size %zu expected, "
320 "but buffer has only %zu bytes left.",
321 exp_size, buffer_len);
325 if (pkg_length != exp_size)
327 WARNING ("network plugin: parse_part_values: "
328 "Length and number of values "
329 "in the packet don't match.");
333 pkg_types = (uint8_t *) malloc (pkg_numval * sizeof (uint8_t));
334 pkg_values = (value_t *) malloc (pkg_numval * sizeof (value_t));
335 if ((pkg_types == NULL) || (pkg_values == NULL))
339 ERROR ("network plugin: parse_part_values: malloc failed.");
343 memcpy ((void *) pkg_types, (void *) buffer, pkg_numval * sizeof (uint8_t));
344 buffer += pkg_numval * sizeof (uint8_t);
345 memcpy ((void *) pkg_values, (void *) buffer, pkg_numval * sizeof (value_t));
346 buffer += pkg_numval * sizeof (value_t);
348 for (i = 0; i < pkg_numval; i++)
350 switch (pkg_types[i])
352 case DS_TYPE_COUNTER:
353 pkg_values[i].counter = (counter_t) ntohll (pkg_values[i].counter);
357 pkg_values[i].gauge = (gauge_t) ntohd (pkg_values[i].gauge);
361 pkg_values[i].derive = (derive_t) ntohll (pkg_values[i].derive);
364 case DS_TYPE_ABSOLUTE:
365 pkg_values[i].absolute = (absolute_t) ntohll (pkg_values[i].absolute);
369 NOTICE ("network plugin: parse_part_values: "
370 "Don't know how to handle data source type %"PRIu8,
375 } /* switch (pkg_types[i]) */
378 *ret_buffer = buffer;
379 *ret_buffer_len = buffer_len - pkg_length;
380 *ret_num_values = pkg_numval;
381 *ret_values = pkg_values;
386 } /* int parse_part_values */
388 static int add_to_buffer (char *buffer, int buffer_size, /* {{{ */
389 value_list_t *vl_def,
390 const data_set_t *ds, const value_list_t *vl)
392 char *buffer_orig = buffer;
394 if (strcmp (vl_def->host, vl->host) != 0)
396 if (write_part_string (&buffer, &buffer_size, TYPE_HOST,
397 vl->host, strlen (vl->host)) != 0)
399 sstrncpy (vl_def->host, vl->host, sizeof (vl_def->host));
402 if (vl_def->time != vl->time)
404 if (write_part_number (&buffer, &buffer_size, TYPE_TIME,
405 (uint64_t) vl->time))
407 vl_def->time = vl->time;
410 if (vl_def->interval != vl->interval)
412 if (write_part_number (&buffer, &buffer_size, TYPE_INTERVAL,
413 (uint64_t) vl->interval))
415 vl_def->interval = vl->interval;
418 if (strcmp (vl_def->plugin, vl->plugin) != 0)
420 if (write_part_string (&buffer, &buffer_size, TYPE_PLUGIN,
421 vl->plugin, strlen (vl->plugin)) != 0)
423 sstrncpy (vl_def->plugin, vl->plugin, sizeof (vl_def->plugin));
426 if (strcmp (vl_def->plugin_instance, vl->plugin_instance) != 0)
428 if (write_part_string (&buffer, &buffer_size, TYPE_PLUGIN_INSTANCE,
430 strlen (vl->plugin_instance)) != 0)
432 sstrncpy (vl_def->plugin_instance, vl->plugin_instance, sizeof (vl_def->plugin_instance));
435 if (strcmp (vl_def->type, vl->type) != 0)
437 if (write_part_string (&buffer, &buffer_size, TYPE_TYPE,
438 vl->type, strlen (vl->type)) != 0)
440 sstrncpy (vl_def->type, ds->type, sizeof (vl_def->type));
443 if (strcmp (vl_def->type_instance, vl->type_instance) != 0)
445 if (write_part_string (&buffer, &buffer_size, TYPE_TYPE_INSTANCE,
447 strlen (vl->type_instance)) != 0)
449 sstrncpy (vl_def->type_instance, vl->type_instance, sizeof (vl_def->type_instance));
452 if (write_part_values (&buffer, &buffer_size, ds, vl) != 0)
455 return (buffer - buffer_orig);
456 } /* }}} int add_to_buffer */
458 static int parse_part_number (void **ret_buffer, size_t *ret_buffer_len,
461 char *buffer = *ret_buffer;
462 size_t buffer_len = *ret_buffer_len;
466 size_t exp_size = 2 * sizeof (uint16_t) + sizeof (uint64_t);
471 if ((buffer_len < 0) || ((size_t) buffer_len < exp_size))
473 WARNING ("network plugin: parse_part_number: "
475 "Chunk of size %zu expected, "
476 "but buffer has only %zu bytes left.",
477 exp_size, buffer_len);
481 memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
482 buffer += sizeof (tmp16);
483 pkg_type = ntohs (tmp16);
485 memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
486 buffer += sizeof (tmp16);
487 pkg_length = ntohs (tmp16);
489 memcpy ((void *) &tmp64, buffer, sizeof (tmp64));
490 buffer += sizeof (tmp64);
491 *value = ntohll (tmp64);
493 *ret_buffer = buffer;
494 *ret_buffer_len = buffer_len - pkg_length;
497 } /* int parse_part_number */
499 static int parse_part_string (void **ret_buffer, size_t *ret_buffer_len,
500 char *output, int output_len)
502 char *buffer = *ret_buffer;
503 size_t buffer_len = *ret_buffer_len;
506 size_t header_size = 2 * sizeof (uint16_t);
511 if ((buffer_len < 0) || (buffer_len < header_size))
513 WARNING ("network plugin: parse_part_string: "
515 "Chunk of at least size %zu expected, "
516 "but buffer has only %zu bytes left.",
517 header_size, buffer_len);
521 memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
522 buffer += sizeof (tmp16);
523 pkg_type = ntohs (tmp16);
525 memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
526 buffer += sizeof (tmp16);
527 pkg_length = ntohs (tmp16);
529 /* Check that packet fits in the input buffer */
530 if (pkg_length > buffer_len)
532 WARNING ("network plugin: parse_part_string: "
534 "Chunk of size %"PRIu16" received, "
535 "but buffer has only %zu bytes left.",
536 pkg_length, buffer_len);
540 /* Check that pkg_length is in the valid range */
541 if (pkg_length <= header_size)
543 WARNING ("network plugin: parse_part_string: "
545 "Header claims this packet is only %hu "
546 "bytes long.", pkg_length);
550 /* Check that the package data fits into the output buffer.
551 * The previous if-statement ensures that:
552 * `pkg_length > header_size' */
554 || ((size_t) output_len < ((size_t) pkg_length - header_size)))
556 WARNING ("network plugin: parse_part_string: "
557 "Output buffer too small.");
561 /* All sanity checks successfull, let's copy the data over */
562 output_len = pkg_length - header_size;
563 memcpy ((void *) output, (void *) buffer, output_len);
564 buffer += output_len;
566 /* For some very weird reason '\0' doesn't do the trick on SPARC in
568 if (output[output_len - 1] != 0)
570 WARNING ("network plugin: parse_part_string: "
571 "Received string does not end "
572 "with a NULL-byte.");
576 *ret_buffer = buffer;
577 *ret_buffer_len = buffer_len - pkg_length;
580 } /* int parse_part_string */
583 static int parse_packet (sockent_t *se, /* {{{ */
584 void *buffer, size_t buffer_size, int flags,
585 const char *username)
589 value_list_t vl = VALUE_LIST_INIT;
593 int packet_was_signed = (flags & PP_SIGNED);
594 int packet_was_encrypted = (flags & PP_ENCRYPTED);
595 int printed_ignore_warning = 0;
596 #endif /* HAVE_LIBGCRYPT */
599 memset (&vl, '\0', sizeof (vl));
600 memset (&n, '\0', sizeof (n));
603 while ((status == 0) && (0 < buffer_size)
604 && ((unsigned int) buffer_size > sizeof (part_header_t)))
609 memcpy ((void *) &pkg_type,
612 memcpy ((void *) &pkg_length,
613 (void *) (buffer + sizeof (pkg_type)),
614 sizeof (pkg_length));
616 pkg_length = ntohs (pkg_length);
617 pkg_type = ntohs (pkg_type);
619 if (pkg_length > buffer_size)
621 /* Ensure that this loop terminates eventually */
622 if (pkg_length < (2 * sizeof (uint16_t)))
625 if (pkg_type == TYPE_ENCR_AES256)
627 status = parse_part_encr_aes256 (se,
628 &buffer, &buffer_size, flags);
631 ERROR ("network plugin: Decrypting AES256 "
633 "with status %i.", status);
638 else if ((se->data.server.security_level == SECURITY_LEVEL_ENCRYPT)
639 && (packet_was_encrypted == 0))
641 if (printed_ignore_warning == 0)
643 INFO ("network plugin: Unencrypted packet or "
644 "part has been ignored.");
645 printed_ignore_warning = 1;
647 buffer = ((char *) buffer) + pkg_length;
650 #endif /* HAVE_LIBGCRYPT */
651 else if (pkg_type == TYPE_SIGN_SHA256)
653 status = parse_part_sign_sha256 (se,
654 &buffer, &buffer_size, flags);
657 ERROR ("network plugin: Verifying HMAC-SHA-256 "
659 "with status %i.", status);
664 else if ((se->data.server.security_level == SECURITY_LEVEL_SIGN)
665 && (packet_was_encrypted == 0)
666 && (packet_was_signed == 0))
668 if (printed_ignore_warning == 0)
670 INFO ("network plugin: Unsigned packet or "
671 "part has been ignored.");
672 printed_ignore_warning = 1;
674 buffer = ((char *) buffer) + pkg_length;
677 #endif /* HAVE_LIBGCRYPT */
678 else if (pkg_type == TYPE_VALUES)
680 status = parse_part_values (&buffer, &buffer_size,
681 &vl.values, &vl.values_len);
685 network_dispatch_values (&vl, username);
689 else if (pkg_type == TYPE_TIME)
692 status = parse_part_number (&buffer, &buffer_size,
696 vl.time = (time_t) tmp;
697 n.time = (time_t) tmp;
700 else if (pkg_type == TYPE_INTERVAL)
703 status = parse_part_number (&buffer, &buffer_size,
706 vl.interval = (int) tmp;
708 else if (pkg_type == TYPE_HOST)
710 status = parse_part_string (&buffer, &buffer_size,
711 vl.host, sizeof (vl.host));
713 sstrncpy (n.host, vl.host, sizeof (n.host));
715 else if (pkg_type == TYPE_PLUGIN)
717 status = parse_part_string (&buffer, &buffer_size,
718 vl.plugin, sizeof (vl.plugin));
720 sstrncpy (n.plugin, vl.plugin,
723 else if (pkg_type == TYPE_PLUGIN_INSTANCE)
725 status = parse_part_string (&buffer, &buffer_size,
727 sizeof (vl.plugin_instance));
729 sstrncpy (n.plugin_instance,
731 sizeof (n.plugin_instance));
733 else if (pkg_type == TYPE_TYPE)
735 status = parse_part_string (&buffer, &buffer_size,
736 vl.type, sizeof (vl.type));
738 sstrncpy (n.type, vl.type, sizeof (n.type));
740 else if (pkg_type == TYPE_TYPE_INSTANCE)
742 status = parse_part_string (&buffer, &buffer_size,
744 sizeof (vl.type_instance));
746 sstrncpy (n.type_instance, vl.type_instance,
747 sizeof (n.type_instance));
749 else if (pkg_type == TYPE_MESSAGE)
751 status = parse_part_string (&buffer, &buffer_size,
752 n.message, sizeof (n.message));
758 else if ((n.severity != NOTIF_FAILURE)
759 && (n.severity != NOTIF_WARNING)
760 && (n.severity != NOTIF_OKAY))
762 INFO ("network plugin: "
763 "Ignoring notification with "
764 "unknown severity %i.",
767 else if (n.time <= 0)
769 INFO ("network plugin: "
770 "Ignoring notification with "
773 else if (strlen (n.message) <= 0)
775 INFO ("network plugin: "
776 "Ignoring notification with "
777 "an empty message.");
781 plugin_dispatch_notification (&n);
784 else if (pkg_type == TYPE_SEVERITY)
787 status = parse_part_number (&buffer, &buffer_size,
790 n.severity = (int) tmp;
794 DEBUG ("network plugin: parse_packet: Unknown part"
795 " type: 0x%04hx", pkg_type);
796 buffer = ((char *) buffer) + pkg_length;
798 } /* while (buffer_size > sizeof (part_header_t)) */
800 if (status == 0 && buffer_size > 0)
801 WARNING ("network plugin: parse_packet: Received truncated "
802 "packet, try increasing `MaxPacketSize'");
805 } /* }}} int parse_packet */
814 ////////////////////////////
815 //// END OF COPY / PASTE ///
816 ////////////////////////////
821 static const char *config_keys[] =
826 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
829 static char *zmq_listen_on = NULL;
830 static char *zmq_send_to = NULL;
833 static int thread_running = 1;
834 static pthread_t listen_thread_id;
835 static void *zmq_context = NULL;
836 static void *push_socket = NULL;
837 static void *pull_socket = NULL;
844 static int my_config (const char *key, const char *value)
846 if( strcasecmp(key, "ListenOn") == 0 ) {
847 if( zmq_listen_on != NULL ) {
849 zmq_listen_on = NULL;
852 if( zmq_listen_on = strdup(value)) == NULL ) {
856 else if( strcasecmp(key, "SendDataTo") == 0 ) {
857 if( zmq_send_to != NULL ) {
862 if( zmq_send_to = strdup(value)) == NULL ) {
871 static void *receive_thread (void __attribute__((unused)) *arg)
878 while( thread_running ) {
879 status = zmq_msg_init(&msg);
880 assert( status == 0 );
881 if( zmq_recv(&pull_socket, &msg, 0) != 0 ) {
882 WARNING("zmq_recv : %s", zmq_strerror(errno));
886 data = zmq_msg_data(&msg);
887 data_size = zmq_msg_size(&msg);
889 parse_packet(NULL, data, data_size,
891 /* username = */ NULL);
897 static int plugin_init (void)
899 int major, minor, patch, status;
900 zmq_version (&major, &minor, &patch);
903 // init zeromq (1 I/O thread)
904 zmq_context = zmq_init(1);
905 if( zmq_context == NULL ) {
906 ERROR("zmq_init : %s", zmq_strerror(errno));
910 // start listening socket
911 if( zmq_listen_on != NULL ) {
912 pull_socket = zmq_socket(zmq_context, ZMQ_PULL);
913 if( pull_socket == NULL ) {
914 ERROR("zmq_socket : %s", zmq_strerror(errno));
918 // and bind it to the inbound queue
919 if( zmq_bind(pull_socket, zmq_listen_on) != 0 ) {
920 ERROR("zmq_bind : %s", zmq_strerror(errno));
924 // listenining thread
925 status = pthread_create(&listen_thread_id,
926 NULL /* no attributes */,
928 NULL /* no argument */);
931 ERROR("network: pthread_create failed: %s", strerror(errno));
935 INFO("ZeroMQ listening on %s", zmq_listen_on);
939 if( zmq_send_to != NULL ) {
940 push_socket = zmq_socket(zmq_context, ZMQ_PUSH);
942 if( push_socket == NULL ) {
943 ERROR("zmq_socket : %s", zmq_strerror(errno));
947 // and connect to remote host
948 if( zmq_connect(push_socket, zmq_send_to) != 0 ) {
949 ERROR("zmq_connect : %s", zmq_strerror(errno));
953 INFO("ZeroMQ pushing to %s", zmq_send_to);
958 INFO("ZeroMQ plugin initialized (zeromq v%d.%d.%d).", major, minor, patch);
964 static int write_notification (const notification_t *n, user_data_t __attribute__((unused)) *user_data)
969 void free_data(void *data, void *hint)
974 #define PACKET_SIZE 512
976 static int write_value (const data_set_t *ds, const value_list_t *vl,
977 user_data_t __attribute__((unused)) *user_data)
981 int send_buffer_size = PACKET_SIZE, real_size;
983 send_buffer = malloc(PACKET_SIZE);
984 if( send_buffer == NULL ) {
985 ERROR("Unable to allocate memory for send_buffer, aborting write");
990 memset(send_buffer, 0, PACKET_SIZE);
992 real_size = add_to_buffer(send_buffer, send_buffer_size, &send_buffer_vl, ds, vl);
994 // zeromq will free the memory when needed by calling the free_data function
995 if( zmq_msg_init_data(&msg, send_buffer, real_size, free_data, NULL) != 0 ) {
996 ERROR("zmq_msg_init : %s", zmq_strerror(errno));
1000 // try to send the message
1001 if( zmq_send(push_socket, &msg, ZMQ_NOBLOCK) != 0 ) {
1002 if( errno == EAGAIN ) {
1003 WARNING("ZeroMQ: Cannot send message, queue is full");
1006 ERROR("zmq_send : %s", zmq_strerror(errno));
1014 static int my_shutdown (void)
1019 pthread_join(listen_thread_id, NULL);
1021 if( zmq_term(zmq_context) != 0 ) {
1022 ERROR("zmq_term : %s", zmq_strerror(errno));
1030 void module_register (void)
1032 plugin_register_config("zeromq", my_config, config_keys, config_keys_num);
1033 plugin_register_init("zeromq", plugin_init);
1034 plugin_register_write("zeromq", write_value,
1035 /* user_data = */ NULL);
1036 plugin_register_notification ("network", write_notification,
1037 /* user_data = */ NULL);
1038 plugin_register_shutdown ("zeromq", my_shutdown);