Skip to content

Commit

Permalink
fixed regression in view udpate processing
Browse files Browse the repository at this point in the history
  • Loading branch information
joalx committed Jan 4, 2019
1 parent 8e95257 commit efa8b53
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 55 deletions.
52 changes: 31 additions & 21 deletions core/src/DashboardBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ StringMapT DashboardBase::calcRules() {

DashboardBase::DashboardBase(DbSession* dbSession)
: m_dbSession(dbSession),
m_timerId(-1),
m_updateCounter(0)
m_timerId(-1)
{
resetStatData();
}
Expand Down Expand Up @@ -133,26 +132,30 @@ std::pair<int, QString> DashboardBase::updateAllNodesStatus(void)
}

resetStatData();
for (auto&& src: m_sources) { runMonitor(src); }
for (const auto& sid: m_cdata.sources) {
auto src = m_sources.constFind(sid);
if (src != std::cend(m_sources)) {
signalUpdateProcessing(*src);
if (m_cdata.monitor != MonitorT::Any) {
runDynamicViewByGroupUpdate(*src);
} else {
runGenericViewUpdate(*src);
}
finalizeUpdate(*src);
} else {
SourceT unknownSrc;
unknownSrc.id = sid;
updateDashboardOnError(unknownSrc, QObject::tr("source not set %1").arg(sid));
}
}

computeBpNodeStatus(ngrt4n::ROOT_ID, m_dbSession);

updateChart();
++m_updateCounter;

return std::make_pair(ngrt4n::RcSuccess, QObject::tr(""));
}

void DashboardBase::runMonitor(SourceT& src)
{
signalUpdateProcessing(src);

if (src.mon_type != MonitorT::Any) {
runDynamicViewByGroupUpdate(src);
} else {
runGenericViewUpdate(src);
}

finalizeUpdate(src);
}

void DashboardBase::signalUpdateProcessing(const SourceT& src)
{
Expand Down Expand Up @@ -417,6 +420,13 @@ void DashboardBase::finalizeUpdate(const SourceT& src)
}

switch (src.mon_type) {
case MonitorT::Any:
if (std::regex_match(cnode.child_nodes.toStdString(), std::regex(QString("%1:.+").arg(src.id).toStdString()))) {
ngrt4n::setCheckOnError(ngrt4n::Unset, tr("Undefined service (%1)").arg(cnode.child_nodes), cnode.check);
updateNodeStatusInfo(cnode, src);
updateDashboard(cnode);
}
break;
case MonitorT::Kubernetes:
cnode.sev = ngrt4n::Critical;
cnode.check.status = ngrt4n::K8sFailed;
Expand All @@ -425,11 +435,11 @@ void DashboardBase::finalizeUpdate(const SourceT& src)
updateDashboard(cnode);
break;
default:
if (std::regex_match(cnode.child_nodes.toStdString(), std::regex(QString("%1:.+").arg(src.id).toStdString()))) {
ngrt4n::setCheckOnError(ngrt4n::Unset, tr("Undefined service (%1)").arg(cnode.child_nodes), cnode.check);
updateNodeStatusInfo(cnode, src);
updateDashboard(cnode);
}
cnode.sev = ngrt4n::Critical;
cnode.check.status = ngrt4n::Unset;
cnode.check.alarm_msg = QObject::tr("Item %1 seems to no longer exist").arg(cnode.child_nodes).toStdString();
updateNodeStatusInfo(cnode, src);
updateDashboard(cnode);
break;
}

Expand Down
3 changes: 0 additions & 3 deletions core/src/DashboardBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class DashboardBase : public QObject

static StringMapT propRules();
static StringMapT calcRules();
qint64 updateCounter(void) const {return m_updateCounter;}
void setSelectedNode(const QString& nodeid) {m_selectedNode = nodeid;}
QString selectedNode(void) const {return m_selectedNode;}
void setTimerId(qint32 id) {m_timerId = id;}
Expand All @@ -60,7 +59,6 @@ class DashboardBase : public QObject
std::pair<int, QString> updateAllNodesStatus(void);

