Beispiel #1
0
void CHZDLReport::GetData(string deviceName, string & sIP, bool & useCPU, bool & useMemory, float & CPUUtl, float & MemoryUtl)
{
	list<string> getMonList;
	list<string>::iterator getMonItem;
	string MonitorID;

	OBJECT tmpObjMonitor = NULL;
	OBJECT tmpObjTempMonitor = NULL;
	MAPNODE tmpMonitorNode = NULL;
	MAPNODE tmpMonitorTempNode = NULL;
	MAPNODE tempParamNode = NULL;
	LISTITEM ParamItem;
	bool bFind;
	string tmpMonitorTempName;

	useCPU = false;
	useMemory = false;
	CPUUtl = 0;
	MemoryUtl = 0;

	bFind = GetSubMonitorsIDByEntity(GetEntity(deviceName), getMonList);
	if (!bFind) return;

	MAPNODE tmpEntityNode = NULL;
	tmpEntityNode = GetEntityMainAttribNode(GetEntity(deviceName));
	string v;
	bFind = FindNodeValue(tmpEntityNode, "_MachineName", v);
	if (bFind)
	{
		sIP = v;
	}

	getMonItem = getMonList.begin();
	
	while ( (getMonItem != getMonList.end()) && ( (!useCPU) || (!useMemory) ) )
	{
		MonitorID = *getMonItem;
		tmpObjMonitor = GetMonitor(MonitorID);
		if (tmpObjMonitor != INVALID_VALUE)
		{
			tmpMonitorNode = GetMonitorMainAttribNode(tmpObjMonitor);
			string TypeID;
			bFind = FindNodeValue(tmpMonitorNode, "sv_monitortype", TypeID);
			int iType = atoi(TypeID.c_str());
			tmpObjTempMonitor = GetMonitorTemplet(iType);
			if(tmpObjTempMonitor!=INVALID_VALUE)
			{
				tmpMonitorTempNode = GetMTMainAttribNode(tmpObjTempMonitor);	
				bFind = FindNodeValue(tmpMonitorTempNode, "sv_name", tmpMonitorTempName);

				if (!useCPU)
				{
					string stmp1 = "CPU";
					string stmp2 = "Cpu";
					string stmp3 = "cpu";
					if ( findString(tmpMonitorTempName, stmp1) || findString(tmpMonitorTempName, stmp2) || findString(tmpMonitorTempName, stmp3) )
					{
						bFind = FindMTReturnFirst(tmpObjTempMonitor, ParamItem);
						bool findPrimary = false;
						while( ((tempParamNode=::FindNext(ParamItem)) != INVALID_VALUE) && !findPrimary )
						{ 
							string szPrimary;
							FindNodeValue(tempParamNode, "sv_primary",szPrimary);
							if(strcmp(szPrimary.c_str(), "1") == 0)
							{
								findPrimary = true;
								string tmpFieldName;
								FindNodeValue(tempParamNode, "sv_name", tmpFieldName);
								CPUUtl = CalcAverage(MonitorID, tmpFieldName);
							}
						}
						useCPU = true;
					}
				} 
				if (!useMemory)
				{
					string stmp = "Memory";
					if ( findString(tmpMonitorTempName, stmp) )
					{
						bFind = FindMTReturnFirst(tmpObjTempMonitor, ParamItem);
						bool findPrimary = false;
						while( ((tempParamNode=::FindNext(ParamItem)) != INVALID_VALUE) && !findPrimary )
						{ 
							string szPrimary;
							FindNodeValue(tempParamNode, "sv_primary",szPrimary);
							if(strcmp(szPrimary.c_str(), "1") == 0)
							{
								findPrimary = true;
								string tmpFieldName;
								FindNodeValue(tempParamNode, "sv_name", tmpFieldName);
								MemoryUtl = CalcAverage(MonitorID, tmpFieldName);
							}
						}
						useMemory = true;
					}
				}
			}	
		}
		getMonItem++;
	}
}
Beispiel #2
0
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 枚举此设备可以使用的所有监测器
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CEccAddMonitor1st::EnumMT(const string &szParentID, const string &szDTName, const string &szNetworkSet)
{
    m_szParentID = szParentID;
    m_szNetworkset = szNetworkSet;

    if(szDTName.empty() || m_szDTName == szDTName)
        return ;

    m_szDTName = szDTName;

    // 移除已有的消息绑定
    removeMapping();

    if(m_pContent)
    {
        m_pContent->clear();

        list<int> lsMTID;
        CEccMainView::m_pTreeView->GetDevMTList(szDTName, lsMTID);
        list<int>::iterator lstItem;
        // 枚举每个监测器模板
        for(lstItem = lsMTID.begin(); lstItem != lsMTID.end(); lstItem++)
        {
            int nMTID = (*lstItem);
            // 打开监测器模板
            OBJECT objMonitor = GetMonitorTemplet(nMTID, CEccMainView::m_szIDCUser, CEccMainView::m_szAddr);
            if(objMonitor != INVALID_VALUE)
            {// 成功
                // 主节点
                MAPNODE node = GetMTMainAttribNode(objMonitor);
                if(node != INVALID_VALUE)
                {
                    // 名称 显示 是否隐藏 描述
                    string szLabel(""), szHidden (""), szDesc ("");
                    if(FindNodeValue(node, svLabel, szLabel))
                        szLabel = SVResString::getResString(szLabel.c_str());
                    
                    if(FindNodeValue(node, svDescription, szDesc))
                        szDesc = SVResString::getResString(szDesc.c_str());

                    FindNodeValue(node, svHidden, szHidden);

                    if(szHidden != "true")
                    {
                        int nRow = m_pContent->numRows();

                        // 监测器显示文字
                        WText *pName = new WText(szLabel, m_pContent->elementAt(nRow, 0));
                        if(pName)
                        {
                            // 文字样式
                            sprintf(pName->contextmenu_, "style='color:#1E5B99;cursor:pointer;' onmouseover='" \
                                "this.style.textDecoration=\"underline\"' " \
                                "onmouseout='this.style.textDecoration=\"none\"'");
                            // 绑定 click
                            connect(pName, SIGNAL(clicked()), "showbar();", &m_MTMapper, SLOT(map()), WObject::ConnectionType::JAVASCRIPTDYNAMIC);
                            m_MTMapper.setMapping(pName, nMTID);
                            pName->setToolTip(szLabel);
                            m_lsText.push_back(pName);
                        }
                        new WText(szDesc, m_pContent->elementAt(nRow, 1));

                        m_pContent->GetRow(nRow)->setStyleClass("padding_top");
                        m_pContent->elementAt(nRow, 0)->setStyleClass("widthbold");
                        m_pContent->elementAt(nRow, 1)->setStyleClass("color_2");
                    }
                }
                // 关闭监测器模板
                CloseMonitorTemplet(objMonitor);
            }
        }
    }
}