unsignedint pol_type;//configfile scripts, crontab or file attribute
char save_path[SAVE_PATH];
}policy_t;
typedefstruct _dev_task_t
{
unsignedint index;//id for table t_task_result
unsignedint host_id;//host id in t_dev
unsignedint host_addr;//host address
struct _dev_task_t * next;
}dev_task_t;
typedefstruct _hosts_policy_t
{
policy_t pol;
dev_task_t * dev_list;
struct _hosts_policy_t * next;
}hosts_policy_t;
typedefstruct _task_t
{
unsignedint task_id;
char task_name[TASK_NAME];
time_t borthday;
hosts_policy_t * pol_list;
struct _task_t * next;
}task_t;
用下图来表示:
初始化代码也比较复杂,从数据库中加载:
int DbMonitor::load_host_policy (task_t* pt)
{
int nRet = 0;
task_t * pTask = pt;
unsignedint old_pol_id = 0;
//loop task list
while(pTask)
{
char szSQL[800]={0};
pTask->pol_list =NULL;
printf("For task [%s]\n", pTask->task_name);
cm_log.LogMessage (CONFIG_SERVER_LOG,"[%s:%d] for task [%s]\n",__FILE__,__LINE__, pTask->task_name);
//load policy information for each task from table 't_task_result'
sprintf(szSQL,
"select t_task_result.Id, t_task_result.f_host_id, t_dev.dev_ip, t_task_result.f_pol_id, t_policy.name, t_policy.type, t_policy.savepath from t_task_result, t_dev, t_policy where t_task_result.f_task_id = %u and t_dev.Id = t_task_result.f_host_id and t_task_result.f_pol_id = t_policy.Id order by t_task_result.f_pol_id desc",
pTask->task_id);
cm_log.LogMessage (CONFIG_SERVER_LOG,"[%s:%d]try to run sql[%s]\n",__FILE__,__LINE__, szSQL);
mysqlpp::Query query = m_pConnect->query(szSQL);
if(mysqlpp::StoreQueryResult res = query.store())
{
cm_log.LogMessage(CONFIG_SERVER_LOG,
"[%s:%d] success run sql[%s]\n",__FILE__,__LINE__, szSQL);