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

  1 martin 1.15 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.16 //
  3 martin 1.15 // Licensed to The Open Group (TOG) under one or more contributor license
  4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5             // this work for additional information regarding copyright ownership.
  6             // Each contributor licenses this file to you under the OpenPegasus Open
  7             // Source License; you may not use this file except in compliance with the
  8             // License.
  9 martin 1.16 //
 10 martin 1.15 // Permission is hereby granted, free of charge, to any person obtaining a
 11             // copy of this software and associated documentation files (the "Software"),
 12             // to deal in the Software without restriction, including without limitation
 13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14             // and/or sell copies of the Software, and to permit persons to whom the
 15             // Software is furnished to do so, subject to the following conditions:
 16 martin 1.16 //
 17 martin 1.15 // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19 martin 1.16 //
 20 martin 1.15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.16 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.15 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.16 //
 28 martin 1.15 //////////////////////////////////////////////////////////////////////////
 29 yi.zhou 1.1  //
 30              //%/////////////////////////////////////////////////////////////////////////////
 31              
 32              #include <Pegasus/Common/Config.h>
 33              #include <Pegasus/Common/PegasusVersion.h>
 34              
 35              #include <iostream>
 36              #include <Pegasus/Handler/CIMHandler.h>
 37 thilo.boehm 1.18 #include <Pegasus/Handler/IndicationFormatter.h>
 38 yi.zhou     1.1  #include <Pegasus/Repository/CIMRepository.h>
 39                  #include <Pegasus/Common/Tracer.h>
 40                  #include <Pegasus/Common/MessageLoader.h>
 41                  #include <Pegasus/Common/System.h>
 42                  #include <Pegasus/Common/CIMType.h>
 43 thilo.boehm 1.18 
 44 yi.zhou     1.1  
 45                  #include "SystemLogListenerDestination.h"
 46                  
 47                  PEGASUS_NAMESPACE_BEGIN
 48                  
 49                  PEGASUS_USING_STD;
 50                  
 51                  void SystemLogListenerDestination::initialize(CIMRepository* repository)
 52                  {
 53                  }
 54                  
 55                  void SystemLogListenerDestination::handleIndication(
 56                      const OperationContext& context,
 57 dl.meetei   1.19     const String &nameSpace,
 58 kumpf       1.7      CIMInstance& indication,
 59                      CIMInstance& handler,
 60                      CIMInstance& subscription,
 61                      ContentLanguageList& contentLanguages)
 62 yi.zhou     1.1  {
 63 kumpf       1.7      PEG_METHOD_ENTER(TRC_IND_HANDLER,
 64 yi.zhou     1.1          "SystemLogListenerDestination::handleIndication");
 65                  
 66                      String ident_name = "CIM Indication";
 67                      String indicationText;
 68                  
 69                      try
 70                      {
 71 r.kieninger 1.11         PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
 72 w.otsuka    1.10             "SystemLogListenerDestination %s:%s.%s processing %s Indication",
 73                             (const char*)(nameSpace.getCString()),
 74                             (const char*)(handler.getClassName().getString().getCString()),
 75                             (const char*)(handler.getProperty(
 76                             handler.findProperty(PEGASUS_PROPERTYNAME_NAME)).
 77                             getValue().toString().getCString()),
 78                             (const char*)(indication.getClassName().getString().
 79                             getCString())));
 80 kumpf       1.7          // gets formatted indication message
 81                          indicationText = IndicationFormatter::getFormattedIndText(
 82                              subscription, indication, contentLanguages);
 83 yi.zhou     1.1  
 84                          // default severity
 85                          Uint32 severity = Logger::INFORMATION;
 86                  
 87                          // If an indication contains severity information, gets the value
 88 kumpf       1.7          // and maps it to Pegasus logger severity. Otherwise, default value
 89 yi.zhou     1.1          // is used.
 90                  
 91 kumpf       1.7          Uint32 severityPos =
 92                              indication.findProperty(CIMName("PerceivedSeverity"));
 93 yi.zhou     1.1  
 94                          if (severityPos != PEG_NOT_FOUND)
 95                          {
 96                              Uint16 perceivedSeverity;
 97 kumpf       1.7              CIMValue perceivedSeverityValue =
 98 yi.zhou     1.1                  indication.getProperty(severityPos).getValue();
 99                  
100                              if (!perceivedSeverityValue.isNull())
101                              {
102                                  perceivedSeverityValue.get(perceivedSeverity);
103                  
104                                  switch (perceivedSeverity)
105                                  {
106                                      case (_SEVERITY_FATAL):
107                                      case (_SEVERITY_CRITICAL):
108                                      {
109                                          severity = Logger::FATAL;
110                                          break;
111                                      }
112                  
113                                      case (_SEVERITY_MAJOR):
114                                      {
115                                          severity = Logger::SEVERE;
116                                          break;
117                                      }
118                  
119 yi.zhou     1.1                      case (_SEVERITY_MINOR):
120                                      case (_SEVERITY_WARNING):
121                                      {
122                                          severity = Logger::WARNING;
123                                          break;
124                                      }
125                  
126                                      case (_SEVERITY_INFORMATION):
127                                      case (_SEVERITY_OTHER):
128                                      case (_SEVERITY_UNKNOWN):
129                                      {
130                                          severity = Logger::INFORMATION;
131                                          break;
132                                      }
133                  
134                                      default:
135                                      {
136 marek       1.12                         PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL2,
137 kumpf       1.7                              "PerceivedSeverity = %d is not a valid value."
138 marek       1.8                              " Using default severity.", perceivedSeverity));
139 yi.zhou     1.1                          break;
140                                      }
141                                  }
142                              }
143                          }
144                  
145 marek       1.12        PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
146 w.otsuka    1.10            "SystemLogListenerDestination writing %s Indication to system log",
147                             (const char*)(indication.getClassName().getString().getCString())));
148                         // writes the formatted indication to a system log file
149 kumpf       1.7          _writeToSystemLog(ident_name, severity, indicationText);
150 marek       1.12        PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
151 w.otsuka    1.10            "%s Indication written to system log successfully",
152                             (const char*)(indication.getClassName().getString().getCString())));
153 yi.zhou     1.1      }
154 kumpf       1.7      catch (CIMException& c)
155 yi.zhou     1.1      {
156 thilo.boehm 1.14         PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1, "CIMException: %s",
157                              (const char*)c.getMessage().getCString()));
158 yi.zhou     1.1          PEG_METHOD_EXIT();
159                  
160 kumpf       1.7          throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, c.getMessage());
161 yi.zhou     1.1      }
162 kumpf       1.7      catch (Exception&e)
163 yi.zhou     1.1      {
164 thilo.boehm 1.14         PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1, "Exception: %s",
165                              (const char*)e.getMessage().getCString()));
166 yi.zhou     1.1          PEG_METHOD_EXIT();
167                  
168 kumpf       1.7          throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
169 yi.zhou     1.1      }
170                      catch (...)
171                      {
172 marek       1.12         PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
173 yi.zhou     1.1              "Failed to deliver indication to system log file.");
174                          PEG_METHOD_EXIT();
175 kumpf       1.7  
176                          throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
177                              "Handler.SystemLogListenerDestination.SystemLogListenerDestination."
178                                  "FAILED_TO_DELIVER_INDICATION_TO_SYSTEM_LOG",
179 yi.zhou     1.1              "Failed to deliver indication to system log file."));
180                      }
181                  
182                      PEG_METHOD_EXIT();
183                  }
184                  
185                  void SystemLogListenerDestination::_writeToSystemLog(
186 kumpf       1.7      const String& identifier,
187 yi.zhou     1.1      Uint32 severity,
188 kumpf       1.7      const String& formattedText)
189 yi.zhou     1.1  {
190 kumpf       1.7      PEG_METHOD_ENTER(TRC_IND_HANDLER,
191                          "SystemLogListenerDestination::_writeToSystemLog");
192 yi.zhou     1.1  
193                  #if defined(PEGASUS_USE_SYSLOGS)
194                  
195 kumpf       1.3      System::syslog(identifier, severity, formattedText.getCString());
196 yi.zhou     1.1  
197                  #else
198                  
199 carson.hovey 1.13     PEG_TRACE_CSTRING(TRC_INDICATION_GENERATION, Tracer::LEVEL3,
200                          "SystemLogListenerDestination writing to PegasusStandard.log");
201 kumpf        1.7      // PEGASUS_USE_SYSLOGS is not defined, writes the formatted
202 yi.zhou      1.1      // indications into PegasusStandard.log file
203 kumpf        1.7      Logger::put(Logger::STANDARD_LOG , identifier, severity,
204                           (const char*)formattedText.getCString());
205 yi.zhou      1.1  
206                   #endif
207                   
208                       PEG_METHOD_EXIT();
209                   
210                   }
211                   
212 kumpf        1.6  PEGASUS_NAMESPACE_END
213                   
214                   PEGASUS_USING_PEGASUS;
215                   
216                   // This is the entry point into this dynamic module.
217                   
218                   extern "C" PEGASUS_EXPORT CIMHandler* PegasusCreateHandler(
219                       const String& handlerName)
220                   {
221                       if (handlerName == "SystemLogListenerDestination")
222                       {
223                           return new SystemLogListenerDestination;
224                       }
225                   
226                       return 0;
227 yi.zhou      1.1  }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2