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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2