bool cAlarmServer::loadAlarmStringsFile(const UtlString& stringsFile) { OsSysLog::add(FAC_ALARM, PRI_DEBUG, " load alarm strings file %s", stringsFile.data()); TiXmlDocument doc(stringsFile); TiXmlHandle docHandle( &doc ); if (!doc.LoadFile()) { UtlString errorMsg; XmlErrorMsg( doc, errorMsg ); OsSysLog::add(FAC_ALARM, PRI_ERR, "failed to load alarm strings file: %s", errorMsg.data()); return false; } TiXmlHandle docH( &doc ); TiXmlHandle alarmServerHandle = docH.FirstChildElement("alarm_server"); TiXmlElement* settingsElement = alarmServerHandle.FirstChildElement("settings").Element(); if (settingsElement) { //load alarm action strings TiXmlElement* alarmActionsElement = settingsElement->FirstChildElement("actions"); if (alarmActionsElement) { TiXmlElement* element = alarmActionsElement->FirstChildElement("log"); if (mpNotifiers[cAlarmData::eActionLog]) { mpNotifiers[cAlarmData::eActionLog]->initStrings(element); } element = alarmActionsElement->FirstChildElement("email"); if (mpNotifiers[cAlarmData::eActionEmail]) { mpNotifiers[cAlarmData::eActionEmail]->initStrings(element); } element = alarmActionsElement->FirstChildElement("sms"); if (mpNotifiers[cAlarmData::eActionSms]) { mpNotifiers[cAlarmData::eActionSms]->initStrings(element); } /* Not implemented as Strings are not needed for TrapNotifier. element = alarmActionsElement->FirstChildElement("trap"); if (mpNotifiers[cAlarmData::eActionTrap]) { mpNotifiers[cAlarmData::eActionTrap]->initStrings(element); } */ } } else { OsSysLog::add(FAC_ALARM, PRI_DEBUG, "no <settings> element in alarm config file '%s'", stringsFile.data()); } //load alarm description strings TiXmlElement* alarmDefElement = alarmServerHandle. FirstChildElement("definitions").Element(); if (alarmDefElement) { TiXmlElement* element = alarmDefElement->FirstChildElement(); UtlString idStr; UtlString descStr; UtlString resStr; for (; element; element=element->NextSiblingElement() ) { idStr = element->Attribute("id"); if (idStr.isNull()) { OsSysLog::add(FAC_ALARM, PRI_ERR,"Parsing alarm strings file %s: alarm ID is required", stringsFile.data()); continue; } cAlarmData* alarmData = lookupAlarm(idStr); if (!alarmData) { OsSysLog::add(FAC_ALARM, PRI_ERR,"unknown alarm ID %s", idStr.data()); continue; } TiXmlElement* codeElement = element->FirstChildElement("shorttitle"); if (codeElement) { textContentShallow(descStr, codeElement); if (!descStr.isNull()) { UtlString tempStr; XmlUnEscape(tempStr, descStr); alarmData->setShortTitle(tempStr); } } codeElement = element->FirstChildElement("description"); if (codeElement) { textContentShallow(descStr, codeElement); if (!descStr.isNull()) { UtlString tempStr; XmlUnEscape(tempStr, descStr); alarmData->setDescription(tempStr); } } codeElement = element->FirstChildElement("resolution"); if (codeElement) { textContentShallow(resStr, codeElement); if (!resStr.isNull()) { UtlString tempStr; XmlUnEscape(tempStr, resStr); alarmData->setResolution(tempStr); } } } } return true; }
bool SwAdminRpcSnapshot::execute(const HttpRequestContext& requestContext, UtlSList& params, void* userData, XmlRpcResponse& response, ExecutionStatus& status) { bool result = false; status = XmlRpcMethod::FAILED; if (2 != params.entries()) { handleExtraExecuteParam(name(), response, status); } else { if (!params.at(0) || !params.at(0)->isInstanceOf(UtlString::TYPE)) { handleMissingExecuteParam(name(), PARAM_NAME_CALLING_HOST, response, status); } else { UtlString* pCallingHostname = dynamic_cast<UtlString*>(params.at(0)); SipxRpc* pSipxRpcImpl = ((SipxRpc *)userData); if (!params.at(1) || !params.at(1)->isInstanceOf(UtlSList::TYPE)) { handleMissingExecuteParam(name(), PARAM_NAME_COMMAND, response, status); } else { if (validCaller(requestContext, *pCallingHostname, response, *pSipxRpcImpl, name())) { UtlSList* pArgsList = dynamic_cast<UtlSList*>(params.at(1)); UtlSListIterator argsListIterator( *pArgsList ); UtlString * pArg; // Make sure that there is no other instance running. if (! duplicateProcess(SwAdminSnapshot, response, status)) { UtlBool method_result(true); UtlString arguments[pArgsList->entries()+2]; UtlString subCommand; OsPath mWorkingDirectory = "."; OsPath mExec = SipXecsService::Path(SipXecsService::BinDirType, SwAdminSnapshot); UtlString mStdOutFile(SwAdminSnapshot_cmd); UtlString mStdErrFile(SwAdminSnapshot_cmd); mStdOutFile.append(SwAdminStdOut_filetype); mStdErrFile.append(SwAdminStdErr_filetype); // Construct and set the response. OsPath mStdOutPath = OsPath(SipXecsService::Path(SipXecsService::LogDirType, mStdOutFile.data())); OsPath mStdErrPath = OsPath(SipXecsService::Path(SipXecsService::LogDirType, mStdErrFile.data())); OsPath processOutPath = OsPath(SipXecsService::Path(SipXecsService::TmpDirType, OUTPUT_FILENAME)); for (int i = 0; (pArg = dynamic_cast<UtlString*>(argsListIterator())); i++) { XmlUnEscape(arguments[i], *pArg); } arguments[pArgsList->entries()] = processOutPath.data(); arguments[pArgsList->entries()+1] = NULL; // execute the command and return whether or not the launch was successful. OsProcess* swCheck = new OsProcess(); // Setup the Standard Output and Standard Error files. OsPath mStdInFile; // Blank int rc; rc = swCheck->setIORedirect(mStdInFile, mStdOutPath, mStdErrPath); // Launch the process but tell the parent to ignore the child's signals (especially on shutdown). // It will let the system handle it to avoid a defunct process. if ( (rc=swCheck->launch(mExec, &arguments[0], mWorkingDirectory, swCheck->NormalPriorityClass, FALSE, TRUE)) // Parent to ignore child signals. == OS_SUCCESS ) { // Add the file resources to Supervisor Process so they can be retrieved FileResource::logFileResource( mStdOutPath, SipxProcessManager::getInstance()->findProcess(SUPERVISOR_PROCESS_NAME)); FileResource::logFileResource( mStdErrPath, SipxProcessManager::getInstance()->findProcess(SUPERVISOR_PROCESS_NAME)); FileResource::logFileResource( processOutPath, SipxProcessManager::getInstance()->findProcess(SUPERVISOR_PROCESS_NAME)); UtlString outputFilename = processOutPath; // Construct and set the response. UtlSList outputPaths; outputPaths.insert(&outputFilename); outputPaths.insert(&mStdOutPath); outputPaths.insert(&mStdErrPath); response.setResponse(&outputPaths); status = XmlRpcMethod::OK; result = true; } // launch else { // Failed to launch the command, send a fault. response.setFault(SwAdminRpcMethod::FailureToLaunch, "Failure to launch command"); status = XmlRpcMethod::FAILED; } delete swCheck; } // duplicateProcess } // validcaller else { status = XmlRpcMethod::FAILED; } } // param 1 okay } // param 0 okay } //number of parms check return result; }