1 a.dunfey 1.3.8.1 //%2006////////////////////////////////////////////////////////////////////////
|
2 yi.zhou 1.1 //
|
3 a.dunfey 1.3.8.1 // 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 a.dunfey 1.3.8.1 // 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 // Author: Yi Zhou, Hewlett-Packard Company (yi.zhou@hp.com)
33 //
34 yi.zhou 1.1 // Modified By:
35 //
36 //%/////////////////////////////////////////////////////////////////////////////
37
38 #include <Pegasus/Common/Config.h>
39 #include <Pegasus/Common/PegasusVersion.h>
40
41 #include <iostream>
42 #include <Pegasus/Handler/CIMHandler.h>
43 #include <Pegasus/Repository/CIMRepository.h>
44 #include <Pegasus/Common/Tracer.h>
45 #include <Pegasus/Common/MessageLoader.h>
46 #include <Pegasus/Common/System.h>
47 #include <Pegasus/Common/CIMType.h>
48 #include <Pegasus/Common/IndicationFormatter.h>
49
50 #include "SystemLogListenerDestination.h"
51
52 PEGASUS_NAMESPACE_BEGIN
53
54 PEGASUS_USING_STD;
55 yi.zhou 1.1
56 void SystemLogListenerDestination::initialize(CIMRepository* repository)
57 {
58 }
59
60 void SystemLogListenerDestination::handleIndication(
61 const OperationContext& context,
62 const String nameSpace,
63 CIMInstance& indication,
64 CIMInstance& handler,
65 CIMInstance& subscription,
|
66 a.dunfey 1.3.8.1 ContentLanguageList & contentLanguages)
|
67 yi.zhou 1.1 {
68 PEG_METHOD_ENTER (TRC_IND_HANDLER,
69 "SystemLogListenerDestination::handleIndication");
70
71 String ident_name = "CIM Indication";
72 String indicationText;
73
74 try
75 {
|
76 yi.zhou 1.2 // gets formatted indication message
77 indicationText = IndicationFormatter::getFormattedIndText(
78 subscription, indication, contentLanguages);
|
79 yi.zhou 1.1
80 // default severity
81 Uint32 severity = Logger::INFORMATION;
82
83 // If an indication contains severity information, gets the value
84 // and maps it to Pegasus logger severity. Otherwise, default value
85 // is used.
86
87 Uint32 severityPos = indication.findProperty(CIMName
88 ("PerceivedSeverity"));
89
90 if (severityPos != PEG_NOT_FOUND)
91 {
92 Uint16 perceivedSeverity;
93 CIMValue perceivedSeverityValue =
94 indication.getProperty(severityPos).getValue();
95
96 if (!perceivedSeverityValue.isNull())
97 {
98 perceivedSeverityValue.get(perceivedSeverity);
99
100 yi.zhou 1.1 switch (perceivedSeverity)
101 {
102 case (_SEVERITY_FATAL):
103 case (_SEVERITY_CRITICAL):
104 {
105 severity = Logger::FATAL;
106 break;
107 }
108
109 case (_SEVERITY_MAJOR):
110 {
111 severity = Logger::SEVERE;
112 break;
113 }
114
115 case (_SEVERITY_MINOR):
116 case (_SEVERITY_WARNING):
117 {
118 severity = Logger::WARNING;
119 break;
120 }
121 yi.zhou 1.1
122 case (_SEVERITY_INFORMATION):
123 case (_SEVERITY_OTHER):
124 case (_SEVERITY_UNKNOWN):
125 {
126 severity = Logger::INFORMATION;
127 break;
128 }
129
130 default:
131 {
132 Tracer::trace(TRC_IND_HANDLER, Tracer::LEVEL4,
133 "PerceivedSeverity = %d is not a valid value."
134 " Using default severity.", perceivedSeverity);
135 break;
136 }
137 }
138 }
139 }
140
141 // writes the formatted indication to a system log file
142 yi.zhou 1.1 _writeToSystemLog(ident_name, severity, indicationText);
143
144 }
145 catch (CIMException & c)
146 {
147 PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, c.getMessage());
148 PEG_METHOD_EXIT();
149
150 throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, c.getMessage());
151 }
152 catch (Exception& e)
153 {
154 PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, e.getMessage());
155 PEG_METHOD_EXIT();
156
157 throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, e.getMessage());
158 }
159 catch (...)
160 {
161 PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
162 "Failed to deliver indication to system log file.");
163 yi.zhou 1.1 PEG_METHOD_EXIT();
164
165 throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
166 MessageLoaderParms("Handler.SystemLogListenerDestination."
167 "SystemLogListenerDestination.FAILED_TO_DELIVER_INDICATION_TO_SYSTEM_LOG",
168 "Failed to deliver indication to system log file."));
169 }
170
171 PEG_METHOD_EXIT();
172 }
173
174 void SystemLogListenerDestination::_writeToSystemLog(
175 const String & identifier,
176 Uint32 severity,
177 const String & formattedText)
178 {
179 PEG_METHOD_ENTER (TRC_IND_HANDLER,
180 "SystemLogListenerDestination::_writeToSystemLog");
181
182 #if defined(PEGASUS_USE_SYSLOGS)
183
|
184 kumpf 1.3 System::syslog(identifier, severity, formattedText.getCString());
|
185 yi.zhou 1.1
186 #else
187
188 // PEGASUS_USE_SYSLOGS is not defined, writes the formatted
189 // indications into PegasusStandard.log file
190 Logger::put (Logger::STANDARD_LOG , identifier, severity,
191 (const char *)formattedText.getCString());
192
193 #endif
194
195 PEG_METHOD_EXIT();
196
197 }
198
199 // This is the dynamic entry point into this dynamic module. The name of
200 // this handler is "SystemLogListenerDestination" which is appended to "PegasusCreateHandler_"
201 // to form a symbol name. This function is called by the HandlerTable
202 // to load this handler.
203
204 extern "C" PEGASUS_EXPORT CIMHandler*
205 PegasusCreateHandler_SystemLogListenerDestination() {
206 yi.zhou 1.1 return new SystemLogListenerDestination;
207 }
208
209 PEGASUS_NAMESPACE_END
|