159 lines
4.7 KiB
C++
159 lines
4.7 KiB
C++
//----------------------------------------------------------------------------
|
||
//
|
||
// Copyright (C) 2008 Intel Corporation
|
||
//
|
||
// File: EventLogReaderFlow.cpp
|
||
//
|
||
// Contents: Api code for Intel(R) Active Management Technology
|
||
// (Intel<65> AMT) EventLogReader Sample.
|
||
//
|
||
// Notes: This file contains the EventLogReaderFlow class implementation.
|
||
//
|
||
//----------------------------------------------------------------------------
|
||
|
||
#include "EventLogReaderFlow.h"
|
||
#include "CimClass.h"
|
||
#include "AMT_MessageLog.h"
|
||
#include "CommonDefinitions.h"
|
||
#include "CmdLineArguments.h"
|
||
#include <time.h>
|
||
#include <iostream>
|
||
|
||
using namespace Intel::Manageability::Cim::Typed;
|
||
|
||
#pragma region STRUCTS
|
||
|
||
typedef struct _EventLogRecord
|
||
{
|
||
unsigned int TimeStamp;
|
||
unsigned char DeviceAddress;
|
||
unsigned char EventSensorType;
|
||
unsigned char EventType;
|
||
unsigned char EventOffset;
|
||
unsigned char EventSourceType;
|
||
unsigned char EventSeverity;
|
||
unsigned char SensorNumber;
|
||
unsigned char Entity;
|
||
unsigned char EntityInstance;
|
||
unsigned char EventData[8];
|
||
}EventLogRecord;
|
||
|
||
#pragma endregion
|
||
|
||
#pragma region MEMBERS
|
||
|
||
CmdLineArguments::Format format;
|
||
|
||
#pragma endregion
|
||
|
||
#pragma region METHODS
|
||
|
||
/*
|
||
* Description: Print a Log Record in the required format
|
||
* Arguments:
|
||
* b64Record - A base64 format of the record
|
||
* record_index - The record index
|
||
*/
|
||
void PrintRecord(string b64Record, int record_index)
|
||
{
|
||
format.SetConsoleTextColor(HCYAN);
|
||
cout << "\tRecord Number: " <<dec<< record_index << endl;
|
||
format.SetConsoleTextColor(LGRAY);
|
||
|
||
Intel::Manageability::Cim::Utils::Base64 record(b64Record);
|
||
|
||
EventLogRecord *e = (EventLogRecord*)record.Data();
|
||
|
||
cout<<"DeviceAddress "<<(unsigned int)e->DeviceAddress<<endl;
|
||
cout<<"Entity "<<(unsigned int)e->Entity<<endl;
|
||
cout<<"EventSensorType "<<(unsigned int)e->EventSensorType<<endl;
|
||
cout<<"EventSourceType "<<(unsigned int)e->EventSourceType<<endl;
|
||
cout<<"EventSeverity "<<(unsigned int)e->EventSeverity<<endl;
|
||
cout<<"SensorNumber "<<(unsigned int)e->SensorNumber<<endl;
|
||
cout<<"EventType "<<(unsigned int)e->EventType<<endl;
|
||
cout<<"EventData ";
|
||
|
||
for(unsigned int j = 0; j < 8; j++)
|
||
{
|
||
cout<<" "<<hex<<(unsigned int)e->EventData[j];
|
||
}
|
||
cout<<endl;
|
||
|
||
#if (defined(_WIN32) && (_MSC_VER >= 1400))
|
||
/*Starting with Visual C++ compiler version 14 (which is VS2005), the
|
||
default for gmtime is the 64-bit version, which we don't want.*/
|
||
#pragma warning(disable:4996)
|
||
struct tm *time = _gmtime32((__time32_t*)(&((e)->TimeStamp)));
|
||
#pragma warning(default:4996)
|
||
|
||
#else
|
||
struct tm *time = gmtime((time_t*)(&((e)->TimeStamp)));
|
||
#endif
|
||
|
||
#pragma warning(disable:4996)
|
||
cout<<"TimeStamp (UTC) "<<(time ? asctime(time) : "Unknown")<<endl<<endl;
|
||
#pragma warning(default:4996)
|
||
}
|
||
|
||
/*
|
||
* Description: Reads the log Records from the Intel(r) AMT and calls the Print mathod
|
||
* Arguments:
|
||
* wsmanClient - ICimWsmanClient For Cimframework
|
||
*/
|
||
void ReadRecords(ICimWsmanClient * wsmanClient)
|
||
{
|
||
unsigned int status;
|
||
|
||
// Create reference to AMT_MessageLog, where keys "Name" = "Intel(r) AMT:MessageLog 1".
|
||
AMT_MessageLog messageLog(wsmanClient);
|
||
messageLog.Name("Intel(r) AMT:MessageLog 1");
|
||
// Get message log instance.
|
||
messageLog.Get();
|
||
|
||
cout << messageLog.Name() << endl;
|
||
cout << ((messageLog.IsFrozen()) ? "Log frozen" : "Log is not frozen") << endl;
|
||
cout << "Max number of records: " << messageLog.MaxNumberOfRecords() << endl;
|
||
cout << "Current number of records: " << messageLog.CurrentNumberOfRecords() << endl<<endl;
|
||
|
||
if(messageLog.CurrentNumberOfRecords() != 0)
|
||
{
|
||
// first position the pointer to the first record
|
||
AMT_MessageLog::PositionToFirstRecord_OUTPUT outputPositionToFirstRecord;
|
||
|
||
bool moreRecords;
|
||
int cnt = 0;
|
||
string identifier;
|
||
|
||
status = messageLog.PositionToFirstRecord(outputPositionToFirstRecord);
|
||
if(status != PT_STATUS_SUCCESS)
|
||
{
|
||
throw GeneralWsmanException("Failed to invoke PositionToFirstRecord, returnValue = ", status);
|
||
}
|
||
|
||
AMT_MessageLog::GetRecords_INPUT inputGetRecords;
|
||
AMT_MessageLog::GetRecords_OUTPUT outputGetRecords;
|
||
|
||
identifier = outputPositionToFirstRecord.IterationIdentifier();
|
||
inputGetRecords.IterationIdentifier(identifier);
|
||
do
|
||
{
|
||
int value = 1;
|
||
inputGetRecords.MaxReadRecords(value);
|
||
|
||
status = messageLog.GetRecords(inputGetRecords,outputGetRecords);
|
||
if(status != PT_STATUS_SUCCESS)
|
||
{
|
||
throw GeneralWsmanException("Failed to invoke GetRecords, returnValue = ", status);
|
||
}
|
||
|
||
for(unsigned int j=0; j< outputGetRecords.RecordArray().size(); j++)
|
||
{
|
||
PrintRecord(outputGetRecords.RecordArray().at(j), cnt++);
|
||
}
|
||
moreRecords = !outputGetRecords.NoMoreRecords() ;
|
||
inputGetRecords.IterationIdentifier(outputGetRecords.IterationIdentifier());
|
||
}while(moreRecords);
|
||
}
|
||
}
|
||
|
||
#pragma endregion |