예제 #1
0
파일: boot.c 프로젝트: marker55/hp-ams
void LOG_OS_SHUTDOWN()
{
    int rc;

    if (!rec_init() ) {
        return;
    }

   /* do Code Descriptor */
    if ((rc = doCodeDescriptor(s_ams_rec_handle,
                               s_ams_rec_class,
                               REC_CODE_AMS_OS_SHUTDOWN,
                               0,
                               REC_SEV_CHANGE,
                               REC_BINARY_DATA,
                               REC_VIS_CUSTOMER,
                               REC_CODE_AMS_OS_SHUTDOWN_STR)) != RECORDER_OK) {
        DEBUGMSGTL(("rec:rec_log_osboot","OS Boot  register descriptor failed %d\n", rc));
        return;
    }

    /* Let's go ahead and set the code for */
    if ((rc = rec_api3(s_ams_rec_handle, REC_CODE_AMS_OS_SHUTDOWN)) 
                != RECORDER_OK) {
        DEBUGMSGTL(("rec:log", "OS Shutdown rec_code_set failed (%d)\n", rc));
        return;
    }

    // Log the record
    if ((rc = rec_api6(s_ams_rec_handle, (const char*)0, 0)) != 
             RECORDER_OK) {
        DEBUGMSGTL(("rec:log", "OS Shutdown LogRecorderData failed (%d)\n",rc));
    }

    DEBUGMSGTL(("rec:log", "OS Shutdown Logged record for code %d\n", 
                REC_CODE_AMS_OS_SHUTDOWN));
    return;

}
예제 #2
0
파일: procusage.c 프로젝트: vejta66/hp-ams
void LOG_PROCESSOR_USAGE()
{
    int j = 0;
    int rc;
    int num_descript;
    size_t toc_sz = 0;
    size_t max_toc_sz = (10 * sizeof(descript));
    struct dirent **cpuent;
    descript *toc;
    descript *ttoc;

    /* do something different for VmWare and Solaris */
    cpucount = scandir("/sys/class/cpuid", &cpuent, file_select, versionsort);
    DEBUGMSGTL(("rec:rec_log:rec_log_proc_usage","cpucount = %d\n", cpucount));

    if (cpucount == -1) 
        return;

    if (!rec_init() )
        return;

    /* do Code Descriptor */
    if ((rc = doCodeDescriptor(s_ams_rec_handle, 
                               s_ams_rec_class, 
			       REC_CODE_AMS_PROCESSOR_USAGE,
			       0,
			       REC_SEV_PERIOD,
			       REC_BINARY_DATA,
			       REC_VIS_CUSTOMER,
			       REC_CODE_AMS_PROCESSOR_USAGE_STR)) 
            != RECORDER_OK) {
        DEBUGMSGTL(("rec:rec_log_error", 
		    "Host Name register descriptor failed %d\n", rc));
        return;
    }

    num_descript = sizeof(fld)/sizeof(field) * cpucount;
    DEBUGMSGTL(("rec:rec_log:rec_log_proc_usage","ProcUsage num_descript = %d\n", 			num_descript));

    toc_sz = sizeof(descript) * num_descript;
    toc = malloc(toc_sz);
    DEBUGMSGTL(("rec:log","Initial Processor Usage toc_sz = %ld\n", toc_sz));

    /* now do the field descriptor */
    memset(toc, 0, toc_sz);
    for (j = 0; j < num_descript; j++ ) {
        toc[j].flags = REC_FLAGS_DESCRIPTOR | REC_FLAGS_DESC_FIELD;
        toc[j].classs = s_ams_rec_class;
        toc[j].code = REC_CODE_AMS_PROCESSOR_USAGE;
        toc[j].field = j;
        toc[j].severity_type = REC_SEV_PERIOD | fld[j%2].tp;
        toc[j].format = fld[j%2].sz;
        toc[j].visibility = REC_VIS_CUSTOMER;
        strncpy(toc[j].desc, fld[j%2].nm, 
                sizeof(toc[j].desc) - strlen(toc[j].desc - 1));
        strcat(toc[j].desc, cpuent[j/2]->d_name);
        DEBUGMSGTL(("rec:log", "toc[i] = %p\n", &toc[j]));
        dump_chunk("rec:rec_log","descriptor", (const u_char *)&toc[j], 96);
        if (j % 2)
            free(cpuent[j/2]);
    }
    dump_chunk("rec:rec_log", "toc", (const u_char *)toc, toc_sz);
    free(cpuent);

    ttoc = toc;
    while (toc_sz > RECORDER_MAX_BLOB_SIZE) {
        DEBUGMSGTL(("rec:log","Processor Usage ttoc = %p\n", ttoc));
        DEBUGMSGTL(("rec:log","Processor Usage toc_sz = %ld\n", toc_sz));
        if ((rc = rec_api4_field(s_ams_rec_handle, 
                                      max_toc_sz,
                                      ttoc)) != RECORDER_OK) {
            DEBUGMSGTL(("rec:rec_log_error","Proc Usage register descriptor failed %d\n", 
                        rc));
            return;
        }
        toc_sz = toc_sz - max_toc_sz;
        ttoc = (void *)ttoc + max_toc_sz;
    }
    if ((rc = rec_api4_field(s_ams_rec_handle, toc_sz, ttoc)) 
                    != RECORDER_OK) {
        DEBUGMSGTL(("rec:rec_log_error","Proc Usage register descriptor failed %d\n", rc));
        return;
    }
    free(toc);

    if (!proc_usage_reinit) 
        switch (log_interval) {
            case 0:
                rec_log_proc_usage(0, &cpucount);
                break;
            case 1:
                snmp_alarm_register(60, SA_REPEAT, &rec_log_proc_usage, &cpucount);
                break;
            case 2:
                snmp_alarm_register(600, SA_REPEAT, &rec_log_proc_usage, &cpucount);
                break;
            case 3:
                snmp_alarm_register(3600, SA_REPEAT, &rec_log_proc_usage, &cpucount);
                break;
        }
    else
        proc_usage_reinit = 0;
    return;
}
예제 #3
0
파일: crash.c 프로젝트: marker55/hp-ams
static int log_buffer_contents_rec(char *msg) {
    int i = 0;
    int rc = 0;
    int num_descript = 0;
    size_t toc_sz = 0;
    size_t blob_sz = 0;
    char* blob;
    RECORDER_API4_RECORD *toc;

    if (NULL != msg) {

        if (!rec_init()) {
            return -1;
        }

        if ((rc = doCodeDescriptor(s_ams_rec_handle,
                                   s_ams_rec_class,
                                   REC_CODE_AMS_OS_CRASH,
                                   0,
                                   REC_SEV_CRIT,
                                   REC_BINARY_DATA,
                                   REC_VIS_CUSTOMER,
                                   REC_CODE_AMS_OS_CRASH_STR)) != RECORDER_OK) {
            DEBUGMSGTL(("rec:rec_kdump","KDump register descriptor failed %d\n", rc));
            return -1;
        }

        /* TODO: Since I'm collapsing all of the kdump data into a
         * single field, do I have to do this? 
         */
        num_descript = sizeof(fld)/sizeof(field);
        DEBUGMSGTL(("rec:log","Kdump num_descript = %d\n", num_descript));
        if ((toc_sz = sizeof(RECORDER_API4_RECORD) * num_descript) 
            > RECORDER_MAX_BLOB_SIZE) {
            DEBUGMSGTL(("rec:log", "KDump descriptor too large %ld\n", toc_sz));
            return -1;
        }

        DEBUGMSGTL(("rec:log", "Kdump toc_sz = %ld\n", toc_sz));
        if ((toc = malloc(toc_sz)) == NULL) {
            DEBUGMSGTL(("rec:log","KDump unable to malloc %ld bytes\n", toc_sz));
            return -1;
        }
        memset(toc, 0, toc_sz);

        /* now setup field descriptor */
        for (i = 0; i < num_descript; i++) {
            toc[i].flags = REC_FLAGS_API4 | REC_FLAGS_DESC_FIELD;
            toc[i].classs = s_ams_rec_class;
            toc[i].code = REC_CODE_AMS_OS_CRASH;
            toc[i].field = i;
            toc[i].severity_type = REC_DESC_SEVERITY_CRITICAL | fld[i].tp;
            toc[i].format = fld[i].sz;
            toc[i].visibility = REC_DESC_VISIBILITY_CUSTOMER;
            strncpy(toc[i].desc, fld[i].nm, strlen(fld[i].nm));
            DEBUGMSGTL(("rec:log", "toc[i] = %p\n", &toc[i]));
            dump_chunk("rec:rec_log", "descriptor", (const u_char*)&toc[i], 96);
        }
        dump_chunk("rec:rec_log", "toc", (const u_char*)toc, toc_sz);
        
        if ((rc = rec_api4_field(s_ams_rec_handle, toc_sz, toc))
            != RECORDER_OK) {
            DEBUGMSGTL(("rec:log", "KDump register descriptor failed %d\n", rc));
            free(toc);
            return -1;
        }
        free(toc);

        blob_sz = RECORDER_MAX_BLOB_SIZE;
        if ((blob = malloc(blob_sz)) == NULL) {
            DEBUGMSGTL(("rec:log", "KDump unable to malloc() %ld blob\n", blob_sz));
            return -1;
        }

        memset(blob, 0, blob_sz);
        strncpy(blob, msg, blob_sz);
        blob_sz = strlen(blob);
        if ((rc = rec_api6(s_ams_rec_handle, (const char*)blob, blob_sz))
            != RECORDER_OK) {
            DEBUGMSGTL(("rec:log", "KDump log to recorder data failed (%d)\n", rc));
            free(blob);
            return -1;
        }
        DEBUGMSGTL(("rec:log", "Logged record for code %d\n", REC_CODE_AMS_OS_CRASH));
        free(blob);
        return 0;
    }

    /* msg was NULL */
    return -1;
}