(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 r.kieninger 1.11         PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
 73 w.otsuka    1.10             "SystemLogListenerDestination %s:%s.%s processing %s Indication",
 74                             (const char*)(nameSpace.getCString()),
 75                             (const char*)(handler.getClassName().getString().getCString()),
 76                             (const char*)(handler.getProperty(
 77                             handler.findProperty(PEGASUS_PROPERTYNAME_NAME)).
 78                             getValue().toString().getCString()),
 79                             (const char*)(indication.getClassName().getString().
 80                             getCString())));
 81 kumpf       1.7          // gets formatted indication message
 82                          indicationText = IndicationFormatter::getFormattedIndText(
 83                              subscription, indication, contentLanguages);
 84 yi.zhou     1.1  
 85                          // default severity
 86                          Uint32 severity = Logger::INFORMATION;
 87                  
 88                          // If an indication contains severity information, gets the value
 89 kumpf       1.7          // and maps it to Pegasus logger severity. Otherwise, default value
 90 yi.zhou     1.1          // is used.
 91                  
 92 kumpf       1.7          Uint32 severityPos =
 93                              indication.findProperty(CIMName("PerceivedSeverity"));
 94 yi.zhou     1.1  
 95                          if (severityPos != PEG_NOT_FOUND)
 96                          {
 97                              Uint16 perceivedSeverity;
 98 kumpf       1.7              CIMValue perceivedSeverityValue =
 99 yi.zhou     1.1                  indication.getProperty(severityPos).getValue();
100                  
101                              if (!perceivedSeverityValue.isNull())
102                              {
103                                  perceivedSeverityValue.get(perceivedSeverity);
104                  
105                                  switch (perceivedSeverity)
106                                  {
107                                      case (_SEVERITY_FATAL):
108                                      case (_SEVERITY_CRITICAL):
109                                      {
110                                          severity = Logger::FATAL;
111                                          break;
112                                      }
113                  
114                                      case (_SEVERITY_MAJOR):
115                                      {
116                                          severity = Logger::SEVERE;
117                                          break;
118                                      }
119                  
120 yi.zhou     1.1                      case (_SEVERITY_MINOR):
121                                      case (_SEVERITY_WARNING):
122                                      {
123                                          severity = Logger::WARNING;
124                                          break;
125                                      }
126                  
127                                      case (_SEVERITY_INFORMATION):
128                                      case (_SEVERITY_OTHER):
129                                      case (_SEVERITY_UNKNOWN):
130                                      {
131                                          severity = Logger::INFORMATION;
132                                          break;
133                                      }
134                  
135                                      default:
136                                      {
137 mike        1.11.4.1                         PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL2,
138 kumpf       1.7                                  "PerceivedSeverity = %d is not a valid value."
139 marek       1.8                                  " Using default severity.", perceivedSeverity));
140 yi.zhou     1.1                              break;
141                                          }
142                                      }
143                                  }
144                              }
145                      
146 mike        1.11.4.1        PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
147 w.otsuka    1.10                "SystemLogListenerDestination writing %s Indication to system log",
148                                 (const char*)(indication.getClassName().getString().getCString())));
149                             // writes the formatted indication to a system log file
150 kumpf       1.7              _writeToSystemLog(ident_name, severity, indicationText);
151 mike        1.11.4.1        PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
152 w.otsuka    1.10                "%s Indication written to system log successfully",
153                                 (const char*)(indication.getClassName().getString().getCString())));
154 yi.zhou     1.1          }
155 kumpf       1.7          catch (CIMException& c)
156 yi.zhou     1.1          {
157 mike        1.11.4.1         PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL1, c.getMessage());
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 mike        1.11.4.1         PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL1, e.getMessage());
165 yi.zhou     1.1              PEG_METHOD_EXIT();
166                      
167 kumpf       1.7              throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
168 yi.zhou     1.1          }
169                          catch (...)
170                          {
171 mike        1.11.4.1         PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
172 yi.zhou     1.1                  "Failed to deliver indication to system log file.");
173                              PEG_METHOD_EXIT();
174 kumpf       1.7      
175                              throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
176                                  "Handler.SystemLogListenerDestination.SystemLogListenerDestination."
177                                      "FAILED_TO_DELIVER_INDICATION_TO_SYSTEM_LOG",
178 yi.zhou     1.1                  "Failed to deliver indication to system log file."));
179                          }
180                      
181                          PEG_METHOD_EXIT();
182                      }
183                      
184                      void SystemLogListenerDestination::_writeToSystemLog(
185 kumpf       1.7          const String& identifier,
186 yi.zhou     1.1          Uint32 severity,
187 kumpf       1.7          const String& formattedText)
188 yi.zhou     1.1      {
189 kumpf       1.7          PEG_METHOD_ENTER(TRC_IND_HANDLER,
190                              "SystemLogListenerDestination::_writeToSystemLog");
191 yi.zhou     1.1      
192                      #if defined(PEGASUS_USE_SYSLOGS)
193                      
194 kumpf       1.3          System::syslog(identifier, severity, formattedText.getCString());
195 yi.zhou     1.1      
196                      #else
197                      
198 mike        1.11.4.1     PEG_TRACE_CSTRING(TRC_INDICATION_GENERATION, Tracer::LEVEL3,
199                             "SystemLogListenerDestination writing to PegasusStandard.log");
200 kumpf       1.7          // PEGASUS_USE_SYSLOGS is not defined, writes the formatted
201 yi.zhou     1.1          // indications into PegasusStandard.log file
202 kumpf       1.7          Logger::put(Logger::STANDARD_LOG , identifier, severity,
203                              (const char*)formattedText.getCString());
204 yi.zhou     1.1      
205                      #endif
206                      
207                          PEG_METHOD_EXIT();
208                      
209                      }
210                      
211 kumpf       1.6      PEGASUS_NAMESPACE_END
212                      
213                      PEGASUS_USING_PEGASUS;
214                      
215                      // This is the entry point into this dynamic module.
216                      
217                      extern "C" PEGASUS_EXPORT CIMHandler* PegasusCreateHandler(
218                          const String& handlerName)
219                      {
220                          if (handlerName == "SystemLogListenerDestination")
221                          {
222                              return new SystemLogListenerDestination;
223                          }
224                      
225                          return 0;
226 yi.zhou     1.1      }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2