- if (g == NULL) {
- fprintf(stderr, "Could not allocate JSON generator.\n");
- return (0);
- }
-
- if (yajl_gen_map_open(g) != yajl_gen_status_ok)
- goto err;
- if (yajl_gen_string(g, (u_char *)"message", strlen("message")) !=
- yajl_gen_status_ok)
- goto err;
- if (strlen(n->message) > 0) {
- if (yajl_gen_string(g, (u_char *)n->message,
- strlen(n->message)) !=
- yajl_gen_status_ok)
- goto err;
- } else {
- if (yajl_gen_string(g, (u_char *)"notification without a message",
- strlen("notification without a message")) !=
- yajl_gen_status_ok)
- goto err;
- }
-
- if (strlen(n->host) > 0) {
- if (yajl_gen_string(g, (u_char *)"host", strlen("host")) !=
- yajl_gen_status_ok)
- goto err;
- if (yajl_gen_string(g, (u_char *)n->host, strlen(n->host)) !=
- yajl_gen_status_ok)
- goto err;
-
- }
- if (strlen(n->plugin) > 0) {
- if (yajl_gen_string(g, (u_char *)"plugin", strlen("plugin")) !=
- yajl_gen_status_ok)
- goto err;
- if (yajl_gen_string(g, (u_char *)n->plugin, strlen(n->plugin)) !=
- yajl_gen_status_ok)
- goto err;
- }
- if (strlen(n->plugin_instance) > 0) {
- if (yajl_gen_string(g, (u_char *)"plugin_instance",
- strlen("plugin_instance")) !=
- yajl_gen_status_ok)
- goto err;
- if (yajl_gen_string(g, (u_char *)n->plugin_instance,
- strlen(n->plugin_instance)) !=
- yajl_gen_status_ok)
- goto err;
- }
- if (strlen(n->type) > 0) {
- if (yajl_gen_string(g, (u_char *)"type", strlen("type")) !=
- yajl_gen_status_ok)
- goto err;
- if (yajl_gen_string(g, (u_char *)n->type, strlen(n->type)) !=
- yajl_gen_status_ok)
- goto err;
- }
- if (strlen(n->type_instance) > 0) {
- if (yajl_gen_string(g, (u_char *)"type_instance",
- strlen("type_instance")) !=
- yajl_gen_status_ok)
- goto err;
- if (yajl_gen_string(g, (u_char *)n->type_instance,
- strlen(n->type_instance)) !=
- yajl_gen_status_ok)
- goto err;
- }
-
- if (yajl_gen_string(g, (u_char *)"severity",
- strlen("severity")) !=
- yajl_gen_status_ok)
- goto err;
-
- switch (n->severity) {
- case NOTIF_FAILURE:
- if (yajl_gen_string(g, (u_char *)"failure",
- strlen("failure")) !=
- yajl_gen_status_ok)
- goto err;
- break;
- case NOTIF_WARNING:
- if (yajl_gen_string(g, (u_char *)"warning",
- strlen("warning")) !=
- yajl_gen_status_ok)
- goto err;
- break;
- case NOTIF_OKAY:
- if (yajl_gen_string(g, (u_char *)"ok",
- strlen("ok")) !=
- yajl_gen_status_ok)
- goto err;
- break;
- default:
- if (yajl_gen_string(g, (u_char *)"unknown",
- strlen("unknown")) !=
- yajl_gen_status_ok)
- goto err;
- break;
- }
-
- log_logstash_print (g, LOG_INFO, (n->time != 0) ? n->time : cdtime ());
- return (0);
-
- err:
- yajl_gen_free(g);
- fprintf(stderr, "Could not correctly generate JSON notification\n");
- return (0);
+ if (g == NULL) {
+ fprintf(stderr, "Could not allocate JSON generator.\n");
+ return (0);
+ }
+
+ if (yajl_gen_map_open(g) != yajl_gen_status_ok)
+ goto err;
+ if (yajl_gen_string(g, (u_char *)"message", strlen("message")) !=
+ yajl_gen_status_ok)
+ goto err;
+ if (strlen(n->message) > 0) {
+ if (yajl_gen_string(g, (u_char *)n->message, strlen(n->message)) !=
+ yajl_gen_status_ok)
+ goto err;
+ } else {
+ if (yajl_gen_string(g, (u_char *)"notification without a message",
+ strlen("notification without a message")) !=
+ yajl_gen_status_ok)
+ goto err;
+ }
+
+ if (strlen(n->host) > 0) {
+ if (yajl_gen_string(g, (u_char *)"host", strlen("host")) !=
+ yajl_gen_status_ok)
+ goto err;
+ if (yajl_gen_string(g, (u_char *)n->host, strlen(n->host)) !=
+ yajl_gen_status_ok)
+ goto err;
+ }
+ if (strlen(n->plugin) > 0) {
+ if (yajl_gen_string(g, (u_char *)"plugin", strlen("plugin")) !=
+ yajl_gen_status_ok)
+ goto err;
+ if (yajl_gen_string(g, (u_char *)n->plugin, strlen(n->plugin)) !=
+ yajl_gen_status_ok)
+ goto err;
+ }
+ if (strlen(n->plugin_instance) > 0) {
+ if (yajl_gen_string(g, (u_char *)"plugin_instance",
+ strlen("plugin_instance")) != yajl_gen_status_ok)
+ goto err;
+ if (yajl_gen_string(g, (u_char *)n->plugin_instance,
+ strlen(n->plugin_instance)) != yajl_gen_status_ok)
+ goto err;
+ }
+ if (strlen(n->type) > 0) {
+ if (yajl_gen_string(g, (u_char *)"type", strlen("type")) !=
+ yajl_gen_status_ok)
+ goto err;
+ if (yajl_gen_string(g, (u_char *)n->type, strlen(n->type)) !=
+ yajl_gen_status_ok)
+ goto err;
+ }
+ if (strlen(n->type_instance) > 0) {
+ if (yajl_gen_string(g, (u_char *)"type_instance",
+ strlen("type_instance")) != yajl_gen_status_ok)
+ goto err;
+ if (yajl_gen_string(g, (u_char *)n->type_instance,
+ strlen(n->type_instance)) != yajl_gen_status_ok)
+ goto err;
+ }
+
+ if (yajl_gen_string(g, (u_char *)"severity", strlen("severity")) !=
+ yajl_gen_status_ok)
+ goto err;
+
+ switch (n->severity) {
+ case NOTIF_FAILURE:
+ if (yajl_gen_string(g, (u_char *)"failure", strlen("failure")) !=
+ yajl_gen_status_ok)
+ goto err;
+ break;
+ case NOTIF_WARNING:
+ if (yajl_gen_string(g, (u_char *)"warning", strlen("warning")) !=
+ yajl_gen_status_ok)
+ goto err;
+ break;
+ case NOTIF_OKAY:
+ if (yajl_gen_string(g, (u_char *)"ok", strlen("ok")) != yajl_gen_status_ok)
+ goto err;
+ break;
+ default:
+ if (yajl_gen_string(g, (u_char *)"unknown", strlen("unknown")) !=
+ yajl_gen_status_ok)
+ goto err;
+ break;
+ }
+
+ log_logstash_print(g, LOG_INFO, (n->time != 0) ? n->time : cdtime());
+ return (0);
+
+err:
+ yajl_gen_free(g);
+ fprintf(stderr, "Could not correctly generate JSON notification\n");
+ return (0);