public Q_SLOTS:
void runMonitor(SourceT& src);
void runGenericViewUpdate(const SourceT& srcInfo);
void runDynamicViewByGroupUpdate(const SourceT& srcInfo);
void resetStatData(void);
Expand Down Expand Up @@ -94,7 +92,6 @@ public Q_SLOTS:
private:
DbSession* m_dbSession;
qint32 m_timerId;
qint64 m_updateCounter;
QString m_selectedNode;
qint32 m_userRole;
qint32 m_interval;
Expand Down
3 changes: 2 additions & 1 deletion core/src/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ std::pair<int, QString> Parser::loadDynamicViewByGroup(QDomNodeList& inXmlDomNod
auto m_lastErrorMsg = QObject::tr("%1: %2").arg(findSourceOut.second.id, loqdK8sNs.first);
return std::make_pair(loqdK8sNs.second, m_lastErrorMsg);
}

} else {
auto loadViewByGroupOut = ngrt4n::loadViewByGroup(findSourceOut.second, monitoredGroup, outCData);
auto loadViewByGroupOut = ngrt4n::loadDynamicViewByGroup(findSourceOut.second, monitoredGroup, outCData);
if (loadViewByGroupOut.first == ngrt4n::RcSuccess) {
ngrt4n::fixupDependencies(outCData);
}
Expand Down
54 changes: 27 additions & 27 deletions core/src/utilsCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,12 @@ QString ngrt4n::basename(const QString& path)
}


