Пример #1
0
uint process_event(DeviceInfo info, MYSQL *mysql, int trigger_type, int last_status, int situation, long int last_triggered, string name)
{
	MYSQL_RES	*mysql_res;
	MYSQL_ROW	mysql_row;
	uint		status = 0;

	string query = "SELECT `value`, `value_type`, `condition`, `logic_condition` FROM `conditions` WHERE `event_id` = '" + inttostr(info.event_id) + "' ORDER BY `id`";
	mysql_res = db_query(mysql, &info, query);

	for (uint i = 0; i < mysql_num_rows(mysql_res); i++)
	{
		mysql_row = mysql_fetch_row(mysql_res);

		if (i == 0)
		{
			status = process_condition(info, strtoint(mysql_row[0]), strtoint(mysql_row[1]), strtoint(mysql_row[2]));
		}
		else
		{
			switch (strtoint(mysql_row[3]))
			{
				case 0:	status = status && process_condition(info, strtoint(mysql_row[0]), strtoint(mysql_row[1]), strtoint(mysql_row[2]));
					break;
				case 1:	status = status || process_condition(info, strtoint(mysql_row[0]), strtoint(mysql_row[1]), strtoint(mysql_row[2]));
					break;
			}
		}
	}

	mysql_free_result(mysql_res);

	if (status == 0)
	{
		debuglogger(DEBUG_EVENT, LEVEL_INFO, &info, "Not Triggered.");
		db_update(mysql, &info, "UPDATE events SET last_status=0 WHERE id=" + inttostr(info.event_id));
		return 0;
	}
	else
	{
		debuglogger(DEBUG_EVENT, LEVEL_INFO, &info, "Triggered.");
		
		// setup parameters for the response to use.
		info.parameters.push_front(ValuePair("event_name", name));
		info.parameters.push_front(ValuePair("situation", situations[situation]));

		if ((uint) last_status != status)
		{
			db_update(mysql, &info, "UPDATE events SET last_triggered=UNIX_TIMESTAMP(NOW()), last_status=1 WHERE id=" + inttostr(info.event_id));
			db_update(mysql, &info, "INSERT INTO event_log SET date=UNIX_TIMESTAMP(NOW()), time_since_last_change=UNIX_TIMESTAMP(NOW())-" + inttostr(last_triggered) + ", event_id=" + inttostr(info.event_id));

			process_responses(info, mysql);
		}

		return 1;
	}
} // end process_event()
Пример #2
0
// return raw(!) value of frontmost, active statistic item at given position
ValuePairList StatisticsObject::getValuesAt(int x, int y)
{
    ValuePairList valueList;

    for(int i=0; i<p_statsTypeList.count(); i++)
    {
        if (p_statsTypeList[i].render)  // only show active values
        {
            int typeID = p_statsTypeList[i].typeID;
            StatisticsItemList statsList = getStatistics(p_lastIdx, typeID);

            if( statsList.size() == 0 && typeID == INT_INVALID ) // no active statistics
                continue;

            StatisticsType* aType = getStatisticsType(typeID);
            Q_ASSERT(aType->typeID != INT_INVALID && aType->typeID == typeID);

            // find item of this type at requested position
            StatisticsItemList::iterator it;
            bool foundStats = false;
            for (it = statsList.begin(); it != statsList.end(); it++)
            {
                StatisticsItem anItem = *it;

                QRect aRect = anItem.positionRect;

                int rawValue1 = anItem.rawValues[0];
                int rawValue2 = anItem.rawValues[1];

                float vectorValue1 = anItem.vector[0];
                float vectorValue2 = anItem.vector[1];

                if( aRect.contains(x,y) )
                {
                    if( anItem.type == blockType )
                    {
                        valueList.append( ValuePair(aType->typeName, QString::number(rawValue1)) );
                    }
                    else if( anItem.type == arrowType )
                    {
                        // TODO: do we also want to show the raw values?
                        valueList.append( ValuePair(QString("%1[x]").arg(aType->typeName), QString::number(vectorValue1)) );
                        valueList.append( ValuePair(QString("%1[y]").arg(aType->typeName), QString::number(vectorValue2)) );
                    }

                    foundStats = true;
                }
            }

            if(!foundStats)
                valueList.append( ValuePair(aType->typeName, "-") );
        }
    }

    return valueList;
}
Пример #3
0
void Ioss::PropertyManager::add(const Ioss::Property& new_prop)
{
  PropMapType::iterator iter = properties.find(new_prop.get_name());
  if (iter != properties.end()) {
    properties.erase(iter);
  }
  properties.insert(ValuePair(new_prop.get_name(), new_prop));
}
Пример #4
0
void ModelBinder::setGlobalValue(LogFile* lf, std::string varName, RFSMvalueEval valueEval)
{
	//-pthread_mutex_lock(m_mutexp);

	FLOG_TRACE(lf, "  (RUNNING:GVar, Write) %s, %s", varName.c_str(), valueEval.getStrValue().c_str());

	ValueMap::iterator it = m_gVarTAB.find(varName);
	if(it != m_gVarTAB.end()){
		RFSMvalueEval eval = it->second;
		m_gVarTAB.erase(it);
	}
	m_gVarTAB.insert(ValuePair(varName, valueEval));

	//-pthread_mutex_unlock(m_mutexp);
}
Пример #5
0
void ExeTask::setWorkerVar(std::string varName, RFSMvalueEval valueEval)
{
	pthread_mutex_lock(&m_lmu);
	FLOG_TRACE(m_logFile, "  (RUNNING:WVAR, Write) %s, %s", varName.c_str(), valueEval.getStrValue().c_str());
	
	ValueMap::iterator it = m_wVarTAB->find(varName);
	if(it != m_wVarTAB->end()){
		RFSMvalueEval eval = it->second;
		//delete eval;
		m_wVarTAB->erase(it);
	}
	m_wVarTAB->insert(ValuePair(varName, valueEval));

	pthread_mutex_unlock(&m_lmu);
}
Пример #6
0
void Diagram::addValue(float xValue, float yValue){
    values.push_back(ValuePair(xValue,yValue));
}
Пример #7
0
uint process_monitor(DeviceInfo info, MYSQL *mysql, RRDInfo rrd)
{
	debuglogger(DEBUG_MONITOR, LEVEL_INFO, &info, "Starting Monitor.");

	info.parameters.push_front(ValuePair("parameters", info.test_params));

	switch (info.test_type)
	{
		case  1:	info.curr_val = process_script_monitor(info, mysql);
					break;

		case  2:	info.curr_val = process_snmp_monitor(info, mysql);
					break;

		case  3:	info.curr_val = process_sql_monitor(info, mysql);
					break;

		case  4:	info.curr_val = process_internal_monitor(info, mysql);
					break;

		default:	debuglogger(DEBUG_MONITOR, LEVEL_WARNING, &info, "Unknown test type (" + inttostr(info.test_type) + ").");
					info.curr_val = "U";

	} // end switch

	debuglogger(DEBUG_MONITOR, LEVEL_INFO, &info, "Value: " + strstripnl(info.curr_val));

	// strip out anything not numeric
	info.curr_val = remove_nonnumerics(info.curr_val);
	
	if (rrd.data_type != "")
	{
		update_monitor_rrd(info, rrd);
	}

	// what type of value are we dealing with?
	if (info.curr_val == "U")
	{
		// value is unknown
		debuglogger(DEBUG_MONITOR, LEVEL_INFO, &info, "Value is unknown.");
	}
	else if (info.curr_val == inttostr(strtoint(info.curr_val)))
	{
		// value is an integer
		// (do nothing)
		debuglogger(DEBUG_MONITOR, LEVEL_INFO, &info, "Value is an integer.");
	}
	else if (info.curr_val == "")
	{
		// value is non-numeric
		debuglogger(DEBUG_MONITOR, LEVEL_INFO, &info, "Value is not numeric.");
		info.curr_val = "U";
	}
	else
	{
		//value is probably decimal
		debuglogger(DEBUG_MONITOR, LEVEL_INFO, &info, "Value is a decimal.");
		info.curr_val = inttostr(ROUND_VAL(strtodec(info.curr_val)));
	}

	if ((info.curr_val == "U") || (info.last_val == "U"))
	{
		info.delta_val = "U";
		info.rate_val  = "U";
	}
	else
	{
		info.delta_val = inttostr(strtoint(info.curr_val) - strtoint(info.last_val));
		if (info.delta_time != 0)
		{
			info.rate_val  = inttostr(strtoint(info.delta_val) / info.delta_time);
		}
		else
		{
			info.rate_val  = "U";
		}
	}
	
	// populate parameters
	info.parameters.push_front(ValuePair("current_value", info.curr_val));
	info.parameters.push_front(ValuePair("delta_value", info.delta_val));
	info.parameters.push_front(ValuePair("rate_value", info.rate_val));
	info.parameters.push_front(ValuePair("last_value", info.last_val));

	uint status = process_events(info, mysql);

	info.status = status;
	update_monitor_db(info, mysql, rrd);

	return status;
}