1 yi.zhou 1.1 //%2005////////////////////////////////////////////////////////////////////////
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 //
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a copy
14 // of this software and associated documentation files (the "Software"), to
15 // deal in the Software without restriction, including without limitation the
16 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
17 // sell copies of the Software, and to permit persons to whom the Software is
18 // furnished to do so, subject to the following conditions:
19 //
20 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
21 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
22 yi.zhou 1.1 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
23 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
24 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29 //==============================================================================
30 //
31 // Author: Yi Zhou, Hewlett-Packard Company (yi.zhou@hp.com)
32 //
33 // Modified By:
34 //
35 //%/////////////////////////////////////////////////////////////////////////////
36
37 #include <Pegasus/Common/Config.h>
38 #include <Pegasus/Common/PegasusVersion.h>
39
40 #include <iostream>
41 #include <Pegasus/Handler/CIMHandler.h>
42 #include <Pegasus/Repository/CIMRepository.h>
43 yi.zhou 1.1 #include <Pegasus/Common/Tracer.h>
44 #include <Pegasus/Common/MessageLoader.h>
45 #include <Pegasus/Common/System.h>
46 #include <Pegasus/Common/CIMType.h>
47 #include <Pegasus/Common/IndicationFormatter.h>
48
49 #if defined(PEGASUS_USE_SYSLOGS)
50 #include <syslog.h>
51 #endif
52
53 #include "SystemLogListenerDestination.h"
54
55 PEGASUS_NAMESPACE_BEGIN
56
57 PEGASUS_USING_STD;
58
59 void SystemLogListenerDestination::initialize(CIMRepository* repository)
60 {
61 }
62
63 void SystemLogListenerDestination::handleIndication(
64 yi.zhou 1.1 const OperationContext& context,
65 const String nameSpace,
66 CIMInstance& indication,
67 CIMInstance& handler,
68 CIMInstance& subscription,
69 ContentLanguages & contentLanguages)
70 {
71 PEG_METHOD_ENTER (TRC_IND_HANDLER,
72 "SystemLogListenerDestination::handleIndication");
73
74 String ident_name = "CIM Indication";
75 String indicationText;
76
77 try
78 {
|
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 // and maps it to Pegasus logger severity. Otherwise, default value
88 // is used.
89
90 Uint32 severityPos = indication.findProperty(CIMName
91 ("PerceivedSeverity"));
92
93 if (severityPos != PEG_NOT_FOUND)
94 {
95 Uint16 perceivedSeverity;
96 CIMValue perceivedSeverityValue =
97 indication.getProperty(severityPos).getValue();
98
99 if (!perceivedSeverityValue.isNull())
100 {
101 perceivedSeverityValue.get(perceivedSeverity);
102
103 yi.zhou 1.1 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 case (_SEVERITY_MINOR):
119 case (_SEVERITY_WARNING):
120 {
121 severity = Logger::WARNING;
122 break;
123 }
124 yi.zhou 1.1
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 Tracer::trace(TRC_IND_HANDLER, Tracer::LEVEL4,
136 "PerceivedSeverity = %d is not a valid value."
137 " Using default severity.", perceivedSeverity);
138 break;
139 }
140 }
141 }
142 }
143
144 // writes the formatted indication to a system log file
145 yi.zhou 1.1 _writeToSystemLog(ident_name, severity, indicationText);
146
147 }
148 catch (CIMException & c)
149 {
150 PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, c.getMessage());
151 PEG_METHOD_EXIT();
152
153 throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, c.getMessage());
154 }
155 catch (Exception& e)
156 {
157 PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, e.getMessage());
158 PEG_METHOD_EXIT();
159
160 throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, e.getMessage());
161 }
162 catch (...)
163 {
164 PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
165 "Failed to deliver indication to system log file.");
166 yi.zhou 1.1 PEG_METHOD_EXIT();
167
168 throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
169 MessageLoaderParms("Handler.SystemLogListenerDestination."
170 "SystemLogListenerDestination.FAILED_TO_DELIVER_INDICATION_TO_SYSTEM_LOG",
171 "Failed to deliver indication to system log file."));
172 }
173
174 PEG_METHOD_EXIT();
175 }
176
177 void SystemLogListenerDestination::_writeToSystemLog(
178 const String & identifier,
179 Uint32 severity,
180 const String & formattedText)
181 {
182 PEG_METHOD_ENTER (TRC_IND_HANDLER,
183 "SystemLogListenerDestination::_writeToSystemLog");
184
185 #if defined(PEGASUS_USE_SYSLOGS)
186
187 yi.zhou 1.1 // Open the syslog
188 System::openlog(identifier);
189
190 System::syslog(severity, (const char *)formattedText.getCString());
191
192 // Close the syslog
193 System::closelog();
194
195 #else
196
197 // PEGASUS_USE_SYSLOGS is not defined, writes the formatted
198 // indications into PegasusStandard.log file
199 Logger::put (Logger::STANDARD_LOG , identifier, severity,
200 (const char *)formattedText.getCString());
201
202 #endif
203
204 PEG_METHOD_EXIT();
205
206 }
207
208 yi.zhou 1.1 // This is the dynamic entry point into this dynamic module. The name of
209 // this handler is "SystemLogListenerDestination" which is appended to "PegasusCreateHandler_"
210 // to form a symbol name. This function is called by the HandlerTable
211 // to load this handler.
212
213 extern "C" PEGASUS_EXPORT CIMHandler*
214 PegasusCreateHandler_SystemLogListenerDestination() {
215 return new SystemLogListenerDestination;
216 }
217
218 PEGASUS_NAMESPACE_END
|