Example #1
0
void list_sel(SaHpiSessionIdT session_id, SaHpiResourceIdT resource_id)
{
        char str[256];

        printf("SEL Info:\n");

        SaHpiSelInfoT info;        
        SaErrorT rv = saHpiEventLogInfoGet(session_id, resource_id, &info);

        if (rv != SA_OK) {
                printf( "Error=%d reading SEL info\n", rv);
                return;
        }

        printf("\tEntries in SEL: %d\n", info.Entries);
        printf("\tSize: %d\n", info.Size);

        time2str(info.UpdateTimestamp, str);
        printf("\tUpdateTimestamp: %s\n", str);

        time2str(info.CurrentTime, str);
        printf("\tCurrentTime    : %s\n", str);
        printf("\tEnabled: %s\n", info.Enabled ? "true" : "false");
        printf("\tOverflowFlag: %s\n", info.OverflowFlag ? "true" : "false");
        printf("\tOverflowAction: " );

        switch(info.OverflowAction) {
        case SAHPI_SEL_OVERFLOW_DROP:
                printf("SAHPI_SEL_OVERFLOW_DROP\n");
                break;

        case SAHPI_SEL_OVERFLOW_WRAP:
                printf("SAHPI_SEL_OVERFLOW_WRAP\n");
                break;

        case SAHPI_SEL_OVERFLOW_WRITELAST:
                printf("SAHPI_SEL_OVERFLOW_WRITELAST\n");
                break;

        default:
                printf("unknown(0x%x)\n", info.OverflowAction);
                break;
        }

        printf("\tDeleteEntrySupported: %s\n", info.DeleteEntrySupported ? "true" : "false" );

		if (info.Entries == 0)
				return;
		//else 
        // read sel records
        SaHpiSelEntryIdT current = SAHPI_OLDEST_ENTRY;

        do {
                SaHpiSelEntryIdT prev;
                SaHpiSelEntryIdT next;
                SaHpiSelEntryT   entry;
                SaHpiRdrT        rdr;
                SaHpiRptEntryT   res;

                rv = saHpiEventLogEntryGet(session_id, resource_id, current, &prev, &next, &entry, &rdr, &res);

                if (rv != SA_OK) {
                        printf( "Error=%d reading SEL entry %d\n", rv, current);
                        return;
                }

                printf("\t\tEntry %d, prev %d, next %d\n", entry.EntryId, prev, next);
                time2str(entry.Timestamp, str);
                printf("\t\t\tTimestamp:            %s\n", str);

                SaHpiRptEntryT rres;

                rv = saHpiRptEntryGetByResourceId(session_id, entry.Event.Source, &rres );

                if ( rv != SA_OK )
                printf("\t\t\tSource:               unknown\n" );
                else {
                        entitypath2string( &rres.ResourceEntity, str, sizeof(str));
                printf("\t\t\tSource:               %s\n", str );
                }

                printf("\t\t\tEventType:            %s\n", eventtype2str(entry.Event.EventType));
                time2str(entry.Timestamp, str);
                printf("\t\t\tEvent timestamp:      %s\n", str);
                printf("\t\t\tSeverity:             %s\n", severity2str( entry.Event.Severity ) );

                switch(entry.Event.EventType) {
                case SAHPI_ET_SENSOR:
                        {
                                SaHpiSensorEventT *se = &entry.Event.EventDataUnion.SensorEvent;
                printf("\t\t\tSensorNum:            %d\n", se->SensorNum );
                printf("\t\t\tSensorType:           %s\n", get_sensor_type(se->SensorType ) );
                printf("\t\t\tEventCategory:        %s\n", get_sensor_category( se->EventCategory ) );
                printf("\t\t\tAssertion:            %s\n", se->Assertion ? "TRUE" : "FALSE" );
                        }

                        break;

                case SAHPI_ET_HOTSWAP:
                        {
                                SaHpiHotSwapEventT *he = &entry.Event.EventDataUnion.HotSwapEvent;
                printf("\t\t\tHotSwapState:         %s\n",
                                      hotswapstate2str( he->HotSwapState ) );
                printf("\t\t\tPreviousHotSwapState: %s\n",
                                        hotswapstate2str( he->PreviousHotSwapState ) );
                        }

                        break;

                case SAHPI_ET_WATCHDOG:
                        break;

                case SAHPI_ET_OEM:
                        break;

                case SAHPI_ET_USER:
                        break;
                }
                
                current = next;
        } while(current != SAHPI_NO_MORE_ENTRIES);
}
Example #2
0
/* handle generic exports */
int handle_export(int callback_type, void *data) {
    int i, debug_level_orig, return_code;
    char * buffer;
    char * type;
    char * event_type;
    nebstruct_log_data          * nld;
    nebstruct_process_data      * npd;
    nebstruct_timed_event_data  * nted;

    temp_buffer[0]          = '\x0';
    mod_gm_opt->debug_level = -1;
    debug_level_orig    = mod_gm_opt->debug_level;
    return_code         = 0;

    /* what type of event/data do we have? */
    switch (callback_type) {
        case NEBCALLBACK_PROCESS_DATA:                      /*  7 */
            npd    = (nebstruct_process_data *)data;
            type   = nebtype2str(npd->type);
            snprintf( temp_buffer,GM_BUFFERSIZE-1, "{\"callback_type\":\"%s\",\"type\":\"%s\",\"flags\":%d,\"attr\":%d,\"timestamp\":%d.%d}",
                    "NEBCALLBACK_PROCESS_DATA",
                    type,
                    npd->flags,
                    npd->attr,
                    (int)npd->timestamp.tv_sec, (int)npd->timestamp.tv_usec
                    );
            free(type);
            break;
        case NEBCALLBACK_TIMED_EVENT_DATA:                  /*  8 */
            nted       = (nebstruct_timed_event_data *)data;
            event_type = eventtype2str(nted->event_type);
            type       = nebtype2str(nted->type);
            snprintf( temp_buffer,GM_BUFFERSIZE-1, "{\"callback_type\":\"%s\",\"event_type\":\"%s\",\"type\":\"%s\",\"flags\":%d,\"attr\":%d,\"timestamp\":%d.%d,\"recurring\":%d,\"run_time\":%d}",
                    "NEBCALLBACK_TIMED_EVENT_DATA",
                    event_type,
                    type,
                    nted->flags,
                    nted->attr,
                    (int)nted->timestamp.tv_sec, (int)nted->timestamp.tv_usec,
                    nted->recurring,
                    (int)nted->run_time
                    );
            free(event_type);
            free(type);
            break;
        case NEBCALLBACK_LOG_DATA:                          /*  9 */
            nld    = (nebstruct_log_data *)data;
            buffer = escapestring(nld->data);
            type   = nebtype2str(nld->type);
            snprintf( temp_buffer,GM_BUFFERSIZE-1, "{\"callback_type\":\"%s\",\"type\":\"%s\",\"flags\":%d,\"attr\":%d,\"timestamp\":%d.%d,\"entry_time\":%d,\"data_type\":%d,\"data\":\"%s\"}",
                    "NEBCALLBACK_LOG_DATA",
                    type,
                    nld->flags,
                    nld->attr,
                    (int)nld->timestamp.tv_sec, (int)nld->timestamp.tv_usec,
                    (int)nld->entry_time,
                    nld->data_type,
                    buffer);
            free(type);
            free(buffer);
            break;
        case NEBCALLBACK_SYSTEM_COMMAND_DATA:               /* 10 */
            break;
        case NEBCALLBACK_EVENT_HANDLER_DATA:                /* 11 */
            break;
        case NEBCALLBACK_NOTIFICATION_DATA:                 /* 12 */
            break;
        case NEBCALLBACK_SERVICE_CHECK_DATA:                /* 13 */
            break;
        case NEBCALLBACK_HOST_CHECK_DATA:                   /* 14 */
            break;
        case NEBCALLBACK_COMMENT_DATA:                      /* 15 */
            break;
        case NEBCALLBACK_DOWNTIME_DATA:                     /* 16 */
            break;
        case NEBCALLBACK_FLAPPING_DATA:                     /* 17 */
            break;
        case NEBCALLBACK_PROGRAM_STATUS_DATA:               /* 18 */
            break;
        case NEBCALLBACK_HOST_STATUS_DATA:                  /* 19 */
            break;
        case NEBCALLBACK_SERVICE_STATUS_DATA:               /* 20 */
            break;
        case NEBCALLBACK_ADAPTIVE_PROGRAM_DATA:             /* 21 */
            break;
        case NEBCALLBACK_ADAPTIVE_HOST_DATA:                /* 22 */
            break;
        case NEBCALLBACK_ADAPTIVE_SERVICE_DATA:             /* 23 */
            break;
        case NEBCALLBACK_EXTERNAL_COMMAND_DATA:             /* 24 */
            break;
        case NEBCALLBACK_AGGREGATED_STATUS_DATA:            /* 25 */
            break;
        case NEBCALLBACK_RETENTION_DATA:                    /* 26 */
            break;
        case NEBCALLBACK_CONTACT_NOTIFICATION_DATA:         /* 27 */
            break;
        case NEBCALLBACK_CONTACT_NOTIFICATION_METHOD_DATA:  /* 28 */
            break;
        case NEBCALLBACK_ACKNOWLEDGEMENT_DATA:              /* 29 */
            break;
        case NEBCALLBACK_STATE_CHANGE_DATA:                 /* 30 */
            break;
        case NEBCALLBACK_CONTACT_STATUS_DATA:               /* 31 */
            break;
        case NEBCALLBACK_ADAPTIVE_CONTACT_DATA:             /* 32 */
            break;
        default:
            gm_log( GM_LOG_ERROR, "handle_export() unknown export type: %d\n", callback_type );
            mod_gm_opt->debug_level = debug_level_orig;
            return 0;
    }

    if(temp_buffer[0] != '\x0') {

        for(i=0;i<mod_gm_opt->exports[callback_type]->elem_number;i++) {
            return_code = mod_gm_opt->exports[callback_type]->return_code[i];
            add_job_to_queue( &client,
                              mod_gm_opt->server_list,
                              mod_gm_opt->exports[callback_type]->name[i], /* queue name */
                              NULL,
                              temp_buffer,
                              GM_JOB_PRIO_NORMAL,
                              GM_DEFAULT_JOB_RETRIES,
                              mod_gm_opt->transportmode,
                              send_now
                            );
        }
    }

    mod_gm_opt->debug_level = debug_level_orig;
    return return_code;
}