(file) Return to SystemLogListenerDestination.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Handler / SystemLogListenerDestination

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2