(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             #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                 String textFormat = String::EMPTY;
 77                 CIMValue textFormatValue;
 78                 CIMValue textFormatParamsValue;
 79             
 80                 Array<String> textFormatParams = NULL;
 81             
 82                 try
 83                 {
 84                     // get TextFormat from subscription
 85 yi.zhou 1.1         Uint32 textFormatPos = 
 86             	    subscription.findProperty(_PROPERTY_TEXTFORMAT); 
 87             
 88             	// if the property TextFormat is not found, 
 89             	// indication is constructed with default format
 90                     if (textFormatPos == PEG_NOT_FOUND)
 91                     {
 92                         indicationText = IndicationFormatter::formatDefaultIndicationText
 93             			     (indication);
 94                     }
 95                     else
 96                     {
 97                         textFormatValue = subscription.getProperty(textFormatPos).
 98             		getValue();
 99             
100             	    // if the value of textFormat is NULL, 
101             	    // indication is constructed with default format
102                         if (textFormatValue.isNull()) 
103                         {
104                             indicationText = 
105             		    IndicationFormatter::formatDefaultIndicationText(indication);
106 yi.zhou 1.1 	    }
107             	    else
108             	    {
109                             // get TextFormatParameters from subscription
110                             Uint32 textFormatParamsPos = subscription.findProperty(
111             		    _PROPERTY_TEXTFORMATPARAMETERS); 
112             
113             	        if (textFormatParamsPos != PEG_NOT_FOUND)
114             	        {
115                                 textFormatParamsValue = subscription.getProperty(
116             	                textFormatParamsPos).getValue();
117                             }
118             
119             		// constructs indication with specified format
120             		if ((textFormatValue.getType() == CIMTYPE_STRING) &&
121             		    !(textFormatValue.isArray()))
122                             {
123             		    textFormatValue.get(textFormat);
124             		    if (!textFormatParamsValue.isNull())
125             		    {
126             			if ((textFormatParamsValue.getType() == 
127 yi.zhou 1.1 			     CIMTYPE_STRING) &&
128                                         (textFormatParamsValue.isArray()))
129                                     {
130             		            textFormatParamsValue.get(textFormatParams);
131                                     }
132             		    }
133             
134             		    indicationText = IndicationFormatter::formatIndicationText
135             				     (textFormat,
136             				      textFormatParams,
137             				      indication,
138             				      contentLanguages);
139             		}
140             		else
141             		{
142                                 indicationText = 
143             		        IndicationFormatter::formatDefaultIndicationText(
144             			    indication);
145             		}
146             	    }
147                     }
148 yi.zhou 1.1 
149                     // default severity
150                     Uint32 severity = Logger::INFORMATION;
151             
152                     // If an indication contains severity information, gets the value
153                     // and maps it to Pegasus logger severity. Otherwise, default value 
154                     // is used.
155             
156                     Uint32 severityPos = indication.findProperty(CIMName 
157             	    ("PerceivedSeverity")); 
158             
159                     if (severityPos != PEG_NOT_FOUND)
160                     {
161                         Uint16 perceivedSeverity;
162                         CIMValue perceivedSeverityValue = 
163                             indication.getProperty(severityPos).getValue();
164             
165                         if (!perceivedSeverityValue.isNull())
166                         {
167                             perceivedSeverityValue.get(perceivedSeverity);
168             
169 yi.zhou 1.1                 switch (perceivedSeverity)
170                             {
171                                 case (_SEVERITY_FATAL):
172                                 case (_SEVERITY_CRITICAL):
173                                 {
174                                     severity = Logger::FATAL;
175                                     break;
176                                 }
177             
178                                 case (_SEVERITY_MAJOR):
179                                 {
180                                     severity = Logger::SEVERE;
181                                     break;
182                                 }
183             
184                                 case (_SEVERITY_MINOR):
185                                 case (_SEVERITY_WARNING):
186                                 {
187                                     severity = Logger::WARNING;
188                                     break;
189                                 }
190 yi.zhou 1.1 
191                                 case (_SEVERITY_INFORMATION):
192                                 case (_SEVERITY_OTHER):
193                                 case (_SEVERITY_UNKNOWN):
194                                 {
195                                     severity = Logger::INFORMATION;
196                                     break;
197                                 }
198             
199                                 default:
200                                 {
201             			Tracer::trace(TRC_IND_HANDLER, Tracer::LEVEL4,
202             			    "PerceivedSeverity = %d is not a valid value." 
203             			    " Using default severity.", perceivedSeverity);
204                                     break;
205                                 }
206                             }
207                         }
208                     }
209             
210             	// writes the formatted indication to a system log file
211 yi.zhou 1.1 	_writeToSystemLog(ident_name, severity, indicationText);
212             
213                 }
214                 catch (CIMException & c)
215                 {
216                     PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, c.getMessage());
217                     PEG_METHOD_EXIT();
218             
219                     throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, c.getMessage());
220                 }
221                 catch (Exception& e)
222                 {
223                     PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, e.getMessage());
224                     PEG_METHOD_EXIT();
225             
226                     throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, e.getMessage());
227                 }
228                 catch (...)
229                 {
230                     PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
231                         "Failed to deliver indication to system log file.");
232 yi.zhou 1.1         PEG_METHOD_EXIT();
233                
234                     throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
235                         MessageLoaderParms("Handler.SystemLogListenerDestination."
236             	    "SystemLogListenerDestination.FAILED_TO_DELIVER_INDICATION_TO_SYSTEM_LOG",
237                         "Failed to deliver indication to system log file."));
238                 }
239             
240                 PEG_METHOD_EXIT();
241             }
242             
243             void SystemLogListenerDestination::_writeToSystemLog(
244                 const String & identifier,
245                 Uint32 severity,
246                 const String & formattedText)
247             {
248                 PEG_METHOD_ENTER (TRC_IND_HANDLER,
249             	"SystemLogListenerDestination::_writeToSystemLog");
250             
251             #if defined(PEGASUS_USE_SYSLOGS)
252                 
253 yi.zhou 1.1     // Open the syslog
254                 System::openlog(identifier);
255             
256                 System::syslog(severity, (const char *)formattedText.getCString());
257             
258                 // Close the syslog
259                 System::closelog();
260             
261             #else
262             
263                 // PEGASUS_USE_SYSLOGS is not defined, writes the formatted 
264                 // indications into PegasusStandard.log file
265                 Logger::put (Logger::STANDARD_LOG , identifier, severity, 
266             		 (const char *)formattedText.getCString());
267             
268             #endif
269             
270                 PEG_METHOD_EXIT();
271             
272             }
273             
274 yi.zhou 1.1 // This is the dynamic entry point into this dynamic module. The name of
275             // this handler is "SystemLogListenerDestination" which is appended to "PegasusCreateHandler_"
276             // to form a symbol name. This function is called by the HandlerTable
277             // to load this handler.
278             
279             extern "C" PEGASUS_EXPORT CIMHandler* 
280                 PegasusCreateHandler_SystemLogListenerDestination() {
281                 return new SystemLogListenerDestination;
282             }
283             
284             PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2