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 CIMInstance& indication,
60 CIMInstance& handler,
61 CIMInstance& subscription,
|
62 kumpf 1.4 ContentLanguageList & contentLanguages)
|
63 yi.zhou 1.1 {
64 PEG_METHOD_ENTER (TRC_IND_HANDLER,
65 "SystemLogListenerDestination::handleIndication");
66
67 String ident_name = "CIM Indication";
68 String indicationText;
69
70 try
71 {
|
72 yi.zhou 1.2 // gets formatted indication message
73 indicationText = IndicationFormatter::getFormattedIndText(
74 subscription, indication, contentLanguages);
|
75 yi.zhou 1.1
76 // default severity
77 Uint32 severity = Logger::INFORMATION;
78
79 // If an indication contains severity information, gets the value
80 // and maps it to Pegasus logger severity. Otherwise, default value
81 // is used.
82
83 Uint32 severityPos = indication.findProperty(CIMName
84 ("PerceivedSeverity"));
85
86 if (severityPos != PEG_NOT_FOUND)
87 {
88 Uint16 perceivedSeverity;
89 CIMValue perceivedSeverityValue =
90 indication.getProperty(severityPos).getValue();
91
92 if (!perceivedSeverityValue.isNull())
93 {
94 perceivedSeverityValue.get(perceivedSeverity);
95
96 yi.zhou 1.1 switch (perceivedSeverity)
97 {
98 case (_SEVERITY_FATAL):
99 case (_SEVERITY_CRITICAL):
100 {
101 severity = Logger::FATAL;
102 break;
103 }
104
105 case (_SEVERITY_MAJOR):
106 {
107 severity = Logger::SEVERE;
108 break;
109 }
110
111 case (_SEVERITY_MINOR):
112 case (_SEVERITY_WARNING):
113 {
114 severity = Logger::WARNING;
115 break;
116 }
117 yi.zhou 1.1
118 case (_SEVERITY_INFORMATION):
119 case (_SEVERITY_OTHER):
120 case (_SEVERITY_UNKNOWN):
121 {
122 severity = Logger::INFORMATION;
123 break;
124 }
125
126 default:
127 {
128 Tracer::trace(TRC_IND_HANDLER, Tracer::LEVEL4,
129 "PerceivedSeverity = %d is not a valid value."
130 " Using default severity.", perceivedSeverity);
131 break;
132 }
133 }
134 }
135 }
136
137 // writes the formatted indication to a system log file
138 yi.zhou 1.1 _writeToSystemLog(ident_name, severity, indicationText);
139
140 }
141 catch (CIMException & c)
142 {
143 PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, c.getMessage());
144 PEG_METHOD_EXIT();
145
146 throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, c.getMessage());
147 }
148 catch (Exception& e)
149 {
150 PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, e.getMessage());
151 PEG_METHOD_EXIT();
152
153 throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, e.getMessage());
154 }
155 catch (...)
156 {
157 PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
158 "Failed to deliver indication to system log file.");
159 yi.zhou 1.1 PEG_METHOD_EXIT();
160
161 throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
162 MessageLoaderParms("Handler.SystemLogListenerDestination."
163 "SystemLogListenerDestination.FAILED_TO_DELIVER_INDICATION_TO_SYSTEM_LOG",
164 "Failed to deliver indication to system log file."));
165 }
166
167 PEG_METHOD_EXIT();
168 }
169
170 void SystemLogListenerDestination::_writeToSystemLog(
171 const String & identifier,
172 Uint32 severity,
173 const String & formattedText)
174 {
175 PEG_METHOD_ENTER (TRC_IND_HANDLER,
176 "SystemLogListenerDestination::_writeToSystemLog");
177
178 #if defined(PEGASUS_USE_SYSLOGS)
179
|
180 kumpf 1.3 System::syslog(identifier, severity, formattedText.getCString());
|
181 yi.zhou 1.1
182 #else
183
184 // PEGASUS_USE_SYSLOGS is not defined, writes the formatted
185 // indications into PegasusStandard.log file
186 Logger::put (Logger::STANDARD_LOG , identifier, severity,
187 (const char *)formattedText.getCString());
188
189 #endif
190
191 PEG_METHOD_EXIT();
192
193 }
194
|
195 kumpf 1.6 PEGASUS_NAMESPACE_END
196
197 PEGASUS_USING_PEGASUS;
198
199 // This is the entry point into this dynamic module.
200
201 extern "C" PEGASUS_EXPORT CIMHandler* PegasusCreateHandler(
202 const String& handlerName)
203 {
204 if (handlerName == "SystemLogListenerDestination")
205 {
206 return new SystemLogListenerDestination;
207 }
208
209 return 0;
|
210 yi.zhou 1.1 }
|