1 martin 1.15 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.16 //
|
3 martin 1.15 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.16 //
|
10 martin 1.15 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.16 //
|
17 martin 1.15 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.16 //
|
20 martin 1.15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.16 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.15 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.16 //
|
28 martin 1.15 //////////////////////////////////////////////////////////////////////////
|
29 yi.zhou 1.1 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include <Pegasus/Common/Config.h>
33 #include <Pegasus/Common/PegasusVersion.h>
34
35 #include <iostream>
36 #include <Pegasus/Handler/CIMHandler.h>
37 #include <Pegasus/Repository/CIMRepository.h>
38 #include <Pegasus/Common/Tracer.h>
39 #include <Pegasus/Common/MessageLoader.h>
40 #include <Pegasus/Common/System.h>
41 #include <Pegasus/Common/CIMType.h>
|
42 thilo.boehm 1.17 #include <Pegasus/General/IndicationFormatter.h>
|
43 yi.zhou 1.1
44 #include "SystemLogListenerDestination.h"
45
46 PEGASUS_NAMESPACE_BEGIN
47
48 PEGASUS_USING_STD;
49
50 void SystemLogListenerDestination::initialize(CIMRepository* repository)
51 {
52 }
53
54 void SystemLogListenerDestination::handleIndication(
55 const OperationContext& context,
56 const String nameSpace,
|
57 kumpf 1.7 CIMInstance& indication,
58 CIMInstance& handler,
59 CIMInstance& subscription,
60 ContentLanguageList& contentLanguages)
|
61 yi.zhou 1.1 {
|
62 kumpf 1.7 PEG_METHOD_ENTER(TRC_IND_HANDLER,
|
63 yi.zhou 1.1 "SystemLogListenerDestination::handleIndication");
64
65 String ident_name = "CIM Indication";
66 String indicationText;
67
68 try
69 {
|
70 r.kieninger 1.11 PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
|
71 w.otsuka 1.10 "SystemLogListenerDestination %s:%s.%s processing %s Indication",
72 (const char*)(nameSpace.getCString()),
73 (const char*)(handler.getClassName().getString().getCString()),
74 (const char*)(handler.getProperty(
75 handler.findProperty(PEGASUS_PROPERTYNAME_NAME)).
76 getValue().toString().getCString()),
77 (const char*)(indication.getClassName().getString().
78 getCString())));
|
79 kumpf 1.7 // gets formatted indication message
80 indicationText = IndicationFormatter::getFormattedIndText(
81 subscription, indication, contentLanguages);
|
82 yi.zhou 1.1
83 // default severity
84 Uint32 severity = Logger::INFORMATION;
85
86 // If an indication contains severity information, gets the value
|
87 kumpf 1.7 // and maps it to Pegasus logger severity. Otherwise, default value
|
88 yi.zhou 1.1 // is used.
89
|
90 kumpf 1.7 Uint32 severityPos =
91 indication.findProperty(CIMName("PerceivedSeverity"));
|
92 yi.zhou 1.1
93 if (severityPos != PEG_NOT_FOUND)
94 {
95 Uint16 perceivedSeverity;
|
96 kumpf 1.7 CIMValue perceivedSeverityValue =
|
97 yi.zhou 1.1 indication.getProperty(severityPos).getValue();
98
99 if (!perceivedSeverityValue.isNull())
100 {
101 perceivedSeverityValue.get(perceivedSeverity);
102
103 switch (perceivedSeverity)
104 {
105 case (_SEVERITY_FATAL):
106 case (_SEVERITY_CRITICAL):
107 {
108 severity = Logger::FATAL;
109 break;
110 }
111
112 case (_SEVERITY_MAJOR):
113 {
114 severity = Logger::SEVERE;
115 break;
116 }
117
118 yi.zhou 1.1 case (_SEVERITY_MINOR):
119 case (_SEVERITY_WARNING):
120 {
121 severity = Logger::WARNING;
122 break;
123 }
124
125 case (_SEVERITY_INFORMATION):
126 case (_SEVERITY_OTHER):
127 case (_SEVERITY_UNKNOWN):
128 {
129 severity = Logger::INFORMATION;
130 break;
131 }
132
133 default:
134 {
|
135 marek 1.12 PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL2,
|
136 kumpf 1.7 "PerceivedSeverity = %d is not a valid value."
|
137 marek 1.8 " Using default severity.", perceivedSeverity));
|
138 yi.zhou 1.1 break;
139 }
140 }
141 }
142 }
143
|
144 marek 1.12 PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
|
145 w.otsuka 1.10 "SystemLogListenerDestination writing %s Indication to system log",
146 (const char*)(indication.getClassName().getString().getCString())));
147 // writes the formatted indication to a system log file
|
148 kumpf 1.7 _writeToSystemLog(ident_name, severity, indicationText);
|
149 marek 1.12 PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
|
150 w.otsuka 1.10 "%s Indication written to system log successfully",
151 (const char*)(indication.getClassName().getString().getCString())));
|
152 yi.zhou 1.1 }
|
153 kumpf 1.7 catch (CIMException& c)
|
154 yi.zhou 1.1 {
|
155 thilo.boehm 1.14 PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1, "CIMException: %s",
156 (const char*)c.getMessage().getCString()));
|
157 yi.zhou 1.1 PEG_METHOD_EXIT();
158
|
159 kumpf 1.7 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, c.getMessage());
|
160 yi.zhou 1.1 }
|
161 kumpf 1.7 catch (Exception&e)
|
162 yi.zhou 1.1 {
|
163 thilo.boehm 1.14 PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1, "Exception: %s",
164 (const char*)e.getMessage().getCString()));
|
165 yi.zhou 1.1 PEG_METHOD_EXIT();
166
|
167 kumpf 1.7 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
|
168 yi.zhou 1.1 }
169 catch (...)
170 {
|
171 marek 1.12 PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
|
172 yi.zhou 1.1 "Failed to deliver indication to system log file.");
173 PEG_METHOD_EXIT();
|
174 kumpf 1.7
175 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
176 "Handler.SystemLogListenerDestination.SystemLogListenerDestination."
177 "FAILED_TO_DELIVER_INDICATION_TO_SYSTEM_LOG",
|
178 yi.zhou 1.1 "Failed to deliver indication to system log file."));
179 }
180
181 PEG_METHOD_EXIT();
182 }
183
184 void SystemLogListenerDestination::_writeToSystemLog(
|
185 kumpf 1.7 const String& identifier,
|
186 yi.zhou 1.1 Uint32 severity,
|
187 kumpf 1.7 const String& formattedText)
|
188 yi.zhou 1.1 {
|
189 kumpf 1.7 PEG_METHOD_ENTER(TRC_IND_HANDLER,
190 "SystemLogListenerDestination::_writeToSystemLog");
|
191 yi.zhou 1.1
192 #if defined(PEGASUS_USE_SYSLOGS)
193
|
194 kumpf 1.3 System::syslog(identifier, severity, formattedText.getCString());
|
195 yi.zhou 1.1
196 #else
197
|
198 carson.hovey 1.13 PEG_TRACE_CSTRING(TRC_INDICATION_GENERATION, Tracer::LEVEL3,
199 "SystemLogListenerDestination writing to PegasusStandard.log");
|
200 kumpf 1.7 // PEGASUS_USE_SYSLOGS is not defined, writes the formatted
|
201 yi.zhou 1.1 // indications into PegasusStandard.log file
|
202 kumpf 1.7 Logger::put(Logger::STANDARD_LOG , identifier, severity,
203 (const char*)formattedText.getCString());
|
204 yi.zhou 1.1
205 #endif
206
207 PEG_METHOD_EXIT();
208
209 }
210
|
211 kumpf 1.6 PEGASUS_NAMESPACE_END
212
213 PEGASUS_USING_PEGASUS;
214
215 // This is the entry point into this dynamic module.
216
217 extern "C" PEGASUS_EXPORT CIMHandler* PegasusCreateHandler(
218 const String& handlerName)
219 {
220 if (handlerName == "SystemLogListenerDestination")
221 {
222 return new SystemLogListenerDestination;
223 }
224
225 return 0;
|
226 yi.zhou 1.1 }
|