bool Parser::process(bool console) { QString graphContent = ""; QDomDocument xmlDoc; QDomElement xmlRoot; QFile file(m_config); if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) { m_lastErrorMsg = QObject::tr("Unable to open the file %1").arg(m_config); Q_EMIT errorOccurred(m_lastErrorMsg); file.close(); return false; } if (!xmlDoc.setContent(&file)) { file.close(); m_lastErrorMsg = QObject::tr("Error while parsing the file %1").arg(m_config); Q_EMIT errorOccurred(m_lastErrorMsg); return false; } file.close(); // The content of the file is already in memory xmlRoot = xmlDoc.documentElement(); m_cdata->monitor = xmlRoot.attribute("monitor").toInt(); m_cdata->format_version = xmlRoot.attribute("compat").toDouble(); QDomNodeList services = xmlRoot.elementsByTagName("Service"); NodeT node; qint32 serviceCount = services.length(); for (qint32 srv = 0; srv < serviceCount; ++srv) { QDomElement service = services.item(srv).toElement(); node.parent.clear(); node.monitored = false; node.id = service.attribute("id").trimmed(); node.type = service.attribute("type").toInt(); node.sev = ngrt4n::Unknown; node.sev_crule = service.attribute("statusCalcRule").toInt(); node.sev_prule = service.attribute("statusPropRule").toInt(); node.icon = service.firstChildElement("Icon").text().trimmed(); node.name = service.firstChildElement("Name").text().trimmed(); node.description = service.firstChildElement("Description").text().trimmed(); node.alarm_msg = service.firstChildElement("AlarmMsg").text().trimmed(); node.notification_msg = service.firstChildElement("NotificationMsg").text().trimmed(); node.child_nodes = service.firstChildElement("SubServices").text().trimmed(); node.weight = (m_cdata->format_version >= 3.1) ? service.attribute("weight").toDouble() : ngrt4n::WEIGHT_UNIT; if (node.sev_crule == CalcRules::WeightedAverageWithThresholds) { QString thdata = service.firstChildElement("Thresholds").text().trimmed(); node.thresholdLimits = ThresholdHelper::dataToList(thdata); qSort(node.thresholdLimits.begin(), node.thresholdLimits.end(), ThresholdLessthanFnt()); } node.check.status = -1; if (node.icon.isEmpty()) node.icon = ngrt4n::DEFAULT_ICON; if (node.type == NodeType::ITService) { node.visibility = ngrt4n::Visible; StringPairT dataPointInfo = ngrt4n::splitDataPointInfo(node.child_nodes); m_cdata->hosts[dataPointInfo.first] << dataPointInfo.second; QString srcid = ngrt4n::getSourceIdFromStr(dataPointInfo.first); if (srcid.isEmpty()) { srcid = ngrt4n::sourceId(0); if (console) node.child_nodes = ngrt4n::realCheckId(srcid, node.child_nodes); } m_cdata->sources.insert(srcid); m_cdata->cnodes.insert(node.id, node); } else { // i.e. a business service node.visibility = ngrt4n::Visible | ngrt4n::Expanded; m_cdata->bpnodes.insert(node.id, node); } } updateNodeHierachy(graphContent); graphContent = m_dotHeader + graphContent; graphContent += m_dotFooter; saveCoordinatesFile(graphContent); return console ? parseDotResult() : true; }
bool Parser::process(int parsingMode) { m_parsingMode = parsingMode; ngrt4n::clearCoreData(*m_cdata); m_dotContent.clear(); QDomDocument xmlDoc; QDomElement xmlRoot; QFile file(m_descriptionFile); if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) { m_lastErrorMsg = QObject::tr("Unable to open the file %1").arg(m_descriptionFile); Q_EMIT errorOccurred(m_lastErrorMsg); file.close(); return false; } if (!xmlDoc.setContent(&file)) { file.close(); m_lastErrorMsg = QObject::tr("Error while parsing the file %1").arg(m_descriptionFile); Q_EMIT errorOccurred(m_lastErrorMsg); return false; } file.close(); // The content of the file is already in memory xmlRoot = xmlDoc.documentElement(); m_cdata->monitor = xmlRoot.attribute("monitor").toInt(); m_cdata->format_version = xmlRoot.attribute("compat").toDouble(); QDomNodeList services = xmlRoot.elementsByTagName("Service"); NodeT node; qint32 serviceCount = services.length(); for (qint32 srv = 0; srv < serviceCount; ++srv) { QDomElement service = services.item(srv).toElement(); node.parent.clear(); node.monitored = false; node.id = service.attribute("id").trimmed(); node.type = service.attribute("type").toInt(); node.sev = node.sev_prop = ngrt4n::Unknown; node.sev_crule = service.attribute("statusCalcRule").toInt(); node.sev_prule = service.attribute("statusPropRule").toInt(); node.icon = service.firstChildElement("Icon").text().trimmed(); node.name = service.firstChildElement("Name").text().trimmed(); node.description = service.firstChildElement("Description").text().trimmed(); node.alarm_msg = service.firstChildElement("AlarmMsg").text().trimmed(); node.notification_msg = service.firstChildElement("NotificationMsg").text().trimmed(); node.child_nodes = service.firstChildElement("SubServices").text().trimmed(); node.weight = (m_cdata->format_version >= 3.1) ? service.attribute("weight").toDouble() : ngrt4n::WEIGHT_UNIT; if (node.sev_crule == CalcRules::WeightedAverageWithThresholds) { QString thdata = service.firstChildElement("Thresholds").text().trimmed(); node.thresholdLimits = ThresholdHelper::dataToList(thdata); qSort(node.thresholdLimits.begin(), node.thresholdLimits.end(), ThresholdLessthanFnt()); } node.check.status = -1; if (node.icon.isEmpty()) node.icon = ngrt4n::DEFAULT_ICON; switch(node.type) { case NodeType::BusinessService: insertBusinessServiceNode(node); break; case NodeType::ITService: insertITServiceNode(node); break; case NodeType::ExternalService: insertExternalServiceNode(node); break; default: break; } } updateNodeHierachy(); saveCoordinatesFile(); if (m_parsingMode == ParsingModeDashboard) return parseDotResult(); return true; }