本文整理汇总了C++中DBselect函数的典型用法代码示例。如果您正苦于以下问题:C++ DBselect函数的具体用法?C++ DBselect怎么用?C++ DBselect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DBselect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: delete_history
/******************************************************************************
* *
* Function: delete_history *
* *
* Purpose: remove outdated information from historical table *
* *
* Parameters: now - current timestamp *
* *
* Return value: number of rows deleted *
* *
* Author: Alexei Vladishev *
* *
* Comments: *
* *
******************************************************************************/
static int delete_history(char *table, zbx_uint64_t itemid, int keep_history, int now)
{
DB_RESULT result;
DB_ROW row;
int min_clock;
zabbix_log( LOG_LEVEL_DEBUG, "In delete_history(%s," ZBX_FS_UI64 "," ZBX_FS_UI64 ",%d)",
table,
itemid,
keep_history,
now);
result = DBselect("select min(clock) from %s where itemid=" ZBX_FS_UI64,
table,
itemid);
row=DBfetch(result);
if(!row || DBis_null(row[0]) == SUCCEED)
{
DBfree_result(result);
return 0;
}
min_clock = atoi(row[0]);
DBfree_result(result);
/* zabbix_log( LOG_LEVEL_DEBUG, "Now %d keep_history %d Itemid " ZBX_FS_UI64 " min %d new min %d",
now,
keep_history,
itemid,
min_clock,
MIN(now-24*3600*keep_history, min_clock+4*3600*CONFIG_HOUSEKEEPING_FREQUENCY));*/
return DBexecute("delete from %s where itemid=" ZBX_FS_UI64 " and clock<%d",
table,
itemid,
MIN(now-24*3600*keep_history, min_clock+4*3600*CONFIG_HOUSEKEEPING_FREQUENCY)
);
}
示例2: check_data_uniqueness
static int check_data_uniqueness(const char *table_name, const char *field_name)
{
DB_RESULT result;
DB_ROW row;
int ret = SUCCEED;
if (NULL == (result = DBselect("select %s from %s group by %s having count(*)>1",
field_name, table_name, field_name)))
{
return FAIL;
}
while (NULL != (row = DBfetch(result)))
{
zabbix_log(LOG_LEVEL_CRIT, "Duplicate data \"%s\" for field \"%s\" is found in table \"%s\"."
" Remove it manually and restart the process.", row[0], field_name, table_name);
ret = FAIL;
}
DBfree_result(result);
return ret;
}
示例3: DBpatch_2030024
static int DBpatch_2030024(void)
{
DB_RESULT result;
DB_ROW row;
char *value, *macro_esc, *value_esc;
int ret = FAIL, rc;
/* 1 - ZBX_FLAG_DISCOVERY_RULE*/
if (NULL == (result = DBselect("select itemid,filter from items where filter<>'' and flags=1")))
return FAIL;
while (NULL != (row = DBfetch(result)))
{
if (NULL == (value = strchr(row[1], ':')) || 0 == strcmp(row[1], ":"))
continue;
*value++ = '\0';
macro_esc = DBdyn_escape_string(row[1]);
value_esc = DBdyn_escape_string(value);
rc = DBexecute("insert into item_condition"
" (item_conditionid,itemid,macro,value)"
" values (%s,%s,'%s','%s')",
row[0], row[0], macro_esc, value_esc);
zbx_free(value_esc);
zbx_free(macro_esc);
if (ZBX_DB_OK > rc)
goto out;
}
ret = SUCCEED;
out:
DBfree_result(result);
return ret;
}
示例4: add_discovered_host_group
/******************************************************************************
* *
* Function: add_discovered_host_group *
* *
* Purpose: add group to host if not added already *
* *
* Author: Alexander Vladishev *
* *
******************************************************************************/
static void add_discovered_host_group(zbx_uint64_t hostid, zbx_uint64_t groupid)
{
DB_RESULT result;
DB_ROW row;
zbx_uint64_t hostgroupid;
result = DBselect(
"select hostgroupid"
" from hosts_groups"
" where groupid=" ZBX_FS_UI64
" and hostid=" ZBX_FS_UI64,
groupid, hostid);
if (NULL == (row = DBfetch(result)))
{
hostgroupid = DBget_maxid("hosts_groups");
DBexecute("insert into hosts_groups (hostgroupid,hostid,groupid)"
" values (" ZBX_FS_UI64 "," ZBX_FS_UI64 "," ZBX_FS_UI64 ")",
hostgroupid, hostid, groupid);
}
DBfree_result(result);
}
示例5: main_historysender
/******************************************************************************
* *
* Function: main_historysender *
* *
* Purpose: periodically sends historical data to master node *
* *
* Parameters: *
* *
* Return value: *
* *
* Author: Alexei Vladishev *
* *
* Comments: *
* *
******************************************************************************/
void main_historysender()
{
DB_RESULT result;
DB_ROW row;
int master_nodeid, nodeid;
zabbix_log(LOG_LEVEL_DEBUG, "In main_historysender()");
master_nodeid = CONFIG_MASTER_NODEID;
if (0 == master_nodeid)
return;
result = DBselect("select nodeid from nodes");
while ((row = DBfetch(result))) {
nodeid = atoi(row[0]);
if (SUCCEED == is_master_node(CONFIG_NODEID, nodeid))
continue;
process_history_tables(master_nodeid, nodeid);
}
DBfree_result(result);
}
示例6: get_next_point_to_node
/******************************************************************************
* *
* Function: get_next_point_to_node *
* *
* Purpose: find next point to slave node *
* *
* Parameters: *
* *
* Return value: SUCCEED - processed successfully *
* FAIL - an error occurred *
* *
* Author: Alexander Vladishev *
* *
* Comments: *
* *
******************************************************************************/
static int get_next_point_to_node(int current_nodeid, int slave_nodeid, int *nodeid)
{
DB_RESULT db_result;
DB_ROW db_row;
int id, res = FAIL;
db_result = DBselect("select nodeid from nodes where masterid=%d",
current_nodeid);
while (NULL != (db_row = DBfetch(db_result))) {
id = atoi(db_row[0]);
if (id == slave_nodeid || SUCCEED == get_next_point_to_node(id, slave_nodeid, NULL)) {
if (NULL != nodeid)
*nodeid = id;
res = SUCCEED;
break;
}
}
DBfree_result(db_result);
return res;
}
示例7: add_host_event
/******************************************************************************
* *
* Function: add_host_event *
* *
* Purpose: generate host UP/DOWN event if required *
* *
* Parameters: *
* *
* Return value: *
* *
* Author: Alexei Vladishev *
* *
* Comments: *
* *
******************************************************************************/
static void add_host_event(char *ip)
{
DB_RESULT result;
DB_ROW row;
DB_EVENT event;
int now;
int status;
zbx_uint64_t dhostid;
assert(ip);
zabbix_log(LOG_LEVEL_DEBUG, "In add_host_event(ip:%s)",
ip);
result = DBselect("select status,dhostid from dhosts where ip='%s'",
ip);
row=DBfetch(result);
if(row && DBis_null(row[0])!=SUCCEED)
{
now = time(NULL);
status = atoi(row[0]);
ZBX_STR2UINT64(dhostid, row[1]);
memset(&event,0,sizeof(DB_EVENT));
event.eventid = 0;
event.source = EVENT_SOURCE_DISCOVERY;
event.object = EVENT_OBJECT_DHOST;
event.objectid = dhostid;
event.clock = now;
event.value = status;
event.acknowledged = 0;
process_event(&event);
}
DBfree_result(result);
zabbix_log(LOG_LEVEL_DEBUG, "End add_host_event()");
}
示例8: DBget_version
static void DBget_version(int *mandatory, int *optional)
{
DB_RESULT result;
DB_ROW row;
*mandatory = -1;
*optional = -1;
result = DBselect("select mandatory,optional from dbversion");
if (NULL != (row = DBfetch(result)))
{
*mandatory = atoi(row[0]);
*optional = atoi(row[1]);
}
DBfree_result(result);
if (-1 == *mandatory)
{
zabbix_log(LOG_LEVEL_CRIT, "Cannot get the database version. Exiting ...");
exit(EXIT_FAILURE);
}
}
示例9: ja_host_unlock
/******************************************************************************
* *
* Function: *
* *
* Purpose: *
* *
* Parameters: *
* *
* Return value: *
* *
* Comments: *
* *
******************************************************************************/
int ja_host_unlock(const char *host)
{
int db_ret;
char *host_esc;
const char *__function_name = "ja_host_unlock";
zabbix_log(LOG_LEVEL_DEBUG, "In %s() host: %s", __function_name, host);
DBfree_result(DBselect
("select lock_host_name from ja_host_lock_table where lock_host_name = 'HOST_LOCK_RECORD' for update"));
host_esc = DBdyn_escape_string(host);
db_ret =
DBexecute
("delete from ja_host_lock_table where lock_host_name = '%s'",
host_esc);
zbx_free(host_esc);
if (db_ret < ZBX_DB_OK)
return FAIL;
else
return SUCCEED;
}
示例10: convert_condition_values
/******************************************************************************
* *
* Function: convert_condition_values *
* *
* Purpose: special processing for "value" field in "conditions" table *
* *
* Parameters: old_id - old id, new_id - new node id *
* *
* Return value: SUCCEED - converted successfully *
* FAIL - an error occurred *
* *
* Author: Aleksandrs Saveljevs *
* *
* Comments: *
* *
******************************************************************************/
static int convert_condition_values(int old_id, int new_id, const char *rel_table_name, int type)
{
zbx_uint64_t prefix;
const ZBX_TABLE *r_table;
DB_RESULT result;
DB_ROW row;
zbx_uint64_t value;
if (NULL == (r_table = DBget_table(rel_table_name)))
{
printf("conditions.value FAILED\n");
return FAIL;
}
prefix = (zbx_uint64_t)__UINT64_C(100000000000000)*(zbx_uint64_t)new_id;
if (r_table->flags & ZBX_SYNC)
prefix += (zbx_uint64_t)__UINT64_C(100000000000)*(zbx_uint64_t)new_id;
result = DBselect("select conditionid,value"
" from conditions"
" where conditiontype=%d",
type);
while (NULL != (row = DBfetch(result)))
{
ZBX_STR2UINT64(value, row[1]);
value += prefix;
DBexecute("update conditions"
" set value='" ZBX_FS_UI64 "'"
" where conditionid=%s",
value,
row[0]);
}
DBfree_result(result);
return SUCCEED;
}
示例11: ja_setenv
/******************************************************************************
* *
* Function: *
* *
* Purpose: *
* *
* Parameters: *
* *
* Return value: *
* *
* Comments: *
* *
******************************************************************************/
int ja_setenv(const zbx_uint64_t inner_job_id)
{
int ret;
DB_RESULT result;
DB_ROW row;
char *key, *value;
const char *__function_name = "ja_setenv";
zabbix_log(LOG_LEVEL_DEBUG,
"In %s() inner_job_id: " ZBX_FS_UI64,
__function_name, inner_job_id);
result =
DBselect
("select value_name, before_value from ja_run_value_before_table"
" where inner_job_id = " ZBX_FS_UI64, inner_job_id);
ret = SUCCEED;
while (NULL != (row = DBfetch(result))) {
key = row[0];
value = row[1];
zabbix_log(LOG_LEVEL_DEBUG,
"In %s() inner_job_id: " ZBX_FS_UI64
", %s = %s", __function_name,
inner_job_id, key, value);
if (setenv(key, value, 1) != 0) {
ja_log("JAENV300001", 0, NULL, inner_job_id, __function_name,
inner_job_id, key, value);
ret = FAIL;
break;
}
}
DBfree_result(result);
return ret;
}
示例12: init_config
/******************************************************************************
* *
* Function: init_config *
* *
* Purpose: init list of medias to send notifications in case if DB is down *
* *
* Parameters: *
* *
* Return value: *
* *
* Author: Alexei Vladishev *
* *
* Comments: *
* *
******************************************************************************/
static void init_config()
{
DB_RESULT result;
DB_ROW row;
zabbix_log(LOG_LEVEL_DEBUG, "In init_config()");
result = DBselect("select mt.mediatypeid, mt.type, mt.description, mt.smtp_server, mt.smtp_helo, mt.smtp_email, mt.exec_path, mt.gsm_modem, mt.username, mt.passwd, m.mediaid,m.userid,m.mediatypeid,m.sendto,m.severity,m.period from media m, users_groups u, config c,media_type mt where m.userid=u.userid and u.usrgrpid=c.alert_usrgrpid and m.mediatypeid=mt.mediatypeid and m.active=%d",
MEDIA_STATUS_ACTIVE);
while((row=DBfetch(result)))
{
if(num>=ZBX_MAX_RECIPIENTS) break;
memset(&recipients[num].mediatype, 0, sizeof(DB_MEDIATYPE));
memset(&recipients[num].alert, 0, sizeof(DB_ALERT));
ZBX_STR2UINT64(recipients[num].mediatype.mediatypeid,row[0]);
recipients[num].mediatype.type=atoi(row[1]);
recipients[num].mediatype.description=strdup(row[2]);
recipients[num].mediatype.smtp_server=strdup(row[3]);
recipients[num].mediatype.smtp_helo=strdup(row[4]);
recipients[num].mediatype.smtp_email=strdup(row[5]);
recipients[num].mediatype.exec_path=strdup(row[6]);
recipients[num].mediatype.gsm_modem=strdup(row[7]);
recipients[num].mediatype.username=strdup(row[8]);
recipients[num].mediatype.passwd=strdup(row[9]);
recipients[num].alert.sendto=strdup(row[13]);
recipients[num].alert.subject=strdup("ZABBIX database is down.");
recipients[num].alert.message=strdup("ZABBIX database is down.");
num++;
}
DBfree_result(result);
}
示例13: ja_host_lockinfo
/******************************************************************************
* *
* Function: *
* *
* Purpose: *
* *
* Parameters: *
* *
* Return value: *
* *
* Comments: *
* *
******************************************************************************/
int ja_host_lockinfo(const char *host)
{
int ret;
DB_RESULT result;
DB_ROW row;
char *host_esc;
const char *__function_name = "ja_host_lockinfo";
zabbix_log(LOG_LEVEL_DEBUG, "In %s() host: %s", __function_name, host);
ret = FAIL;
host_esc = DBdyn_escape_string(host);
result =
DBselect
("select lock_host_name from ja_host_lock_table where lock_host_name = '%s'",
host_esc);
row = DBfetch(result);
if (row != NULL)
ret = SUCCEED;
zbx_free(host_esc);
DBfree_result(result);
return ret;
}
示例14: convert_triggers_expression
/******************************************************************************
* *
* Function: convert_triggers_expression *
* *
* Purpose: convert trigger expressions to new node ID *
* *
* Parameters: old_id - old id, new_id - new node id *
* *
* Return value: SUCCEED - converted successfully *
* FAIL - an error occurred *
* *
* Author: Alexander Vladishev *
* *
* Comments: *
* *
******************************************************************************/
static int convert_triggers_expression(int old_id, int new_id)
{
zbx_uint64_t prefix;
const ZBX_TABLE *r_table;
DB_RESULT result;
DB_ROW row;
char new_expression[MAX_STRING_LEN];
char *new_expression_esc;
if (NULL == (r_table = DBget_table("functions")))
{
printf("triggers.expression FAILED\n");
return FAIL;
}
prefix = (zbx_uint64_t)__UINT64_C(100000000000000)*(zbx_uint64_t)new_id;
if (r_table->flags & ZBX_SYNC)
prefix += (zbx_uint64_t)__UINT64_C(100000000000)*(zbx_uint64_t)new_id;
result = DBselect("select expression,triggerid from triggers");
while (NULL != (row = DBfetch(result)))
{
memset(new_expression, 0, sizeof(new_expression));
convert_expression(old_id, new_id, prefix, row[0], new_expression);
new_expression_esc = DBdyn_escape_string_len(new_expression, TRIGGER_EXPRESSION_LEN);
DBexecute("update triggers set expression='%s' where triggerid=%s",
new_expression_esc,
row[1]);
zbx_free(new_expression_esc);
}
DBfree_result(result);
return SUCCEED;
}
示例15: housekeeping_history_and_trends
/******************************************************************************
* *
* Function: housekeeping_history_and_trends *
* *
* Purpose: remove outdated information from history and trends *
* *
* Parameters: now - current timestamp *
* *
* Return value: number of rows deleted *
* *
* Author: Alexei Vladishev *
* *
* Comments: *
* *
******************************************************************************/
static int housekeeping_history_and_trends(int now)
{
const char *__function_name = "housekeeping_history_and_trends";
zbx_uint64_t itemid;
DB_RESULT result;
DB_ROW row;
int history, trends, deleted = 0;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() now:%d", __function_name, now);
result = DBselect(
"select i.itemid,i.history,i.trends from items i,hosts h"
" where i.hostid=h.hostid"
" and h.status in (%d,%d)",
HOST_STATUS_MONITORED, HOST_STATUS_NOT_MONITORED);
while (NULL != (row = DBfetch(result)))
{
ZBX_STR2UINT64(itemid, row[0]);
history = atoi(row[1]);
trends = atoi(row[2]);
deleted += delete_history("history", itemid, history, now);
deleted += delete_history("history_uint", itemid, history, now);
deleted += delete_history("history_str", itemid, history, now);
deleted += delete_history("history_text", itemid, history, now);
deleted += delete_history("history_log", itemid, history, now);
deleted += delete_history("trends", itemid, trends, now);
deleted += delete_history("trends_uint", itemid, trends, now);
}
DBfree_result(result);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%d", __function_name, deleted);
return deleted;
}