1 yi.zhou 1.1 //%2006////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 yi.zhou 1.1 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #include <Pegasus/Common/Config.h>
35 #include <Pegasus/Common/Constants.h>
36 #include <Pegasus/Common/Logger.h>
37 #include <Pegasus/Common/Formatter.h>
38 #include <Pegasus/Common/CIMPropertyList.h>
39 #include <Pegasus/Common/InternalException.h>
40 #include <unistd.h>
41 #include <stdlib.h>
42
43 yi.zhou 1.1 #ifndef PEGASUS_DISABLE_AUDIT_LOGGER
44
45 #include <Pegasus/Common/AuditLogger.h>
46
47 PEGASUS_USING_STD;
48
49 PEGASUS_NAMESPACE_BEGIN
50
51 static const String providerModuleStatus [] = {"Unknown", "Other", "OK", "Degraded",
52 "Stressed", "Predictive Failure", "Error", "Non-Recoverable Error",
53 "Starting", "Stopping", "Stopped", "In Service", "No Contact",
54 "Lost Communication"};
55
56 Boolean AuditLogger::_auditLogFlag = false;
57
58 AuditLogger::PEGASUS_AUDITLOGINITIALIZE_CALLBACK_T AuditLogger::_auditLogInitializeCallback;
59
60 AuditLogger::PEGASUS_AUDITLOG_CALLBACK_T AuditLogger::_writeAuditMessageToFile =
61 AuditLogger::_writeAuditMessage;
62
63 void AuditLogger::logCurrentConfig(
64 yi.zhou 1.1 const Array<String> & propertyNames,
65 const Array<String> & propertyValues)
66 {
67 String properties;
68
69 for (Uint32 i = 0; i < propertyNames.size(); i++)
70 {
71 properties.append(propertyNames[i]);
72 properties.append("=");
73 properties.append(propertyValues[i]);
74 properties.append("\n");
75 }
76
77 MessageLoaderParms msgParms("Common.AuditLogger.CURRENT_CONFIG",
78 "The current configuration properties are:\n$0", properties);
79
80 _writeAuditMessageToFile(CONFIGURATION, CURRENT_CONFIGURATION,
81 START_UP, Logger::INFORMATION, msgParms);
82
83 }
84
85 yi.zhou 1.1 void AuditLogger::logCurrentRegProvider(
86 const Array < CIMInstance > & instances)
87 {
88 String moduleName, registeredModules;
89 Array<Uint16> moduleStatus;
90 String statusValue;
91 Uint32 pos;
92
93 // get all the registered provider module names and status
94 for (Uint32 i = 0; i <instances.size(); i++)
95 {
96 instances[i].getProperty(instances[i].findProperty(
97 _PROPERTY_PROVIDERMODULE_NAME)).getValue().get(moduleName);
98
99 registeredModules.append(moduleName);
100 registeredModules.append("=");
101
102 pos = instances[i].findProperty(_PROPERTY_OPERATIONALSTATUS);
103
104 if (pos == PEG_NOT_FOUND)
105 {
106 yi.zhou 1.1 moduleStatus.append(0);
107 }
108 else
109 {
110 CIMValue theValue = instances[i].getProperty(pos).getValue();
111
112 if (theValue.isNull())
113 {
114 moduleStatus.append(0);
115 }
116 else
117 {
118 theValue.get(moduleStatus);
119 }
120 }
121
122 statusValue = _getModuleStatusValue(moduleStatus);
123
124 registeredModules.append(statusValue);
125 registeredModules.append("\n");
126 }
127 yi.zhou 1.1
128 MessageLoaderParms msgParms(
129 "Common.AuditLogger.CURRENT_PROVIDER_REGISTRATION",
130 "The current registered provider modules are:\n$0", registeredModules);
131
132 _writeAuditMessageToFile(CONFIGURATION, CURRENT_PROVIDER_REGISTRATION,
133 START_UP, Logger::INFORMATION, msgParms);
134 }
135
136 void AuditLogger::logCurrentEnvironmentVar()
137 {
138
139 String envList;
140 char ** envp = environ;
141
142 Uint32 i = 0;
143
144 while (envp[i])
145 {
146 envList.append(envp[i]);
147 envList.append("\n");
148 yi.zhou 1.1
149 i++;
150 }
151
152 MessageLoaderParms msgParms("Common.AuditLogger.CURRENT_ENV",
153 "The current environment variables are:\n$0", envList);
154
155 _writeAuditMessageToFile(CONFIGURATION, CURRENT_ENVIRONMENT_VARIABLES,
156 START_UP, Logger::INFORMATION, msgParms);
157 }
158
159 void AuditLogger::logSetConfigProperty(
160 const String & userName,
161 const String & propertyName,
162 const String & prePropertyValue,
163 const String & newPropertyValue,
164 Boolean isPlanned)
165 {
166 if (isPlanned)
167 {
168 MessageLoaderParms msgParms(
169 yi.zhou 1.1 "Common.AuditLogger.SET_PLANNED_CONFIG_PROPERTY",
170 "The planned value of property \"$0\" is modified from value \"$1\"" " to value \"$2\" by user \"$3\".\n",
171 propertyName, prePropertyValue, newPropertyValue, userName);
172
173 _writeAuditMessageToFile(CONFIGURATION, CONFIGURATION_CHANGE,
174 UPDATE, Logger::INFORMATION, msgParms);
175 }
176 else
177 {
178 MessageLoaderParms msgParms(
179 "Common.AuditLogger.SET_CURRENT_CONFIG_PROPERTY",
180 "The current value of property \"$0\" is modified from value "
181 "\"$1\" to value \"$2\" by user \"$3\".\n",
182 propertyName, prePropertyValue, newPropertyValue, userName);
183
184 _writeAuditMessageToFile(CONFIGURATION, CONFIGURATION_CHANGE,
185 UPDATE, Logger::INFORMATION, msgParms);
186 }
187 }
188
189 void AuditLogger::setInitializeCallback(
190 yi.zhou 1.1 PEGASUS_AUDITLOGINITIALIZE_CALLBACK_T auditLogInitializeCallback)
191 {
192 _auditLogInitializeCallback = auditLogInitializeCallback;
193 }
194
195 void AuditLogger::setEnabled(Boolean enabled)
196 {
197 if (enabled)
198 {
199 if (!_auditLogFlag)
200 {
201 _auditLogInitializeCallback();
202 }
203 }
204 else
205 {
206 if (_auditLogFlag)
207 {
208 MessageLoaderParms msgParms(
209 "Common.AuditLogger.DISABLE_AUDIT_LOG",
210 "Audit logging is disabled.\n");
211 yi.zhou 1.1
212 _writeAuditMessageToFile(CONFIGURATION, CONFIGURATION_CHANGE,
213 UPDATE, Logger::INFORMATION, msgParms);
214 }
215 }
216
217 _auditLogFlag = enabled;
218 }
219
220 void AuditLogger::writeAuditLogToFileCallback(
221 PEGASUS_AUDITLOG_CALLBACK_T writeAuditLogToFileCallback)
222 {
223 _writeAuditMessageToFile = writeAuditLogToFileCallback;
224 }
225
226 void AuditLogger::_writeAuditMessage(
227 AuditType auditType,
228 AuditSubType auditSubType,
229 AuditEvent auditEvent,
230 Uint32 logLevel,
231 MessageLoaderParms & msgParms)
232 yi.zhou 1.1 {
233 String localizedMsg = MessageLoader::getMessage(msgParms);
234
235 String identifier = "CIM Server Audit";
236
237 Logger::put(Logger::AUDIT_LOG, identifier, logLevel, localizedMsg);
238 }
239
240 String AuditLogger::_getModuleStatusValue(
241 const Array<Uint16> moduleStatus)
242 {
243 String moduleStatusValue, statusValue;
244 Uint32 moduleStatusSize = moduleStatus.size();
245
246 for (Uint32 j=0; j < moduleStatusSize; j++)
247 {
248 statusValue = providerModuleStatus[moduleStatus[j]];
249 moduleStatusValue.append(statusValue);
250
251 if (j < moduleStatusSize - 1)
252 {
253 yi.zhou 1.1 moduleStatusValue.append(",");
254 }
255 }
256
257 return (moduleStatusValue);
258 }
259
260 PEGASUS_NAMESPACE_END
261
262 #endif
|