static void _test1 (CIMClient & client, const String & ql) { try { for (Uint32 i = 0; i < QUERIES; i++) { if (verbose) cerr << "Querying " << queries[i] << endl; Array < CIMObject > objects = client.execQuery (providerNamespace, ql, queries[i]); if (objects.size () == 0) { // Only the third (second when starting from zero) // and eight(7) won't return instances. //PEGASUS_TEST_ASSERT(i == 2 || i == 5 || i == 7 // || i == 8 || i == 12); if (verbose) cerr <<i<< " No instance returned.. That is good" << endl; } for (Uint32 i = 0; i < objects.size (); i++) { if (objects[i].isInstance ()) { CIMInstance inst (objects[i]); if (inst.findProperty ("ElementName") != PEG_NOT_FOUND) _checkStringProperty (inst, "ElementName", "TestCMPI_ExecQuery"); if (inst.findProperty ("s") != PEG_NOT_FOUND) _checkStringProperty (inst, "s", "s"); if (inst.findProperty ("n32") != PEG_NOT_FOUND) _checkUint32Property (inst, "n32", 32); if (inst.findProperty ("n64") != PEG_NOT_FOUND) _checkUint64Property (inst, "n64", 64); if (inst.findProperty ("n16") != PEG_NOT_FOUND) _checkUint16Property (inst, "n16", 16); } } } } catch (const Exception & e) { cerr << "test failed: " << e.getMessage () << endl; exit (-1); } }
Boolean _propertyIdentical( const char* propertyName, CIMInstance& instance1, CIMInstance& instance2) { Uint32 pos = instance1.findProperty(propertyName); CIMConstProperty p1 = instance1.getProperty(pos); pos = instance2.findProperty(propertyName); CIMConstProperty p2 = instance2.getProperty(pos); return (p1.identical(p2)); }
void testUserContextRequestor() { try { CIMClient client; client.connectLocal(); // Determine whether the CIM Server has authentication enabled CIMObjectPath authConfigInstName = CIMObjectPath( "PG_ConfigSetting.PropertyName=\"enableAuthentication\""); CIMInstance authConfigInst = client.getInstance("root/PG_Internal", authConfigInstName); String authConfigValue; authConfigInst.getProperty(authConfigInst.findProperty("CurrentValue")) .getValue().get(authConfigValue); Boolean authenticationEnabled = String::equalNoCase(authConfigValue, "true"); // Test a provider running in Requestor user context CIMObjectPath instName = CIMObjectPath("TST_UserContextRequestor.Id=1"); CIMInstance cimInstance = client.getInstance(NAMESPACE, instName); String userContext; cimInstance.getProperty(cimInstance.findProperty("UserContext")) .getValue().get(userContext); if (verbose) { cout << "Requestor test: UserContext = " << userContext << endl; } if (authenticationEnabled) { PEGASUS_TEST_ASSERT(userContext == System::getEffectiveUserName()); } else { PEGASUS_TEST_ASSERT(userContext == serverUserContext); } } catch (Exception& e) { cerr << "Error: " << e.getMessage() << endl; exit(1); } }
static void checkBlocked(CIMInstance &pm) { PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "checkBlocked"); Array<Uint16> operationalStatus; Uint32 pos = pm.findProperty(CIMName ("OperationalStatus")); if(pos == PEG_NOT_FOUND) { PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4, "OperationalStatus not found."); PEG_METHOD_EXIT(); //l10n //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "provider lookup failed."); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( "ProviderManager.ProviderManagerService.PROVIDER_LOOKUP_FAILED", "provider lookup failed.")); } pm.getProperty(pos).getValue().get(operationalStatus); for(Uint32 i = 0; i < operationalStatus.size(); i++) { if(operationalStatus[i] == _MODULE_STOPPED || operationalStatus[i] == _MODULE_STOPPING) { PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4, "Provider blocked."); PEG_METHOD_EXIT(); //l10n //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ACCESS_DENIED, "provider blocked."); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED, MessageLoaderParms( "ProviderManager.ProviderManagerService.PROVIDER_BLOCKED", "provider blocked.")); } } }
void setPropertyValue(CIMInstance& instance, const CIMName& propertyName, const Uint32 value) { Uint32 pos; PEGASUS_ASSERT(pos = instance.findProperty(propertyName) != PEG_NOT_FOUND); instance.getProperty(pos).setValue(CIMValue(value)); }
void _checkUint32Property (CIMInstance & instance, const String & name, Uint32 value) { Uint32 pos = instance.findProperty (name); PEGASUS_ASSERT (pos != PEG_NOT_FOUND); CIMProperty theProperty = instance.getProperty (pos); CIMValue theValue = theProperty.getValue (); PEGASUS_ASSERT (theValue.getType () == CIMTYPE_UINT32); PEGASUS_ASSERT (!theValue.isArray ()); PEGASUS_ASSERT (!theValue.isNull ()); Uint32 result; theValue.get (result); if (verbose) { if (result != value) { cerr << "Property value comparison failed. "; cerr << "Expected " << value << "; "; cerr << "Actual property value was " << result << "." << endl; } } PEGASUS_ASSERT (result == value); }
void _checkUint64Property (CIMInstance & instance, const String & name, Uint64 value) { Uint32 pos = instance.findProperty (name); PEGASUS_ASSERT (pos != PEG_NOT_FOUND); CIMProperty theProperty = instance.getProperty (pos); CIMValue theValue = theProperty.getValue (); PEGASUS_ASSERT (theValue.getType () == CIMTYPE_UINT64); PEGASUS_ASSERT (!theValue.isArray ()); PEGASUS_ASSERT (!theValue.isNull ()); Uint64 result; theValue.get (result); if (verbose) { if (result != value) { char buffer[32]; // Should need 21 chars max sprintf (buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", value); cerr << "Property value comparison failed. "; cerr << "Expected " << buffer << "; "; sprintf (buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", result); cerr << "Actual property value was " << buffer << "." << endl; } } PEGASUS_ASSERT (result == value); }
void testUserContextPrivileged() { try { CIMClient client; client.connectLocal(); // Test a provider running in Privileged user context CIMObjectPath instName = CIMObjectPath("TST_UserContextPrivileged.Id=1"); // ATTN: use of the localOnly flag is deprecated, but nor reliably // applied by the CIMOM. An explicit parameter is required for now. CIMInstance cimInstance = client.getInstance(NAMESPACE, instName, false); String userContext; cimInstance.getProperty(cimInstance.findProperty("UserContext")) .getValue().get(userContext); if (verbose) { cout << "Privileged test: UserContext = " << userContext << endl; } PEGASUS_TEST_ASSERT(userContext == testUserContext); } catch (Exception& e) { cerr << "Error: " << e.getMessage() << endl; exit(1); } }
/* Return the value in a property. If the property cannot be found, return false */ Boolean _getPropertyValue(const CIMInstance& inst, const CIMName name, CIMValue& val) { #ifdef ENABLE_LOCAL_DIAGNOSTICS DCOUT << "Instance from which to retrieve " << inst.getClassName().getString() << " propertyName " << name.getString() << endl; #endif unsigned int pos = inst.findProperty(name); if (pos==PEG_NOT_FOUND) { #ifdef ENABLE_LOCAL_DIAGNOSTICS DCOUT << "property " << name.getString() << " pos " << pos << " NOT found" << endl; #endif return false; } #ifdef ENABLE_LOCAL_DIAGNOSTICS DCOUT << "property " << name.getString() << " FOUND" << endl; #endif val=inst.getProperty(pos).getValue(); return true; }
CIMValue CIMHelper::getPropertyValue(const CIMInstance &instanceObject, String name) { CIMName cname(name); Uint32 index = instanceObject.findProperty(cname); if (index == PEG_NOT_FOUND) return CIMValue(); CIMConstProperty property = instanceObject.getProperty(index); return property.getValue(); }
void getPropertiesFromCIMServer( CIMClient& client, const CIMName& propName, Array <String>& propValues) { CIMProperty prop; Array<CIMKeyBinding> kbArray; CIMKeyBinding kb; String _hostName; kb.setName(PROPERTY_NAME); kb.setValue(propName.getString()); kb.setType(CIMKeyBinding::STRING); _hostName.assign(System::getHostName()); kbArray.append(kb); CIMObjectPath reference(_hostName, PEGASUS_NAMESPACENAME_CONFIG, PEGASUS_CLASSNAME_CONFIGSETTING, kbArray); CIMInstance cimInstance = client.getInstance(PEGASUS_NAMESPACENAME_CONFIG, reference); Uint32 pos = cimInstance.findProperty(PROPERTY_NAME); prop = (CIMProperty)cimInstance.getProperty(pos); propValues.append(prop.getValue().toString()); pos = cimInstance.findProperty(DEFAULT_VALUE); prop = (CIMProperty)cimInstance.getProperty(pos); propValues.append(prop.getValue().toString()); pos = cimInstance.findProperty(CURRENT_VALUE); prop = (CIMProperty)cimInstance.getProperty(pos); propValues.append(prop.getValue().toString()); pos = cimInstance.findProperty(PLANNED_VALUE); prop = (CIMProperty)cimInstance.getProperty(pos); propValues.append(prop.getValue().toString()); pos = cimInstance.findProperty(DYNAMIC_PROPERTY); prop = (CIMProperty)cimInstance.getProperty(pos); propValues.append(prop.getValue().toString()); }
void _testPropertyValue( CIMInstance& instance, const CIMName& propertyName, const CIMValue & testValue) { CIMValue value = instance.getProperty(instance.findProperty(propertyName)).getValue(); PEGASUS_TEST_ASSERT(testValue == value); }
ProviderName ProviderRegistrar::findConsumerProvider(const String & destinationPath) { CIMInstance provider; CIMInstance providerModule; ProviderName temp; if (_prm->lookupIndicationConsumer(destinationPath,provider,providerModule)) return ProviderName( provider.getProperty(provider.findProperty ("Name")).getValue ().toString (), providerModule.getProperty(providerModule.findProperty ("Location")).getValue().toString(), providerModule.getProperty(providerModule.findProperty ("InterfaceType")).getValue().toString(), 0); return temp; }
static Boolean _checkValue( CIMInstance &instance, const String &prop, T value) { T lvalue; instance.getProperty(instance.findProperty(prop)).getValue().get(lvalue); return lvalue == value; }
void InstanceProvider::createInstance( const OperationContext & context, const CIMObjectPath & instanceReference, const CIMInstance & instanceObject, ObjectPathResponseHandler & handler) { // Validate the class name if (!instanceObject.getClassName().equal("Sample_InstanceProviderClass")) { throw CIMNotSupportedException( instanceObject.getClassName().getString()); } // Find the key property Uint32 idIndex = instanceObject.findProperty("Identifier"); if (idIndex == PEG_NOT_FOUND) { throw CIMInvalidParameterException("Missing key value"); } CIMInstance cimInstance = instanceObject.clone(); // Create the new instance name CIMValue idValue = instanceObject.getProperty(idIndex).getValue(); Array<CIMKeyBinding> keys; keys.append(CIMKeyBinding("Identifier", idValue)); CIMObjectPath instanceName = CIMObjectPath( String(), CIMNamespaceName(), instanceObject.getClassName(), keys); cimInstance.setPath(instanceName); // Determine whether this instance already exists for(Uint32 i = 0, n = _instances.size(); i < n; i++) { if(instanceName == _instances[i].getPath()) { throw CIMObjectAlreadyExistsException(instanceName.toString()); } } // begin processing the request handler.processing(); // add the new instance to the array _instances.append(cimInstance); // deliver the new instance name handler.deliver(instanceName); // complete processing the request handler.complete(); }
Boolean setObjectManagerStatistics(CIMClient & client, Boolean newState) { CIMName gathStatName ("GatherStatisticalData"); Array<CIMInstance> instancesObjectManager; CIMInstance instObjectManager; Uint32 prop_num; Array<CIMName> plA; plA.append(gathStatName); CIMPropertyList statPropertyList(plA); // Create property list that represents correct request // get instance. Get only the gatherstatitistics property instancesObjectManager = client.enumerateInstances(PEGASUS_NAMESPACENAME_INTEROP, "CIM_ObjectManager", true, false, false, false, statPropertyList); PEGASUS_TEST_ASSERT(instancesObjectManager.size() == 1); instObjectManager = instancesObjectManager[0]; // set correct path into instance instObjectManager.setPath(instancesObjectManager[0].getPath()); prop_num = instObjectManager.findProperty(gathStatName); PEGASUS_TEST_ASSERT(prop_num != PEG_NOT_FOUND); instObjectManager.getProperty(prop_num).setValue(CIMValue(newState)); client.modifyInstance(PEGASUS_NAMESPACENAME_INTEROP, instObjectManager, false, statPropertyList); CIMInstance updatedInstance = client.getInstance(PEGASUS_NAMESPACENAME_INTEROP, instObjectManager.getPath(), false, false, false, statPropertyList); prop_num = updatedInstance.findProperty(gathStatName); PEGASUS_TEST_ASSERT(prop_num != PEG_NOT_FOUND); CIMProperty p = updatedInstance.getProperty(prop_num); CIMValue v = p.getValue(); Boolean rtn; v.get(rtn); //// Need to get it again cout << "Updated Status= " << ((rtn)? "true" : "false") << endl; return(rtn); }
bool setPropertyValue(CIMInstance& instance, const CIMName& propertyName, const CIMValue & value) { unsigned int pos = instance.findProperty(propertyName); if(pos != PEG_NOT_FOUND) { instance.getProperty(pos).setValue(value); return true; } return false; }
///////////////////////////////////////////////////////////////////////////// // WMIInstanceProvider::getProperty // // /////////////////////////////////////////////////////////////////////////// CIMValue WMIInstanceProvider::getProperty( const String& nameSpace, const String& userName, const String& password, const CIMObjectPath& instanceName, const String& propertyName) { CIMInstance cimInstance; Array<CIMName> propertyNames; PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMIInstanceProvider::getProperty()"); setup(nameSpace,userName,password); if (!m_bInitialized) { throw CIMException(CIM_ERR_FAILED, "[getProperty] m_bInitialized"); } CIMName propName = propertyName; propertyNames.append(propName); CIMPropertyList propertyList = CIMPropertyList(propertyNames); // get the relevant CIMInstance object cimInstance = getCIMInstance(nameSpace, userName, password, instanceName, propertyList); // now fetch the property Uint32 pos = cimInstance.findProperty(propName); if (PEG_NOT_FOUND == pos) { throw CIMException(CIM_ERR_NO_SUCH_PROPERTY, "[getProperty] findproperty"); } CIMProperty property = cimInstance.getProperty(pos); // and return the value CIMValue value = property.getValue(); PEG_METHOD_EXIT(); return value; }
void CIMError::setInstance(const CIMInstance& instance) { for (Uint32 i = 0; i < instance.getPropertyCount(); i++) { CIMConstProperty p = instance.getProperty(i); _Check("ErrorType", p, (Uint16*)0); _Check("OtherErrorType", p, (String*)0); _Check("OwningEntity", p, (String*)0); _Check("MessageID", p, (String*)0); _Check("Message", p, (String*)0); _Check("MessageArguments", p, (Array<String>*)0); _Check("PerceivedSeverity", p, (Uint16*)0); _Check("ProbableCause", p, (Uint16*)0); _Check("ProbableCauseDescription", p, (String*)0); _Check("RecommendedActions", p, (Array<String>*)0); _Check("ErrorSource", p, (String*)0); _Check("ErrorSourceFormat", p, (Uint16*)0); _Check("OtherErrorSourceFormat", p, (String*)0); _Check("CIMStatusCode", p, (Uint32*)0); _Check("CIMStatusCodeDescription", p, (String*)0); } // Verify that the instance contains all of the required properties. for (Uint32 i = 0; i < _numRequiredProperties; i++) { // Does inst have this property? Uint32 pos = instance.findProperty(_requiredProperties[i]); if (pos == PEG_NOT_FOUND) { char buffer[80]; sprintf(buffer, "required property does not exist: %s", _requiredProperties[i]); throw CIMException(CIM_ERR_NO_SUCH_PROPERTY, buffer); } // is required property non-null? CIMConstProperty p = instance.getProperty(pos); CIMValue v = p.getValue(); if (v.isNull()) { char buffer[80]; sprintf(buffer, "required property MUST NOT be Null: %s", _requiredProperties[i]); throw CIMException(CIM_ERR_FAILED, buffer); } } _inst = instance; }
static CIMValue _getPropertyValue(const CIMInstance & cimInstance, const String & propertyName) { CIMValue value; Uint32 pos = 0; // get ClassName property if((pos = cimInstance.findProperty(propertyName)) != PEG_NOT_FOUND) { value = cimInstance.getProperty(pos).getValue(); } return(value); }
void _getKeyValue ( const CIMInstance& namespaceInstance, CIMNamespaceName& childNamespaceName, Boolean& isRelativeName) { //Validate key property Uint32 pos; CIMValue propertyValue; // [Key, MaxLen (256), Description ( // "A string that uniquely identifies the Namespace " // "within the ObjectManager.") ] // string Name; pos = namespaceInstance.findProperty(NAMESPACE_PROPERTYNAME); if (pos == PEG_NOT_FOUND) { throw CIMPropertyNotFoundException (NAMESPACE_PROPERTYNAME.getString()); } propertyValue = namespaceInstance.getProperty(pos).getValue(); if (propertyValue.getType() != CIMTYPE_STRING) { //l10n //throw CIMInvalidParameterException("Invalid type for property: " //+ NAMESPACE_PROPERTYNAME.getString()); throw CIMInvalidParameterException(MessageLoaderParms( "ControlProviders.NamespaceProvider.NamespaceProvider.INVALID_TYPE_FOR_PROPERTY", "Invalid type for property: $0", NAMESPACE_PROPERTYNAME.getString())); } String cnsName; propertyValue.get(cnsName); if (cnsName == String::EMPTY) { childNamespaceName = CIMNamespaceName(); } else { childNamespaceName = CIMNamespaceName(cnsName); } isRelativeName = !(childNamespaceName.isNull()); }
void _testDeliveryRetryIntervalValue( CIMInstance& instance) { CIMValue value = instance.getProperty( instance.findProperty( _PROPERTY_DELIVERYRETRYINTERVAL)).getValue(); if (value.getType() == CIMTYPE_UINT64) { // CIM Schema 2.17 experimental class PEGASUS_TEST_ASSERT( Uint64(_PROPERTY_DELIVERYRETRYINTERVAL_VALUE) == value); } else { // CIM Schema 2.22 and up PEGASUS_TEST_ASSERT(_PROPERTY_DELIVERYRETRYINTERVAL_VALUE == value); } }
void testUserContextDesignated() { try { if (!System::isSystemUser(alternateUserContext)) { cout << " Skipping Designated UserContext test -- User \"" << alternateUserContext << "\" is not configured on this system." << endl; return; } CIMClient client; client.connectLocal(); // Test a provider running in Designated user context CIMObjectPath instName = CIMObjectPath("TST_UserContextDesignated.Id=1"); // ATTN: use of the localOnly flag is deprecated, but nor reliably // applied by the CIMOM. An explicit parameter is required for now. CIMInstance cimInstance = client.getInstance(NAMESPACE, instName, false); String userContext; cimInstance.getProperty(cimInstance.findProperty("UserContext")) .getValue().get(userContext); if (verbose) { cout << "Designated test: UserContext = " << userContext << endl; } PEGASUS_TEST_ASSERT(userContext == String(alternateUserContext)); } catch (Exception& e) { cerr << "Error: " << e.getMessage() << endl; exit(1); } }
void _testSubscriptionRemovalIntervalValue( CIMInstance& instance) { CIMValue value = instance.getProperty( instance.findProperty( _PROPERTY_SUBSCRIPTIONREMOVALTIMEINTERVAL)).getValue(); if (value.getType() == CIMTYPE_UINT64) { // CIM Schema 2.17 experimental class PEGASUS_TEST_ASSERT( Uint64(_PROPERTY_SUBSCRIPTIONREMOVALTIMEINTERVAL_VALUE) == value); } else { // CIM Schema 2.22 and up PEGASUS_TEST_ASSERT( _PROPERTY_SUBSCRIPTIONREMOVALTIMEINTERVAL_VALUE == value); } }
void testGetInstance(CIMClient& client, const char* ns) { CIMInstance instance; Array<CIMKeyBinding> keyBindings; keyBindings.append(CIMKeyBinding(PROPERTY_NAME_INSTANCEID, INSTANCEID_VALUE, CIMKeyBinding::STRING)); CIMObjectPath objectPath(String::EMPTY, ns, CIM_QUERYCAPCLASS_NAME, keyBindings); instance = client.getInstance(ns, objectPath, false); Array<Uint16> providerReturnedVal; Uint32 prop = instance.findProperty(CIMName(PROPERTY_NAME_CQLFEATURES)); instance.getProperty(prop).getValue().get(providerReturnedVal); _checkIfReturnedValueIsCorrect(providerReturnedVal); }
int main(const int argc, const char **argv) { // output looks like: // PG_OperatingSystem /// Namespaces: root/cimv2 // Provider: PG_OperatingSystemProvider // Type: Instance // Module: OperatingSystemModule // File: libOSProvider.sl _c.setTimeout(PEGASUS_DEFAULT_CLIENT_TIMEOUT_MILLISECONDS); // everything in big try/catch to display errors try { _c.connectLocal(); // Start by enumerating PG_ProviderCapabilities Array<CIMObjectPath> capRef = _c.enumerateInstanceNames(PEGASUS_NAMESPACENAME_INTEROP, "PG_ProviderCapabilities"); for (int i=0; i<capRef.size(); i++) { // get the instance CIMInstance cap = _c.getInstance(PEGASUS_NAMESPACENAME_INTEROP,capRef[i]); // get referenced instance of PG_ProviderModule for later use String pMod; cap.getProperty( cap.findProperty("ProviderModuleName")).getValue().get(pMod); CIMObjectPath modRef(String("PG_ProviderModule.Name=\"") + pMod + "\""); CIMInstance mod = _c.getInstance(PEGASUS_NAMESPACENAME_INTEROP,modRef); // display name of class instrumented String className; cap.getProperty(cap.findProperty("ClassName")).getValue().get(className); cout << endl << className << endl; // display namespaces Array<String> nameSpaces; cap.getProperty( cap.findProperty("Namespaces")).getValue().get(nameSpaces); cout << " Namespaces:"; for (int j=0; j<nameSpaces.size(); j++) cout << " " << nameSpaces[j]; cout << endl; // display name of provider String pName; cap.getProperty(cap.findProperty("ProviderName")).getValue().get(pName); cout << " Provider: " << pName << endl; // display type of provider Array<Uint16> pType; cap.getProperty(cap.findProperty("ProviderType")).getValue().get(pType); cout << " Type: "; for (int j=0; j<pType.size(); j++) cout << " " << _providerType[ pType[j] ]; cout << endl; // display state Array<Uint16> state; mod.getProperty( mod.findProperty("OperationalStatus")).getValue().get(state); cout << " State: "; for (int j=0; j<state.size(); j++) cout << " " << _providerState[ state[j] ]; cout << endl; // display module cout << " Module: " << pMod << endl; // display file (PG_ProviderModule.Location) String loc; mod.getProperty(mod.findProperty("Location")).getValue().get(loc); cout << " File: lib" << loc << ".sl" << endl; } } catch (Exception &e) { cerr << e.getMessage() << endl; return 1; } return 0; }
// l10n - note: ignoring indication language void snmpIndicationHandler::handleIndication( const OperationContext& context, const String nameSpace, CIMInstance& indication, CIMInstance& handler, CIMInstance& subscription, ContentLanguageList & contentLanguages) { Array<String> propOIDs; Array<String> propTYPEs; Array<String> propVALUEs; Array<String> mapStr; PEG_METHOD_ENTER(TRC_IND_HANDLER, "snmpIndicationHandler::handleIndication"); try { PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4, "snmpIndicationHandler %s:%s.%s processing %s Indication", (const char*)(nameSpace.getCString()), (const char*)(handler.getClassName().getString().getCString()), (const char*)(handler.getProperty( handler.findProperty(PEGASUS_PROPERTYNAME_NAME)). getValue().toString().getCString()), (const char*)(indication.getClassName().getString(). getCString()))); CIMClass indicationClass = _repository->getClass( nameSpace, indication.getClassName(), false, true, false, CIMPropertyList()); Uint32 propertyCount = indication.getPropertyCount(); for (Uint32 i=0; i < propertyCount; i++) { CIMProperty prop = indication.getProperty(i); Uint32 propDeclPos = indicationClass.findProperty(prop.getName()); if (propDeclPos != PEG_NOT_FOUND) { CIMProperty propDecl = indicationClass.getProperty(propDeclPos); Uint32 qualifierPos = propDecl.findQualifier(CIMName("MappingStrings")); if (qualifierPos != PEG_NOT_FOUND) { // // We are looking for following fields: // MappingStrings {"OID.IETF | SNMP." oidStr, // "DataType.IETF |" dataType} // oidStr is the object identifier (e.g. "1.3.6.1.2.1.5..." // dataType is either Integer, or OctetString, // or OID // Following is one example: // MappingStrings {"OID.IETF | SNMP.1.3.6.6.3.1.1.5.2", // "DataType.IETF | Integer"} // propDecl.getQualifier(qualifierPos).getValue().get( mapStr); String oidStr, dataType; String mapStr1, mapStr2; Boolean isValidAuthority = false; Boolean isValidDataType = false; for (Uint32 j=0; j < mapStr.size(); j++) { Uint32 barPos = mapStr[j].find("|"); if (barPos != PEG_NOT_FOUND) { mapStr1 = mapStr[j].subString(0, barPos); mapStr2 = mapStr[j].subString(barPos + 1); _trimWhitespace(mapStr1); _trimWhitespace(mapStr2); if ((mapStr1 == "OID.IETF") && (String::compare(mapStr2, String("SNMP."), 5) == 0)) { isValidAuthority = true; oidStr = mapStr2.subString(5); } else if (mapStr1 == "DataType.IETF") { isValidDataType = true; dataType = mapStr2; } if (isValidAuthority && isValidDataType) { propOIDs.append(oidStr); propTYPEs.append(dataType); propVALUEs.append(prop.getValue().toString()); break; } } } } } } // Collected complete data in arrays and ready to send the trap. // trap destination and SNMP type are defined in handlerInstance // and passing this instance as it is to deliverTrap() call Uint32 targetHostPos = handler.findProperty(CIMName("TargetHost")); Uint32 targetHostFormatPos = handler.findProperty(CIMName("TargetHostFormat")); Uint32 otherTargetHostFormatPos = handler.findProperty(CIMName("OtherTargetHostFormat")); Uint32 portNumberPos = handler.findProperty(CIMName("PortNumber")); Uint32 snmpVersionPos = handler.findProperty(CIMName("SNMPVersion")); Uint32 securityNamePos = handler.findProperty(CIMName("SNMPSecurityName")); Uint32 engineIDPos = handler.findProperty(CIMName("SNMPEngineID")); Uint32 snmpSecLevelPos = handler.findProperty(CIMName("SNMPSecurityLevel")); Uint32 snmpSecAuthProtoPos = handler.findProperty(CIMName("SNMPSecurityAuthProtocol")); Uint32 snmpSecAuthKeyPos = handler.findProperty(CIMName("SNMPSecurityAuthKey")); Uint32 snmpSecPrivProtoPos = handler.findProperty(CIMName("SNMPSecurityPrivProtocol")); Uint32 snmpSecPrivKeyPos = handler.findProperty(CIMName("SNMPSecurityPrivKey")); if (targetHostPos == PEG_NOT_FOUND) { PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1, "Target host is not set for IndicationHandlerSNMPMapper %s" " Indication.", (const char*)(indication.getClassName().getString(). getCString()))); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( "Handler.snmpIndicationHandler.snmpIndicationHandler." "INVALID_SNMP_INSTANCE", "Invalid IndicationHandlerSNMPMapper instance")); } if (targetHostFormatPos == PEG_NOT_FOUND) { PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1, "Target host format is not set for IndicationHandlerSNMPMapper" " %s Indication.", (const char*)(indication.getClassName().getString(). getCString()))); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( "Handler.snmpIndicationHandler.snmpIndicationHandler." "INVALID_SNMP_INSTANCE", "Invalid IndicationHandlerSNMPMapper instance")); } if (snmpVersionPos == PEG_NOT_FOUND) { PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1, "SNMP Version is not set for IndicationHandlerSNMPMapper %s" " Indication.", (const char*)(indication.getClassName().getString(). getCString()))); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( "Handler.snmpIndicationHandler.snmpIndicationHandler." "INVALID_SNMP_INSTANCE", "Invalid IndicationHandlerSNMPMapper instance")); } else { // properties from the handler instance String targetHost; String otherTargetHostFormat = String(); String securityName = String(); String engineID = String(); Uint16 targetHostFormat = 0; Uint16 snmpVersion = 0; Uint32 portNumber; Uint8 snmpSecLevel = 1; // noAuthnoPriv Uint8 snmpSecAuthProto = 0; Array<Uint8> snmpSecAuthKey;// no key Uint8 snmpSecPrivProto = 0; Array<Uint8> snmpSecPrivKey ;// no key String trapOid; Boolean trapOidAvailable = false; // // Get snmpTrapOid from context // if (context.contains(SnmpTrapOidContainer::NAME)) { SnmpTrapOidContainer trapContainer = context.get(SnmpTrapOidContainer::NAME); trapOid = trapContainer.getSnmpTrapOid(); trapOidAvailable = true; } else { // get trapOid from indication Class Uint32 pos = indicationClass.findQualifier(CIMName("MappingStrings")); if (pos != PEG_NOT_FOUND) { Array<String> classMapStr; indicationClass.getQualifier(pos).getValue(). get(classMapStr); for (Uint32 i=0; i < classMapStr.size(); i++) { Uint32 barPos = classMapStr[i].find("|"); if (barPos != PEG_NOT_FOUND) { String authorityName = classMapStr[i].subString(0, barPos); String oidStr = classMapStr[i].subString( barPos+1, PEG_NOT_FOUND); _trimWhitespace(authorityName); _trimWhitespace(oidStr); if ((authorityName == "OID.IETF") && (String::compare(oidStr, String("SNMP."), 5) == 0)) { trapOid = oidStr.subString(5); trapOidAvailable = true; break; } } } if (!trapOidAvailable) { PEG_TRACE(( TRC_IND_HANDLER, Tracer::LEVEL1, "No MappingStrings for snmp trap is specified " "for class: %s", (const char*) indication.getClassName().getString().getCString() )); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L( CIM_ERR_FAILED, MessageLoaderParms( "Handler.snmpIndicationHandler." "snmpIndicationHandler.NO_MS_FOR_SNMP_TRAP", "No MappingStrings for snmp trap is specified " "for class: $0", indication.getClassName().getString())); } } else { PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1, "Qualifier MappingStrings can not be found."); PEG_METHOD_EXIT(); MessageLoaderParms parms( "Handler.snmpIndicationHandler.snmpIndicationHandler." "QUALIFIER_MAPPINGS_NOT_FOUND", "Qualifier MappingStrings can not be found"); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, parms); } } handler.getProperty(targetHostPos).getValue().get(targetHost); handler.getProperty(targetHostFormatPos).getValue().get( targetHostFormat); if (otherTargetHostFormatPos != PEG_NOT_FOUND) { handler.getProperty(otherTargetHostFormatPos).getValue().get( otherTargetHostFormat); } if (portNumberPos != PEG_NOT_FOUND) { handler.getProperty(portNumberPos).getValue().get(portNumber); } else { // default port portNumber = SNMP_TRAP_DEFAULT_PORT; } handler.getProperty(snmpVersionPos).getValue().get(snmpVersion); if (securityNamePos != PEG_NOT_FOUND) { handler.getProperty(securityNamePos).getValue().get( securityName); } if (engineIDPos != PEG_NOT_FOUND) { handler.getProperty(engineIDPos).getValue().get(engineID); } if(snmpVersion == 5) // SNMPv3 Trap { //fetch the security data if(snmpSecLevelPos != PEG_NOT_FOUND) { handler.getProperty(snmpSecLevelPos).getValue(). \ get(snmpSecLevel); } if(snmpSecAuthProtoPos != PEG_NOT_FOUND) { handler.getProperty(snmpSecAuthProtoPos).getValue(). \ get(snmpSecAuthProto); } if(snmpSecAuthKeyPos != PEG_NOT_FOUND) { handler.getProperty(snmpSecAuthKeyPos).getValue(). \ get(snmpSecAuthKey); } if(snmpSecPrivProtoPos != PEG_NOT_FOUND) { handler.getProperty(snmpSecPrivProtoPos).getValue(). \ get(snmpSecPrivProto); } if(snmpSecPrivKeyPos!= PEG_NOT_FOUND) { handler.getProperty(snmpSecPrivKeyPos).getValue(). \ get(snmpSecPrivKey); } } PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4, "snmpIndicationHandler sending %s Indication trap %s to target" " host %s target port %d", (const char*)(indication.getClassName().getString(). getCString()), (const char*)(trapOid.getCString()), (const char*)(targetHost.getCString()),portNumber)); _snmpTrapSender->deliverTrap( trapOid, securityName, targetHost, targetHostFormat, otherTargetHostFormat, portNumber, snmpVersion, engineID, snmpSecLevel, snmpSecAuthProto, snmpSecAuthKey, snmpSecPrivProto, snmpSecPrivKey, propOIDs, propTYPEs, propVALUEs); PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4, "%s Indication trap %s sent to target host %s target port %d " "successfully", (const char*)(indication.getClassName().getString().getCString()), (const char*)(trapOid.getCString()), (const char*)(targetHost.getCString()),portNumber)); } } catch (CIMException& c) { PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1, "CIMException %s", (const char*)c.getMessage().getCString())); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, c.getMessage()); } catch (Exception& e) { PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1, "Exception %s", (const char*)e.getMessage().getCString())); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage()); } catch (...) { PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1, "Failed to deliver trap."); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( "Handler.snmpIndicationHandler.snmpIndicationHandler." "FAILED_TO_DELIVER_TRAP", "Failed to deliver trap.")); } PEG_METHOD_EXIT(); }
void FileListenerDestination::handleIndication( const OperationContext& context, const String nameSpace, CIMInstance& indication, CIMInstance& handler, CIMInstance& subscription, ContentLanguageList& contentLanguages) { PEG_METHOD_ENTER(TRC_IND_HANDLER, "FileListenerDestination::handleIndication"); String indicationText; try { PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4, "FileListenerDestination %s:%s.%s processing %s Indication", (const char*)(nameSpace.getCString()), (const char*)(handler.getClassName().getString().getCString()), (const char*)(handler.getProperty( handler.findProperty(PEGASUS_PROPERTYNAME_LSTNRDST_FILE)). getValue().toString().getCString()), (const char*)(indication.getClassName().getString(). getCString()))); // gets formatted indication message indicationText = IndicationFormatter::getFormattedIndText( subscription, indication, contentLanguages); String filePath; handler.getProperty(handler.findProperty( PEGASUS_PROPERTYNAME_LSTNRDST_FILE)). getValue().get(filePath); PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4, "FileListenerDestination writing %s Indication to file %s", (const char*)(indication.getClassName().getString().getCString()), (const char*)filePath.getCString())); // writes the indication to a file _recordIndicationToFile( (const char*)filePath.getCString(), indicationText); } catch(const Exception&e) { PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1, "Exception: %s", (const char*)e.getMessage().getCString())); PEG_METHOD_EXIT(); throw; } catch (...) { PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1, "Failed to write indication to local file."); PEG_METHOD_EXIT(); throw; } PEG_METHOD_EXIT(); }
// Tests PROPERTY as an embedded object. static void testGetInstanceElement(const char* testDataFile) { //-------------------------------------------------------------------------- // Read in instance //-------------------------------------------------------------------------- CIMInstance cimInstance; Buffer text; FileSystem::loadFileToMemory(text, testDataFile); XmlParser parser((char*)text.getData()); XmlReader::getInstanceElement(parser, cimInstance); PEGASUS_TEST_ASSERT( cimInstance.getClassName() == CIMName("CIM_InstCreation")); Uint32 idx; CIMProperty cimProperty; CIMValue cimValue; CIMType cimType; PEGASUS_TEST_ASSERT(cimInstance.getPropertyCount() == 3); idx = cimInstance.findProperty(CIMName("IndicationIdentifier")); PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND); cimProperty = cimInstance.getProperty(idx); cimValue = cimProperty.getValue(); cimType = cimProperty.getType(); PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "string") == 0); String myString; cimValue.get(myString); PEGASUS_TEST_ASSERT(strcmp(myString.getCString(), "0") == 0); idx = cimInstance.findProperty(CIMName("IndicationTime")); PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND); cimProperty = cimInstance.getProperty(idx); cimValue = cimProperty.getValue(); cimType = cimProperty.getType(); PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "datetime") == 0); CIMDateTime myDateTime; cimValue.get(myDateTime); PEGASUS_TEST_ASSERT(myDateTime.equal( CIMDateTime("20050227225624.524000-300"))); idx = cimInstance.findProperty(CIMName("SourceInstance")); PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND); cimProperty = cimInstance.getProperty(idx); cimValue = cimProperty.getValue(); cimType = cimProperty.getType(); PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "object") == 0); CIMObject cimObject; cimValue.get(cimObject); PEGASUS_TEST_ASSERT( cimObject.getClassName() == CIMName("Sample_LifecycleIndicationProviderClass")); PEGASUS_TEST_ASSERT(cimObject.getPropertyCount() == 2); idx = cimObject.findProperty(CIMName("uniqueId")); PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND); cimProperty = cimObject.getProperty(idx); cimValue = cimProperty.getValue(); cimType = cimProperty.getType(); PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "uint32") == 0); Uint32 myUint32; cimValue.get(myUint32); PEGASUS_TEST_ASSERT(myUint32 == 1); idx = cimObject.findProperty(CIMName("lastOp")); PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND); cimProperty = cimObject.getProperty(idx); cimValue = cimProperty.getValue(); cimType = cimProperty.getType(); PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "string") == 0); cimValue.get(myString); PEGASUS_TEST_ASSERT(strcmp(myString.getCString(), "createInstance") == 0); }
// Tests PROPERTY.ARRAY as an embedded object with array type. static void testGetInstanceElement2(const char* testDataFile) { CIMInstance cimInstance; Buffer text; FileSystem::loadFileToMemory(text, testDataFile); XmlParser parser((char*)text.getData()); XmlReader::getInstanceElement(parser, cimInstance); PEGASUS_TEST_ASSERT(cimInstance.getClassName() == CIMName("CIM_InstCreation")); Uint32 idx; CIMProperty cimProperty; CIMValue cimValue; CIMType cimType; PEGASUS_TEST_ASSERT(cimInstance.getPropertyCount() == 3); idx = cimInstance.findProperty(CIMName("IndicationIdentifier")); PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND); cimProperty = cimInstance.getProperty(idx); cimValue = cimProperty.getValue(); cimType = cimProperty.getType(); PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "string") == 0); String myString; cimValue.get(myString); PEGASUS_TEST_ASSERT(strcmp(myString.getCString(), "0") == 0); idx = cimInstance.findProperty(CIMName("IndicationTime")); PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND); cimProperty = cimInstance.getProperty(idx); cimValue = cimProperty.getValue(); cimType = cimProperty.getType(); PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "datetime") == 0); CIMDateTime myDateTime; cimValue.get(myDateTime); PEGASUS_TEST_ASSERT(myDateTime.equal( CIMDateTime("20050227225624.524000-300"))); idx = cimInstance.findProperty(CIMName("SourceInstance")); PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND); cimProperty = cimInstance.getProperty(idx); cimValue = cimProperty.getValue(); cimType = cimProperty.getType(); PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "object") == 0); Array<CIMObject> cimObject; cimValue.get(cimObject); PEGASUS_TEST_ASSERT(cimObject.size() == 2); for (idx = 0; idx < cimObject.size(); idx++) { CIMInstance cimInstanceElement(cimObject[idx]); PEGASUS_TEST_ASSERT(cimInstanceElement.getPropertyCount() == 2); Uint32 propIdx = cimInstanceElement.findProperty(CIMName("uniqueId")); if (propIdx != PEG_NOT_FOUND) { CIMProperty nestedProperty = cimInstanceElement.getProperty(propIdx); cimValue = nestedProperty.getValue(); Uint32 uniqueId; cimValue.get(uniqueId); propIdx = cimInstanceElement.findProperty(CIMName("lastOp")); nestedProperty = cimInstanceElement.getProperty(propIdx); cimValue = nestedProperty.getValue(); String checkStringValue; cimValue.get(checkStringValue); if (uniqueId == 1) { PEGASUS_TEST_ASSERT(strcmp( checkStringValue.getCString(), "createInstance") == 0); } else if (uniqueId == 2) { PEGASUS_TEST_ASSERT(strcmp( checkStringValue.getCString(), "deleteInstance") == 0); } else { PEGASUS_TEST_ASSERT(false); } } } }