📄 cimsubcommand.cpp
字号:
maxColumnWidth.append(handlerTitle.size()); destinationsFound.append(destinationTitle); maxColumnWidth.append(destinationTitle.size()); } listOutputTable.append(handlersFound); listOutputTable.append(destinationsFound); // // Find handlers in namespaces // for (Uint32 i = 0 ; i < namespaceNames.size() ; i++) { _getHandlerList(handlerName, namespaceNames[i], handlerCreationClass, verbose, instancesFound, handlerTypesFound, maxColumnWidth, listOutputTable, outPrintWriter, errPrintWriter); } if (verbose) { if (listOutputTable[_HANDLER_LIST_NAME_COLUMN].size() > 0 ) { _printHandlersVerbose(instancesFound, handlerTypesFound, listOutputTable, outPrintWriter); } } else { if (listOutputTable[_HANDLER_LIST_NAME_COLUMN].size() > 1 ) { _printColumns(maxColumnWidth, listOutputTable, outPrintWriter); } }}//// get a list of all handlers in a specified namespace//void CIMSubCommand::_getHandlerList( const String& handlerName, const CIMNamespaceName& handlerNamespace, const String& handlerCreationClass, const Boolean verbose, Array<CIMInstance>& instancesFound, Array<Uint32>& handlerTypesFound, Array <Uint32>& maxColumnWidth, Array <ListColumnEntry>& listOutputTable, ostream& outPrintWriter, ostream& errPrintWriter){ Array<CIMObjectPath> handlerPaths; try { handlerPaths = _client->enumerateInstanceNames( handlerNamespace, PEGASUS_CLASSNAME_LSTNRDST); } catch(CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_CLASS) { return; } else { throw; } } Uint32 handlerCount = handlerPaths.size(); if (handlerCount > 0) { String handlerNameValue; String destination; String creationClassValue; // List all the indication handlers for (Uint32 i = 0; i < handlerCount; i++) { Boolean isMatch = true; CIMObjectPath handlerPath; CIMObjectPath hPath = handlerPaths[i]; Array<CIMKeyBinding> keys = hPath.getKeyBindings(); for(Uint32 j=0; j < keys.size(); j++) { if(keys[j].getName().equal(PEGASUS_PROPERTYNAME_NAME)) { handlerNameValue = keys[j].getValue(); } if(keys[j].getName().equal(PEGASUS_PROPERTYNAME_CREATIONCLASSNAME)) { creationClassValue = keys[j].getValue(); } } if (handlerName != String::EMPTY) { if (handlerNameValue == handlerName) { if (handlerCreationClass != String::EMPTY) { if (handlerCreationClass != creationClassValue) { isMatch = false; } } } else { isMatch = false; } } if (isMatch) { handlerPath = hPath; CIMInstance handlerInstance = _client->getInstance( handlerNamespace, handlerPath); Uint32 handlerType = _HANDLER_CIMXML; _getHandlerDestination(handlerInstance, creationClassValue, handlerType, destination); String handlerString = handlerNamespace.getString(); handlerString.append(DELIMITER_NAMESPACE); handlerString.append(creationClassValue); handlerString.append(DELIMITER_HANDLER_CLASS); handlerString.append(handlerNameValue); listOutputTable[_HANDLER_LIST_NAME_COLUMN].append(handlerString); listOutputTable[_HANDLER_LIST_DESTINATION_COLUMN].append(destination); handlerTypesFound.append(handlerType); if (verbose) { instancesFound.append(handlerInstance); } else { if (handlerString.size() > maxColumnWidth[_HANDLER_LIST_NAME_COLUMN]) { maxColumnWidth[_HANDLER_LIST_NAME_COLUMN] = handlerString.size(); } if (destination.size() > maxColumnWidth[_HANDLER_LIST_DESTINATION_COLUMN]) { maxColumnWidth[_HANDLER_LIST_DESTINATION_COLUMN] = destination.size(); } } } } }}//// print a verbose list of Handlers//void CIMSubCommand::_printHandlersVerbose( const Array<CIMInstance>& instancesFound, const Array<Uint32>& handlerTypesFound, const Array <ListColumnEntry>& listOutputTable, ostream& outPrintWriter){ Uint32 maxEntries = listOutputTable[_HANDLER_LIST_NAME_COLUMN].size(); Array <Uint32> indexes; for (Uint32 i = 0; i < maxEntries; i++) { indexes.append (i); } _bubbleIndexSort (listOutputTable[_HANDLER_LIST_NAME_COLUMN], 0, indexes); for (Uint32 i = 0; i < maxEntries; i++) { Uint32 pos; CIMInstance handlerInstance = instancesFound[indexes[i]]; outPrintWriter << "Handler: " << (listOutputTable[_HANDLER_LIST_NAME_COLUMN])[indexes[i]] << endl; switch (handlerTypesFound[indexes[i]]) { case _HANDLER_SNMP: { String targetHost = String::EMPTY; pos = handlerInstance.findProperty( PEGASUS_PROPERTYNAME_LSTNRDST_TARGETHOST); if (pos != PEG_NOT_FOUND) { handlerInstance.getProperty(pos).getValue().get (targetHost); } outPrintWriter << "TargetHost: " << targetHost << endl; outPrintWriter << "SNMPVersion: " << _getSnmpVersion(handlerInstance) << endl; break; } case _HANDLER_EMAIL: { String mailCc; String mailTo; String mailSubject; _getEmailInfo(handlerInstance, mailCc, mailTo, mailSubject ); outPrintWriter << "MailTo: " << mailTo << endl; if (mailCc.size() > 0 ) { outPrintWriter << "MailCc: " << mailCc << endl; } if (mailSubject.size() > 0 ) { outPrintWriter << "MailSubject: " << mailSubject << endl; } break; } case _HANDLER_SYSLOG: { break; } case _HANDLER_CIMXML: { outPrintWriter << "Destination: " << (listOutputTable[_HANDLER_LIST_DESTINATION_COLUMN])[indexes[i]] << endl; } } outPrintWriter << "PersistenceType: " << _getPersistenceType(handlerInstance) << endl; outPrintWriter << "-----------------------------------------" << endl; }}//// get a list of all filters in the specified namespace(s)//void CIMSubCommand::_listFilters( const String& filterName, const Boolean verbose, const Array<CIMNamespaceName>& namespaceNames, ostream& outPrintWriter, ostream& errPrintWriter){ Array <Uint32> maxColumnWidth; Array <ListColumnEntry> listOutputTable; Array<String> filtersFound; Array<String> querysFound; Array<String> queryLangsFound; const String filterTitle = "FILTER"; const String queryTitle = "QUERY"; if (!verbose) { filtersFound.append(filterTitle); maxColumnWidth.append(filterTitle.size()); querysFound.append(queryTitle); maxColumnWidth.append(queryTitle.size()); } listOutputTable.append(filtersFound); listOutputTable.append(querysFound); // Find filters in namespaces for (Uint32 i = 0 ; i < namespaceNames.size(); i++) { _getFilterList(filterName, namespaceNames[i], verbose, maxColumnWidth, listOutputTable, queryLangsFound, outPrintWriter, errPrintWriter); } if (verbose) { if (listOutputTable[_FILTER_LIST_NAME_COLUMN].size() > 0) { _printFiltersVerbose(listOutputTable, queryLangsFound, outPrintWriter); } } else { if (listOutputTable[_FILTER_LIST_NAME_COLUMN].size() > 1) { _printColumns(maxColumnWidth, listOutputTable, outPrintWriter); } }}//// get a list of all filters in the specified namespace(s)//void CIMSubCommand::_printFiltersVerbose( const Array <ListColumnEntry>& listOutputTable, const Array <String>& queryLangs, ostream& outPrintWriter){ Uint32 maxEntries = listOutputTable[_FILTER_LIST_NAME_COLUMN].size(); Array <Uint32> indexes; for (Uint32 i = 0; i < maxEntries; i++) { indexes.append(i); } _bubbleIndexSort (listOutputTable[_FILTER_LIST_NAME_COLUMN], 0, indexes); for (Uint32 i = 0; i < maxEntries; i++) { outPrintWriter << "Filter: " << (listOutputTable[_FILTER_LIST_NAME_COLUMN])[indexes[i]] << endl; outPrintWriter << "Query: " << (listOutputTable[_FILTER_LIST_QUERY_COLUMN])[indexes[i]] << endl; outPrintWriter << "Query Language: " << queryLangs[indexes[i]] << endl; outPrintWriter << "-----------------------------------------" << endl; }}//// get a list of all filters in the specified namespace//void CIMSubCommand::_getFilterList( const String& filterName, const CIMNamespaceName& filterNamespace, const Boolean verbose, Array <Uint32>& maxColumnWidth, Array <ListColumnEntry>& listOutputTable, Array <String>& queryLangsFound, ostream& outPrintWriter, ostream& errPrintWriter){ Array<CIMObjectPath> filterPaths; try { filterPaths = _client->enumerateInstanceNames( filterNamespace, PEGASUS_CLASSNAME_INDFILTER); } catch(CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_CLASS) { return; } else { throw; } } Uint32 filterCount = filterPaths.size(); if (filterCount > 0) { CIMObjectPath filterPath; String filterNameValue; // List all the indication filters for (Uint32 i = 0; i < filterCount; i++) { Boolean isMatch = true; CIMObjectPath fPath = filterPaths[i]; Array<CIMKeyBinding> keys = fPath.getKeyBindings(); for(Uint32 j=0; j < keys.size(); j++) { if(keys[j].getName().equal(PEGASUS_PROPERTYNAME_NAME)) { filterNameValue = keys[j].getValue(); filterPath = fPath; if (filterName != String::EMPTY) { if (filterNameValue == filterName) { break; } else { isMatch = false; break; } } else { break; } } } if (isMatch) { String queryString,queryLanguageString; String filterString = filterNamespace.getString(); filterString.append(DELIMITER_NAMESPACE); filterString.append(filterNameValue); _getQueryString(filterNamespace, filterPath, queryString, queryLanguageString); listOutputTable[_FILTER_LIST_NAME_COLUMN].append(filterString); listOutputTable[_FILTER_LIST_QUERY_COLUMN].append(queryString); if (verbose) { queryLangsFound.append(queryLanguageString); } else { if (filterString.size () > maxColumnWidth[_FILTER_LIST_NAME_COLUMN]) { maxColumnWidth[_FILTER_LIST_NAME_COLUMN] = filterString.size(); } if (queryString.size() > maxColumnWidth[_FILTER_LIST_QUERY_COLUMN]) { maxColumnWidth[_FILTER_LIST_QUERY_COLUMN] = queryString.size(); } } } } }}//// get the query string for a filter//void CIMSubCommand::_getQueryString( const CIMNamespaceName& filterNamespace, const CIMObjectPath& filterPath, String& queryString, String& queryLangString){ String query; queryString = "\""; CIMInstance filterInstance
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -