Ejemplo n.º 1
0
double Timestamp::toDouble() const {
    return timeval2double(value);
}
Ejemplo n.º 2
0
int read_child_check(char *bufstart, char *bufend, struct timeval * end_time) {
    char *attribute  = NULL;
    char *attribute2 = NULL;
    char *attribute3 = NULL;
    char *error      = NULL;
    char temp_buffer[GM_BUFFERSIZE];
    double end_time_d;
    struct timeval start_time;

    /* child check number */
    if ((attribute=read_multi_attribute(bufstart,bufend,"no")) == NULL) {
        return 0;
    } else {
        /* skip parent check */
        if (!strcmp(attribute,"0")) {
            return 0;
        }
        gm_log( GM_LOG_TRACE, "child check: %d\n", atoi(attribute));
    }

    /* service description */
    if ((attribute=read_multi_attribute(bufstart,bufend,"name")) == NULL)
        return 0;
    mod_gm_opt->service=gm_strdup(attribute);
    gm_log( GM_LOG_TRACE, "service_description: %s\n", mod_gm_opt->service);

    /* return code */
    if ((attribute=read_multi_attribute(bufstart,bufend,"rc")) == NULL)
        return 0;
    mod_gm_opt->return_code=atoi(attribute);
    gm_log( GM_LOG_TRACE, "mod_gm_opt->return_code: %d\n", mod_gm_opt->return_code);

    /* runtime */
    if ((attribute=read_multi_attribute(bufstart,bufend,"runtime")) == NULL)
        return 0;
    end_time_d   = timeval2double(end_time);
    double2timeval(end_time_d - atof(attribute), &start_time);

    mod_gm_opt->starttime.tv_sec  = start_time.tv_sec;
    mod_gm_opt->starttime.tv_usec = start_time.tv_usec;
    gm_log( GM_LOG_TRACE, "starttime: %d.%d\n", mod_gm_opt->starttime.tv_sec, mod_gm_opt->starttime.tv_usec);


    /* end time is the execution time of send_multi itself */
    mod_gm_opt->finishtime.tv_sec  = end_time->tv_sec;
    mod_gm_opt->finishtime.tv_usec = end_time->tv_usec;
    gm_log( GM_LOG_TRACE, "endtime: %d.%d\n", mod_gm_opt->finishtime.tv_sec, mod_gm_opt->finishtime.tv_usec);

    /* message */
    if ((attribute=read_multi_attribute(bufstart,bufend,"output")) == NULL)
        return 0;

    /* stderr */
    if ((error=read_multi_attribute(bufstart,bufend,"error")) == NULL) {
        return 0;
    /* if error found: 'error' -> ' [error]' */
    } else if (*error) {
        *(--error)='[';
        *(--error)=' ';
        strcat(error,"]");
    }

    /* performance data with multi headers */
    if ((attribute2=read_multi_attribute(bufstart,bufend,"performance")) == NULL) {
        snprintf( temp_buffer, sizeof( temp_buffer )-1, "%s%s", decode_xml(attribute), decode_xml(error));
    } else if ((attribute3=read_multi_attribute(bufstart,bufend,"pplugin")) == NULL) {
        return 0;
    } else {
        attribute2 = trim(attribute2);
        attribute2 = decode_xml(attribute2);

        /* do we have a single quote performance label?
           then single quote the whole multi header */
        if (*attribute2 == '\'') {
            attribute2++;
            snprintf( temp_buffer, sizeof( temp_buffer )-1, "%s%s|\'%s::%s::%s", decode_xml(attribute), decode_xml(error), mod_gm_opt->service, decode_xml(attribute3), decode_xml(attribute2));
        /* normal header without single quotes */
        } else {
            snprintf( temp_buffer, sizeof( temp_buffer )-1, "%s%s|%s::%s::%s", decode_xml(attribute), decode_xml(error), mod_gm_opt->service, decode_xml(attribute3), decode_xml(attribute2));
        }
    }
    mod_gm_opt->message=gm_strdup(temp_buffer);
    gm_log( GM_LOG_TRACE, "mod_gm_opt->message: %s\n", mod_gm_opt->message);

    return 1;
}
Ejemplo n.º 3
0
/* submit result */
int submit_result() {
    char * buf;
    char * temp_buffer;
    char * result;
    struct timeval now;
    struct timeval starttime;
    struct timeval finishtime;
    int resultsize;

    gettimeofday(&now, NULL);
    if(mod_gm_opt->has_starttime == FALSE) {
        starttime = now;
    } else {
        starttime = mod_gm_opt->starttime;
    }

    if(mod_gm_opt->has_finishtime == FALSE) {
        finishtime = now;
    } else {
        finishtime = mod_gm_opt->finishtime;
    }

    if(mod_gm_opt->has_latency == FALSE) {
        mod_gm_opt->latency.tv_sec  = 0;
        mod_gm_opt->latency.tv_usec = 0;
    }

    /* escape newline */
    buf = gm_escape_newlines(mod_gm_opt->message, GM_DISABLED);
    free(mod_gm_opt->message);
    mod_gm_opt->message = gm_strdup(buf);
    free(buf);

    gm_log( GM_LOG_TRACE, "queue: %s\n", mod_gm_opt->result_queue );
    resultsize = sizeof(char) * strlen(mod_gm_opt->message) + GM_BUFFERSIZE;
    result = gm_malloc(resultsize);
    snprintf( result, resultsize-1, "type=%s\nhost_name=%s\nstart_time=%Lf\nfinish_time=%Lf\nlatency=%Lf\nreturn_code=%i\nsource=send_gearman\n",
              mod_gm_opt->active == GM_ENABLED ? "active" : "passive",
              mod_gm_opt->host,
              timeval2double(&starttime),
              timeval2double(&finishtime),
              timeval2double(&mod_gm_opt->latency),
              mod_gm_opt->return_code
            );

    temp_buffer = gm_malloc(resultsize);
    if(mod_gm_opt->service != NULL) {
        temp_buffer[0]='\x0';
        strcat(temp_buffer, "service_description=");
        strcat(temp_buffer, mod_gm_opt->service);
        strcat(temp_buffer, "\n");
        strcat(result, temp_buffer);
    }

    if(mod_gm_opt->message != NULL) {
        temp_buffer[0]='\x0';
        strcat(temp_buffer, "output=");
        strcat(temp_buffer, mod_gm_opt->message);
        strcat(temp_buffer, "\n");
        strcat(result, temp_buffer);
    }
    strcat(result, "\n");

    gm_log( GM_LOG_TRACE, "data:\n%s\n", result);

    if(add_job_to_queue( &client,
                         mod_gm_opt->server_list,
                         mod_gm_opt->result_queue,
                         NULL,
                         result,
                         GM_JOB_PRIO_NORMAL,
                         GM_DEFAULT_JOB_RETRIES,
                         mod_gm_opt->transportmode,
                         TRUE
                        ) == GM_OK) {
        gm_log( GM_LOG_TRACE, "send_result_back() finished successfully\n" );

        if( mod_gm_opt->dupserver_num ) {
            if(add_job_to_queue( &client_dup,
                                 mod_gm_opt->dupserver_list,
                                 mod_gm_opt->result_queue,
                                 NULL,
                                 result,
                                 GM_JOB_PRIO_NORMAL,
                                 GM_DEFAULT_JOB_RETRIES,
                                 mod_gm_opt->transportmode,
                                 TRUE
                            ) == GM_OK) {
                gm_log( GM_LOG_TRACE, "send_result_back() finished successfully for duplicate server.\n" );
            }
            else {
                gm_log( GM_LOG_TRACE, "send_result_back() finished unsuccessfully for duplicate server\n" );
            }
        }
    }
    else {
        gm_log( GM_LOG_TRACE, "send_result_back() finished unsuccessfully\n" );
        free(result);
        free(temp_buffer);
        return( STATE_UNKNOWN );
    }
    free(result);
    free(temp_buffer);
    return( STATE_OK );
}