1
/*###############################################################################
2
# Linux Management Providers (LMP), OpenDRIM_RecordLogPackage provider package
3
# Copyright (C) 2007 Ilsoo Byun, ETRI <widepis@etri.re.kr, widepis@empal.com>
5
# This program is being developed under the "OpenDRIM" project.
6
# The "OpenDRIM" project web page: http://opendrim.sourceforge.net
7
# The "OpenDRIM" project mailing list: opendrim@googlegroups.com
9
# This program is free software; you can redistribute it and/or
10
# modify it under the terms of the GNU General Public License
11
# as published by the Free Software Foundation; version 2
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with this program; if not, write to the Free Software
21
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
#################################################################################
24
#################################################################################
25
# To contributors, please leave your contact information in this section
26
# AND comment your changes in the source code.
28
# Modified by 2008 Guillaume BOTTEX, ETRI <guillaumebottex@etri.re.kr, guillaumebottex@gmail.com>
29
###############################################################################*/
31
#include "OpenDRIM_LogEntryAccess.h"
32
#include "../OpenDRIM_RecordLog/OpenDRIM_RecordLogAccess.h"
33
#include "CMPIBroking.h"
35
#define LOG_TIME_LIMIT 15
37
int OpenDRIM_RecordLogPackage_OpenDRIM_LogEntry_load(const CMPIBroker* broker, string& errorMessage) {
43
int OpenDRIM_RecordLogPackage_OpenDRIM_LogEntry_unload(string& errorMessage) {
49
int OpenDRIM_RecordLogPackage_OpenDRIM_LogEntry_makeInstances(const string& filename, vector<OpenDRIM_LogEntry>& result, const string& discriminant, string& errorMessage) {
51
ifstream ifs(filename.c_str());
54
errorMessage = "Failed to open the file: "+filename;
60
struct tm *tp = localtime(&timep);
62
OpenDRIM_LogEntry instance;
64
while (getline(ifs, line)) {
67
CF_assert(OpenDRIM_RecordLogPackage_OpenDRIM_LogEntry_populate(instance, filename, line, tp, discriminant, errorMessage));
68
result.push_back(instance);
76
int OpenDRIM_RecordLogPackage_OpenDRIM_LogEntry_retrieve(const CMPIBroker* broker, const CMPIContext* ctx, vector<OpenDRIM_LogEntry>& result, const char** properties, string& errorMessage, const string& discriminant) {
78
vector<OpenDRIM_RecordLog> recordLogs;
79
CF_assert(OpenDRIM_RecordLogPackage_OpenDRIM_RecordLog_retrieve(broker, ctx, recordLogs, NULL, errorMessage, "ein"));
81
for (size_t i=0; i<recordLogs.size(); i++) {
83
recordLogs[i].getInstanceID(logInstanceID);
84
CF_assert(OpenDRIM_RecordLogPackage_OpenDRIM_LogEntry_makeInstances(logInstanceID, result, discriminant, errorMessage));
90
int OpenDRIM_RecordLogPackage_OpenDRIM_LogEntry_getInstance(const CMPIBroker* broker, const CMPIContext* ctx, OpenDRIM_LogEntry& instance, const char** properties, string& errorMessage) {
92
if (!instance.InstanceID_isNULL) {
93
string filename = instance.InstanceID.substr(0, instance.InstanceID.find(':'));
94
string subject_timestamp = instance.InstanceID.substr(instance.InstanceID.find(':')+1);
95
vector<OpenDRIM_LogEntry> result;
97
ifstream ifs(filename.c_str());
100
errorMessage = "Failed to open the file: "+filename;
106
struct tm *tp = localtime(&timep);
109
while (getline(ifs, line)) {
110
if (line.size() < 15)
112
string timestamp = CF_logTimeFormat(line.substr(0, LOG_TIME_LIMIT), tp);
113
if (subject_timestamp == timestamp) {
115
CF_assert(OpenDRIM_RecordLogPackage_OpenDRIM_LogEntry_populate(instance, filename, line, tp, "ei", errorMessage));
121
errorMessage = "No instance";
124
errorMessage = "No key property";
131
int OpenDRIM_RecordLogPackage_OpenDRIM_LogEntry_setInstance(const CMPIBroker* broker, const CMPIContext* ctx, const OpenDRIM_LogEntry& newInstance, const OpenDRIM_LogEntry& oldInstance, const char** properties, string& errorMessage) {
134
return NOT_SUPPORTED;
137
int OpenDRIM_RecordLogPackage_OpenDRIM_LogEntry_createInstance(const CMPIBroker* broker, const CMPIContext* ctx, const OpenDRIM_LogEntry& instance, string& errorMessage) {
140
return NOT_SUPPORTED;
143
int OpenDRIM_RecordLogPackage_OpenDRIM_LogEntry_deleteInstance(const CMPIBroker* broker, const CMPIContext* ctx, const OpenDRIM_LogEntry& instance, string& errorMessage) {
146
return NOT_SUPPORTED;
149
int OpenDRIM_RecordLogPackage_OpenDRIM_LogEntry_populate(OpenDRIM_LogEntry& instance, const string& filename, string& line, struct tm* tp, const string& discriminant, string& errorMessage) {
153
* Properties to fill from profile
155
* [X] InstanceID [KEY]
157
* [X] CreationTimestamp
166
string timestamp = CF_logTimeFormat(line.substr(0, LOG_TIME_LIMIT), tp);
167
string id = filename+":"+timestamp;
168
instance.setInstanceID(id);
169
instance.setCreationTimeStamp(timestamp);
170
instance.setRecordData(line);
171
instance.setLogInstanceID(filename);
172
instance.setRecordID(timestamp);
173
instance.setRecordFormat(": string Month uint8 Day uint8 Hour:uint8 Minute:uint8 Second string HostName string Origin: string Message");
174
instance.setLogName(filename);
175
instance.setElementName(id);
180
// added by Frederic Desmons (2007/11/15)
181
int OpenDRIM_RecordLogPackage_OpenDRIM_LogEntry_retrieveInDatetimeBoundaries(const string& log_file, const string& datetime_lower_limit, const string& datetime_upper_limit, vector<OpenDRIM_LogEntry>& log_entries, string& errorMessage) {
183
ifstream ifs(log_file.c_str());
186
errorMessage = "Failed to open the file: "+log_file;
192
struct tm *tp = localtime(&timep);
195
while (getline(ifs, line)) {
196
if (line.size() < 15)
198
string timestamp = CF_logTimeFormat(line.substr(0, LOG_TIME_LIMIT), tp);
199
int upper_sign, lower_sign;
200
CF_assert(CF_datetimeCmp(upper_sign, timestamp, datetime_upper_limit, errorMessage));
201
CF_assert(CF_datetimeCmp(lower_sign, timestamp, datetime_lower_limit, errorMessage));
202
if (upper_sign <= 0 && lower_sign >=0) {
203
OpenDRIM_LogEntry instance;
204
CF_assert(OpenDRIM_RecordLogPackage_OpenDRIM_LogEntry_populate(instance, log_file, line, tp, "ei", errorMessage));
205
log_entries.push_back(instance);