std::pair<int, QString> ngrt4n::loadViewByGroup(const SourceT& srcInfo, const QString& filter, CoreDataT& cdata)
std::pair<int, QString> ngrt4n::loadDynamicViewByGroup(const SourceT& sinfo, const QString& filter, CoreDataT& cdata)
{
const auto MONITOR_NAME = MonitorT::toString(srcInfo.mon_type);
const auto MONITOR_NAME = MonitorT::toString(sinfo.mon_type);

ChecksT checks;
auto loadSourceItemsOut = loadDataItems(srcInfo, filter, checks);
auto loadSourceItemsOut = loadDataItems(sinfo, filter, checks);
if (loadSourceItemsOut.first != ngrt4n::RcSuccess) {
return std::make_pair(ngrt4n::RcGenericFailure, QObject::tr("%1: %2").arg(MONITOR_NAME, loadSourceItemsOut.second));
}
Expand All @@ -324,7 +324,7 @@ std::pair<int, QString> ngrt4n::loadViewByGroup(const SourceT& srcInfo, const QS
}

cdata.clear();
cdata.monitor = MonitorT::Any;
cdata.monitor = sinfo.mon_type;
static uint64_t importIndex = 0;

NodeT rootService;
Expand Down Expand Up @@ -362,7 +362,7 @@ std::pair<int, QString> ngrt4n::loadViewByGroup(const SourceT& srcInfo, const QS
itemNode.id = ngrt4n::generateId();
itemNode.parents.insert(hostNode.id);
itemNode.name = checkId.startsWith(hostNode.name+"/") ? checkId.mid(hostNode.name.size() + 1) : checkId;
itemNode.child_nodes = QString::fromStdString("%1:%2").arg(srcInfo.id, checkId);
itemNode.child_nodes = QString::fromStdString("%1:%2").arg(sinfo.id, checkId);
cdata.bpnodes.insert(hostNode.id, hostNode);
cdata.cnodes.insert(itemNode.id, itemNode);
}
Expand All @@ -374,73 +374,73 @@ std::pair<int, QString> ngrt4n::loadViewByGroup(const SourceT& srcInfo, const QS
}


std::pair<int, QString> ngrt4n::loadDataItems(const SourceT& srcInfo, const QString& filter, ChecksT& checks)
std::pair<int, QString> ngrt4n::loadDataItems(const SourceT& sinfo, const QString& filter, ChecksT& checks)
{
// Nagios
if (srcInfo.mon_type == MonitorT::Nagios) {
if (sinfo.mon_type == MonitorT::Nagios) {
int retcode = ngrt4n::RcGenericFailure;
LsHelper handler(srcInfo.ls_addr, static_cast<uint16_t>(srcInfo.ls_port));
LsHelper handler(sinfo.ls_addr, static_cast<uint16_t>(sinfo.ls_port));
if (handler.setupSocket() == 0 && handler.loadChecks(filter, checks) == 0) {
retcode = ngrt4n::RcSuccess;
}
return std::make_pair(retcode, handler.lastError());
}

// Zabbix
if (srcInfo.mon_type == MonitorT::Zabbix) {
if (sinfo.mon_type == MonitorT::Zabbix) {
ZbxHelper handler;
int retcode = handler.loadChecks(srcInfo, checks, filter, ngrt4n::GroupFilter);
int retcode = handler.loadChecks(sinfo, checks, filter, ngrt4n::GroupFilter);
if (checks.empty()) {
retcode = handler.loadChecks(srcInfo, checks, filter, ngrt4n::HostFilter);
retcode = handler.loadChecks(sinfo, checks, filter, ngrt4n::HostFilter);
}
return std::make_pair(retcode, handler.lastError());
}


// Zenoss
if (srcInfo.mon_type == MonitorT::Zenoss) {
ZnsHelper handler(srcInfo.mon_url);
int retcode = handler.loadChecks(srcInfo, checks, filter, ngrt4n::HostFilter);
if (sinfo.mon_type == MonitorT::Zenoss) {
ZnsHelper handler(sinfo.mon_url);
int retcode = handler.loadChecks(sinfo, checks, filter, ngrt4n::HostFilter);
if (checks.empty()) {
retcode = handler.loadChecks(srcInfo, checks, filter, ngrt4n::GroupFilter);
retcode = handler.loadChecks(sinfo, checks, filter, ngrt4n::GroupFilter);
}
return std::make_pair(retcode, handler.lastError());
}


// Pandora
if (srcInfo.mon_type == MonitorT::Pandora) {
PandoraHelper handler(srcInfo.mon_url);
int retcode = handler.loadChecks(srcInfo, checks, filter);
if (sinfo.mon_type == MonitorT::Pandora) {
PandoraHelper handler(sinfo.mon_url);
int retcode = handler.loadChecks(sinfo, checks, filter);
return std::make_pair(retcode, handler.lastError());
}


// OpManager
if (srcInfo.mon_type == MonitorT::OpManager) {
if (sinfo.mon_type == MonitorT::OpManager) {
int retcode = ngrt4n::RcGenericFailure;
OpManagerHelper handler(srcInfo.mon_url);
OpManagerHelper handler(sinfo.mon_url);
if (filter.isEmpty()) {
retcode = handler.loadChecks(srcInfo, OpManagerHelper::ListAllDevices, filter, checks);
retcode = handler.loadChecks(sinfo, OpManagerHelper::ListAllDevices, filter, checks);
} else {
retcode = handler.loadChecks(srcInfo, OpManagerHelper::ListDeviceByName, filter, checks);
retcode = handler.loadChecks(sinfo, OpManagerHelper::ListDeviceByName, filter, checks);
if (checks.empty()) {
retcode = handler.loadChecks(srcInfo, OpManagerHelper::ListDeviceByCategory, filter, checks);
retcode = handler.loadChecks(sinfo, OpManagerHelper::ListDeviceByCategory, filter, checks);
if (checks.empty()) {
retcode = handler.loadChecks(srcInfo, OpManagerHelper::ListDeviceByType, filter, checks);
retcode = handler.loadChecks(sinfo, OpManagerHelper::ListDeviceByType, filter, checks);
}
}
}
return std::make_pair(retcode, handler.lastError());
}

// Kubernetes
if (srcInfo.mon_type == MonitorT::Kubernetes) {
K8sHelper k8s(srcInfo.mon_url, srcInfo.verify_ssl_peer);
if (sinfo.mon_type == MonitorT::Kubernetes) {
K8sHelper k8s(sinfo.mon_url, sinfo.verify_ssl_peer);
return std::make_pair(ngrt4n::RcGenericFailure, "TODO import k8s data points");
}

return std::make_pair(ngrt4n::RcGenericFailure, QObject::tr("Cannot load data points for unknown data source: %1").arg(srcInfo.mon_type));
return std::make_pair(ngrt4n::RcGenericFailure, QObject::tr("Cannot load data points for unknown data source: %1").arg(sinfo.mon_type));
}


Expand Down
4 changes: 2 additions & 2 deletions core/src/utilsCore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ namespace ngrt4n

QString basename(const QString& path);

std::pair<int, QString> loadViewByGroup(const SourceT& srcInfo, const QString& filter, CoreDataT& cdata);
std::pair<int, QString> loadDynamicViewByGroup(const SourceT& sinfo, const QString& filter, CoreDataT& cdata);

std::pair<int, QString> loadDataItems(const SourceT& srcInfo, const QString& filter, ChecksT& checks);
std::pair<int, QString> loadDataItems(const SourceT& sinfo, const QString& filter, ChecksT& checks);

std::pair<int, QString> saveViewDataToPath(const CoreDataT& cdata, const QString& path);

Expand Down
2 changes: 1 addition & 1 deletion web/src/WebEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ void WebEditor::importMonitoringConfig(const std::string& srcId, const std::stri
}

CoreDataT cdata;
auto loadViewByGroupOut = ngrt4n::loadViewByGroup(findSourceOut.second, groupFilter.c_str(), cdata);
auto loadViewByGroupOut = ngrt4n::loadDynamicViewByGroup(findSourceOut.second, groupFilter.c_str(), cdata);
if (loadViewByGroupOut.first != ngrt4n::RcSuccess) {
m_operationCompleted.emit(ngrt4n::OperationFailed, loadViewByGroupOut.second.toStdString());
return ;
Expand Down

0 comments on commit efa8b53

Please sign in to comment.