1 karl 1.5 //%2006////////////////////////////////////////////////////////////////////////
|
2 yi.zhou 1.1 //
|
3 karl 1.5 // 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 yi.zhou 1.1 // 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 karl 1.5 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 yi.zhou 1.1 //
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 // 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 yi.zhou 1.1 #include <Pegasus/Common/Config.h>
35 #include <Pegasus/Common/PegasusVersion.h>
36
37 #include <iostream>
38 #include <Pegasus/Handler/CIMHandler.h>
39 #include <Pegasus/Repository/CIMRepository.h>
40 #include <Pegasus/Common/Tracer.h>
41 #include <Pegasus/Common/MessageLoader.h>
42 #include <Pegasus/Common/System.h>
43 #include <Pegasus/Common/CIMType.h>
44 #include <Pegasus/Common/IndicationFormatter.h>
45
46 #include "SystemLogListenerDestination.h"
47
48 PEGASUS_NAMESPACE_BEGIN
49
50 PEGASUS_USING_STD;
51
52 void SystemLogListenerDestination::initialize(CIMRepository* repository)
53 {
54 }
55 yi.zhou 1.1
56 void SystemLogListenerDestination::handleIndication(
57 const OperationContext& context,
58 const String nameSpace,
|
59 kumpf 1.7 CIMInstance& indication,
60 CIMInstance& handler,
61 CIMInstance& subscription,
62 ContentLanguageList& contentLanguages)
|
63 yi.zhou 1.1 {
|
64 kumpf 1.7 PEG_METHOD_ENTER(TRC_IND_HANDLER,
|
65 yi.zhou 1.1 "SystemLogListenerDestination::handleIndication");
66
67 String ident_name = "CIM Indication";
68 String indicationText;
69
70 try
71 {
|
72 r.kieninger 1.11 PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
|
73 w.otsuka 1.10 "SystemLogListenerDestination %s:%s.%s processing %s Indication",
74 (const char*)(nameSpace.getCString()),
75 (const char*)(handler.getClassName().getString().getCString()),
76 (const char*)(handler.getProperty(
77 handler.findProperty(PEGASUS_PROPERTYNAME_NAME)).
78 getValue().toString().getCString()),
79 (const char*)(indication.getClassName().getString().
80 getCString())));
|
81 kumpf 1.7 // gets formatted indication message
82 indicationText = IndicationFormatter::getFormattedIndText(
83 subscription, indication, contentLanguages);
|
84 yi.zhou 1.1
85 // default severity
86 Uint32 severity = Logger::INFORMATION;
87
88 // If an indication contains severity information, gets the value
|
89 kumpf 1.7 // and maps it to Pegasus logger severity. Otherwise, default value
|
90 yi.zhou 1.1 // is used.
91
|
92 kumpf 1.7 Uint32 severityPos =
93 indication.findProperty(CIMName("PerceivedSeverity"));
|
94 yi.zhou 1.1
95 if (severityPos != PEG_NOT_FOUND)
96 {
97 Uint16 perceivedSeverity;
|
98 kumpf 1.7 CIMValue perceivedSeverityValue =
|
99 yi.zhou 1.1 indication.getProperty(severityPos).getValue();
100
101 if (!perceivedSeverityValue.isNull())
102 {
103 perceivedSeverityValue.get(perceivedSeverity);
104
105 switch (perceivedSeverity)
106 {
107 case (_SEVERITY_FATAL):
108 case (_SEVERITY_CRITICAL):
109 {
110 severity = Logger::FATAL;
111 break;
112 }
113
114 case (_SEVERITY_MAJOR):
115 {
116 severity = Logger::SEVERE;
117 break;
118 }
119
120 yi.zhou 1.1 case (_SEVERITY_MINOR):
121 case (_SEVERITY_WARNING):
122 {
123 severity = Logger::WARNING;
124 break;
125 }
126
127 case (_SEVERITY_INFORMATION):
128 case (_SEVERITY_OTHER):
129 case (_SEVERITY_UNKNOWN):
130 {
131 severity = Logger::INFORMATION;
132 break;
133 }
134
135 default:
136 {
|
137 marek 1.12 PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL2,
|
138 kumpf 1.7 "PerceivedSeverity = %d is not a valid value."
|
139 marek 1.8 " Using default severity.", perceivedSeverity));
|
140 yi.zhou 1.1 break;
141 }
142 }
143 }
144 }
145
|
146 marek 1.12 PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
|
147 w.otsuka 1.10 "SystemLogListenerDestination writing %s Indication to system log",
148 (const char*)(indication.getClassName().getString().getCString())));
149 // writes the formatted indication to a system log file
|
150 kumpf 1.7 _writeToSystemLog(ident_name, severity, indicationText);
|
151 marek 1.12 PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
|
152 w.otsuka 1.10 "%s Indication written to system log successfully",
153 (const char*)(indication.getClassName().getString().getCString())));
|
154 yi.zhou 1.1 }
|
155 kumpf 1.7 catch (CIMException& c)
|
156 yi.zhou 1.1 {
|
157 thilo.boehm 1.14 PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1, "CIMException: %s",
158 (const char*)c.getMessage().getCString()));
|
159 yi.zhou 1.1 PEG_METHOD_EXIT();
160
|
161 kumpf 1.7 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, c.getMessage());
|
162 yi.zhou 1.1 }
|
163 kumpf 1.7 catch (Exception&e)
|
164 yi.zhou 1.1 {
|
165 thilo.boehm 1.14 PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1, "Exception: %s",
166 (const char*)e.getMessage().getCString()));
|
167 yi.zhou 1.1 PEG_METHOD_EXIT();
168
|
169 kumpf 1.7 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
|
170 yi.zhou 1.1 }
171 catch (...)
172 {
|
173 marek 1.12 PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
|
174 yi.zhou 1.1 "Failed to deliver indication to system log file.");
175 PEG_METHOD_EXIT();
|
176 kumpf 1.7
177 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
178 "Handler.SystemLogListenerDestination.SystemLogListenerDestination."
179 "FAILED_TO_DELIVER_INDICATION_TO_SYSTEM_LOG",
|
180 yi.zhou 1.1 "Failed to deliver indication to system log file."));
181 }
182
183 PEG_METHOD_EXIT();
184 }
185
186 void SystemLogListenerDestination::_writeToSystemLog(
|
187 kumpf 1.7 const String& identifier,
|
188 yi.zhou 1.1 Uint32 severity,
|
189 kumpf 1.7 const String& formattedText)
|
190 yi.zhou 1.1 {
|
191 kumpf 1.7 PEG_METHOD_ENTER(TRC_IND_HANDLER,
192 "SystemLogListenerDestination::_writeToSystemLog");
|
193 yi.zhou 1.1
194 #if defined(PEGASUS_USE_SYSLOGS)
195
|
196 kumpf 1.3 System::syslog(identifier, severity, formattedText.getCString());
|
197 yi.zhou 1.1
198 #else
199
|
200 carson.hovey 1.13 PEG_TRACE_CSTRING(TRC_INDICATION_GENERATION, Tracer::LEVEL3,
201 "SystemLogListenerDestination writing to PegasusStandard.log");
|
202 kumpf 1.7 // PEGASUS_USE_SYSLOGS is not defined, writes the formatted
|
203 yi.zhou 1.1 // indications into PegasusStandard.log file
|
204 kumpf 1.7 Logger::put(Logger::STANDARD_LOG , identifier, severity,
205 (const char*)formattedText.getCString());
|
206 yi.zhou 1.1
207 #endif
208
209 PEG_METHOD_EXIT();
210
211 }
212
|
213 kumpf 1.6 PEGASUS_NAMESPACE_END
214
215 PEGASUS_USING_PEGASUS;
216
217 // This is the entry point into this dynamic module.
218
219 extern "C" PEGASUS_EXPORT CIMHandler* PegasusCreateHandler(
220 const String& handlerName)
221 {
222 if (handlerName == "SystemLogListenerDestination")
223 {
224 return new SystemLogListenerDestination;
225 }
226
227 return 0;
|
228 yi.zhou 1.1 }
|