summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-01-15 11:46:29 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-01-15 11:46:29 +0000
commitf2cdda2e9d91f04e12687423d54a1bf137d392f5 (patch)
tree02291faf0cab6ef2250bbf87662fe0351c7b98bd
parentce52fd6e6dcef1015d59ce046a0b19f7000a2812 (diff)
downloadzabbix-f2cdda2e9d91f04e12687423d54a1bf137d392f5.tar.gz
zabbix-f2cdda2e9d91f04e12687423d54a1bf137d392f5.tar.xz
zabbix-f2cdda2e9d91f04e12687423d54a1bf137d392f5.zip
- increased message size for alerts (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@3711 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r--ChangeLog1
-rw-r--r--create/schema/schema.sql2
-rw-r--r--frontends/php/include/actions.inc.php2
-rw-r--r--frontends/php/include/events.inc.php2
-rw-r--r--frontends/php/include/forms.inc.php2
-rw-r--r--include/common.h5
-rw-r--r--include/db.h3
-rw-r--r--misc/conf/zabbix_server.conf2
-rw-r--r--src/libs/zbxcommon/base64.c313
-rw-r--r--src/libs/zbxcommon/comms.c23
-rw-r--r--src/libs/zbxcommon/str.c36
-rw-r--r--src/libs/zbxdbhigh/db.c124
-rw-r--r--src/zabbix_get/Makefile.am2
-rw-r--r--src/zabbix_sender/Makefile.am2
-rw-r--r--src/zabbix_server/actions.c26
-rw-r--r--src/zabbix_server/expression.c131
-rw-r--r--src/zabbix_server/server.c92
17 files changed, 231 insertions, 537 deletions
diff --git a/ChangeLog b/ChangeLog
index c8f475fc..33091247 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -65,6 +65,7 @@ Integrated from 1.1.x
1.1.5
+ - increased message size for alerts (Eugene)
- fixed conflict with cookies of other products (Eugene)
- added sorting by host in trigger status screen (Eugene)
- added login/logout information into auditlog (Eugene)
diff --git a/create/schema/schema.sql b/create/schema/schema.sql
index 2122bd15..d698e7e4 100644
--- a/create/schema/schema.sql
+++ b/create/schema/schema.sql
@@ -28,7 +28,7 @@ FIELD |applicationid |t_id |'0' |NOT NULL |ZBX_SYNC
FIELD |nextcheck |t_integer |'0' |NOT NULL |ZBX_SYNC
FIELD |delay |t_integer |'60' |NOT NULL |ZBX_SYNC
FIELD |status |t_integer |'0' |NOT NULL |ZBX_SYNC
-INDEX |httptest_1 |hostid
+INDEX |httptest_1 |httptestid
TABLE|httpstep|httpstepid|ZBX_SYNC
FIELD |httpstepid |t_id |'0' |NOT NULL |ZBX_SYNC
diff --git a/frontends/php/include/actions.inc.php b/frontends/php/include/actions.inc.php
index c0833e01..327b4e20 100644
--- a/frontends/php/include/actions.inc.php
+++ b/frontends/php/include/actions.inc.php
@@ -286,7 +286,7 @@
$denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_MODE_LT);
- $result=DBselect("select a.alertid,a.clock,mt.description,a.sendto,a.subject,a.message,a.status,a.retries,".
+ $result=DBselect("select distinct a.alertid,a.clock,mt.description,a.sendto,a.subject,a.message,a.status,a.retries,".
"a.error from alerts a,media_type mt,functions f,items i ".
" where mt.mediatypeid=a.mediatypeid and a.triggerid=f.triggerid and f.itemid=i.itemid ".
" and i.hostid not in (".$denyed_hosts.")".
diff --git a/frontends/php/include/events.inc.php b/frontends/php/include/events.inc.php
index 9e402ee1..6334725b 100644
--- a/frontends/php/include/events.inc.php
+++ b/frontends/php/include/events.inc.php
@@ -39,7 +39,7 @@
$sql_cond = " and h.hostid=hg.hostid and hg.groupid=".$groupid;
}
- $result = DBselect(" select t.triggerid,t.priority,t.description,h.host,e.clock,e.value ".
+ $result = DBselect("select distinct t.triggerid,t.priority,t.description,h.host,e.clock,e.value ".
" from events e, triggers t, functions f, items i, hosts h ".$sql_from.
" where ".DBid2nodeid("t.triggerid")."=".$nodeid.
" and e.triggerid=t.triggerid and t.triggerid=f.triggerid and f.itemid=i.itemid ".
diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php
index 998ed7b5..9a18ba19 100644
--- a/frontends/php/include/forms.inc.php
+++ b/frontends/php/include/forms.inc.php
@@ -1826,7 +1826,7 @@
$uid=null;
- $frmAction = new CFormTable(S_ACTION,'actionconf.php');
+ $frmAction = new CFormTable(S_ACTION,'actionconf.php','post');
$frmAction->SetHelp('web.actions.action.php');
$conditions = get_request("conditions",array());
diff --git a/include/common.h b/include/common.h
index c4c66bfb..316f3134 100644
--- a/include/common.h
+++ b/include/common.h
@@ -305,8 +305,11 @@ typedef enum
/* Secure string copy */
#define strscpy(x,y) zbx_strlcpy(x,y,sizeof(x))
+#define strnscpy(x,y,n) zbx_strlcpy(x,y,n);
+void *zbx_malloc(size_t size);
#define zbx_free(ptr) { if(ptr){ free(ptr); ptr = NULL; } }
+
#define zbx_fclose(f) { if(f){ fclose(f); f = NULL; } }
/* list structure as item of agent return vaile */
@@ -480,6 +483,8 @@ int set_result_type(AGENT_RESULT *result, int value_type, char *c);
size_t zbx_strlcpy(char *dst, const char *src, size_t siz);
size_t zbx_strlcat(char *dst, const char *src, size_t siz);
+char* zbx_dvsprintf(const char *f, va_list args);
+
int replace_param(const char *cmd, const char *param, char *out, int outlen);
int xml_get_data(char *xml,char *tag, char *data, int maxlen);
diff --git a/include/db.h b/include/db.h
index 60e6da9e..0d4e6715 100644
--- a/include/db.h
+++ b/include/db.h
@@ -340,7 +340,8 @@ DB_ACTION
int lastcheck;
int recipient;
char subject[ACTION_SUBJECT_LEN_MAX]; /* don't use pointer, cose sizeof is used */
- char message[MAX_STRING_LEN]; /* don't use pointer, cose sizeof is used */
+ char *message;
+ int message_len;
int maxrepeats;
int repeatdelay;
char scripts[MAX_STRING_LEN];
diff --git a/misc/conf/zabbix_server.conf b/misc/conf/zabbix_server.conf
index 78b09803..3243ed45 100644
--- a/misc/conf/zabbix_server.conf
+++ b/misc/conf/zabbix_server.conf
@@ -16,7 +16,7 @@ Server=1
# Number of pre-forked instances of pollers
# Default value is 6
-# This parameter must be between 5 and 255
+# This parameter must be between 6 and 255
StartPollers=6
# Number of pre-forked instances of trappers
diff --git a/src/libs/zbxcommon/base64.c b/src/libs/zbxcommon/base64.c
deleted file mode 100644
index bcb3f428..00000000
--- a/src/libs/zbxcommon/base64.c
+++ /dev/null
@@ -1,313 +0,0 @@
-#include "common.h"
-
-#define MAX_B64_LEN ZBX_MAX_B64_LEN
-
-static char base64_set [] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-void str_base64_encode(char *p_str, char *p_b64str, int in_size);
-void str_base64_decode(char *p_b64str, char *p_str, int *p_out_size);
-static char char_base64_encode(unsigned char uc);
-static unsigned char char_base64_decode(char c);
-static int is_base64 (char c);
-
-/*------------------------------------------------------------------------
- *
- * Function : is_base64
- *
- * Purpose : Is the character passed in a base64 character ?
- *
- * Parameters :
- *
- * Returns :
- *
- * Comments :
- *
- *----------------------------------------------------------------------*/
-static int is_base64 (char c)
-{
- if ( (c >= '0' && c <= '9')
- || (c >= 'a' && c <= 'z')
- || (c >= 'A' && c <= 'Z')
- || c == '/'
- || c == '+'
- || c == '=' )
-
- {
- return 1;
- }
-
- return 0;
-}
-/*------------------------------------------------------------------------
- *
- * Function : char_base64_encode
- *
- * Purpose : Encode a byte into a base64 character
- *
- * Parameters :
- *
- * Returns :
- *
- * Comments :
- *
- *----------------------------------------------------------------------*/
-static char char_base64_encode(unsigned char uc)
-{
- return base64_set[uc];
-}
-
-/*------------------------------------------------------------------------
- *
- * Function : char_base64_decode
- *
- * Purpose : Decode a base64 character into a byte
- *
- * Parameters :
- *
- * Returns :
- *
- * Comments :
- *
- *----------------------------------------------------------------------*/
-static unsigned char char_base64_decode(char c)
-{
- if (c >= 'A' && c <= 'Z')
- {
- return c - 'A';
- }
-
- if (c >= 'a' && c <= 'z')
- {
- return c - 'a' + 26;
- }
-
- if (c >= '0' && c <= '9')
- {
- return c - '0' + 52;
- }
-
- if (c == '+')
- {
- return 62;
- }
-
- return 63;
-}
-/*------------------------------------------------------------------------
- *
- * Function : str_base64_encode
- *
- * Purpose : Encode a string into a base64 string
- *
- * Parameters : p_str (in) - the string to encode
- * p_b64str (out) - the encoded str to return
- * in_size (in) - size (length) of input str
- * Returns :
- *
- * Comments :
- *
- *----------------------------------------------------------------------*/
-void str_base64_encode(char *p_str, char *p_b64str, int in_size)
-{
- int i;
- unsigned char from1=0,from2=0,from3=0;
- unsigned char to1=0,to2=0,to3=0,to4=0;
-
- if ( 0 == in_size )
- {
- return;
- };
-
- for ( i = 0; i < in_size ; i += 3 )
- {
- from1 = from2 = from3 = 0;
- from1 = p_str[i];
- if (i+1 < in_size)
- {
- from2 = p_str[i+1];
- }
- if (i+2 < in_size)
- {
- from3 = p_str[i+2];
- }
-
- to1 = to2 = to3 = to4 = 0;
- to1 = (from1>>2) & 0x3f;
- to2 = ((from1&0x3)<<4)|(from2>>4);
- to3 = ((from2&0xf)<<2)|(from3>>6);
- to4 = from3&0x3f;
-
- *(p_b64str++) = char_base64_encode(to1);
- *(p_b64str++) = char_base64_encode(to2);
-
- if (i+1 < in_size)
- {
- *(p_b64str++) = char_base64_encode(to3);
- }
- else
- {
- *(p_b64str++) = '='; /* Padding */
- }
- if (i+2 < in_size)
- {
- *(p_b64str++) = char_base64_encode(to4);
- }
- else
- {
- *(p_b64str++) = '='; /* Padding */
- };
-
-/* if ( i % (76/4*3) == 0)
- {
- *(p_b64str++) = '\r';
- *(p_b64str++) = '\n';
- }*/
- };
-
- return;
-}
-/*------------------------------------------------------------------------
- *
- * Function : str_base64_decode
- *
- * Purpose : Decode a base64 string into a string
- *
- * Parameters : p_b64str (in) - the base64 string to decode
- * p_str (out) - the encoded str to return
- * p_out_size (out) - the size (len) of the str decoded
- *
- * Returns :
- *
- * Comments :
- *
- *----------------------------------------------------------------------*/
-void str_base64_decode(char *p_b64str, char *p_str, int *p_out_size)
-{
- int i;
- int j = 0;
- int in_size;
- char from1='A',from2='A',from3='A',from4='A';
- unsigned char to1=0,to2=0,to3=0,to4=0;
- char str_clean[MAX_B64_LEN];/* str_clean is the string
- * after removing the non-base64
- * characters
- */
-
- in_size = strlen(p_b64str);
- memset(str_clean, 0, sizeof(str_clean));
- *p_out_size = 0;
-
- /* Clean-up input string */
- for ( i=0; i < in_size; i++ )
- {
- if (is_base64(p_b64str[i]))
- {
- str_clean[j++] = p_b64str[i];
- }
- }
-
- /* Re-define in_size after clean-up */
- in_size = strlen(str_clean);
-
- if ( 0 == in_size )
- {
- return;
- }
-
- for ( i=0; i < in_size ;i+=4)
- {
- from1 = from2 = from3 = from4 = 'A';
- from1 = str_clean[i];
- if ( i+1 < in_size )
- {
- from2 = str_clean[i+1];
- }
- if ( i+2 < in_size )
- {
- from3 = str_clean[i+2];
- }
- if ( i+3 < in_size )
- {
- from4 = str_clean[i+3];
- };
-
- to1 = to2 = to3 = to4 = 0;
- to1 = char_base64_decode(from1);
- to2 = char_base64_decode(from2);
- to3 = char_base64_decode(from3);
- to4 = char_base64_decode(from4);
-
- *(p_str++) = ( (to1<<2)|(to2>>4) );
- (*p_out_size)++;
- if (from3 != '=')
- {
- *(p_str++) = ( ((to2&0xf)<<4)|(to3>>2) );
- (*p_out_size)++;
- }
- if (from4 != '=')
- {
- *(p_str++) = ( ((to3&0x3)<<6)|to4 );
- (*p_out_size)++;
- }
- }
-
- return;
-}
-
-/*#define ZABBIX_TEST*/
-
-#ifdef ZABBIX_TEST
-int main()
-{
- int len=2;
- char s[]= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
- "0000000000000000000000000000000000000000000000000000000000000000"
- "11111111111111111111111111111111111111111111111111111111111111";
- char b64[MAX_B64_LEN];
- char b64_rev[MAX_B64_LEN];
- int i;
-
- memset(b64,0,sizeof(b64));
-
- str_base64_encode(s, b64, strlen(s));
- printf("%d: [%s]\n", strlen(s), s);
- printf("%d: [%s]\n\n", strlen(b64), b64);
- str_base64_decode(b64, b64_rev, &i);
- printf("%d: [%s]\n", strlen(s), s);
- printf("%d: [%s]\n", strlen(b64), b64);
- printf("%d: [%s]\n", strlen(b64_rev), b64_rev);
-
- if(strcmp(s,b64_rev) == 0)
- {
- printf("Test passed OK\n");
- }
- else
- {
- printf("Test NOT passed\n");
- }
-}
-#endif
-
diff --git a/src/libs/zbxcommon/comms.c b/src/libs/zbxcommon/comms.c
index d53457fd..201fff95 100644
--- a/src/libs/zbxcommon/comms.c
+++ b/src/libs/zbxcommon/comms.c
@@ -105,3 +105,26 @@ int comms_parse_response(char *xml,char *host,char *key, char *data, char *lastl
return ret;
}
+
+void *zbx_malloc(size_t size)
+{
+ int max_attempts;
+ void *ptr = NULL;
+
+ assert(size);
+
+ for( max_attempts = 10;
+ max_attempts > 0 && !ptr;
+ ptr = malloc(size),
+ max_attempts--
+ );
+
+ if(ptr) return ptr;
+
+ zabbix_log(LOG_LEVEL_CRIT,"out of memory. requested '%i' bytes.", size);
+ exit(FAIL);
+
+ /* Program will never reach this point. */
+ return ptr;
+}
+
diff --git a/src/libs/zbxcommon/str.c b/src/libs/zbxcommon/str.c
index 07e95743..04577476 100644
--- a/src/libs/zbxcommon/str.c
+++ b/src/libs/zbxcommon/str.c
@@ -720,3 +720,39 @@ size_t zbx_strlcat(char *dst, const char *src, size_t siz)
return(dlen + (s - src)); /* count does not include NUL */
}
+
+/******************************************************************************
+ * *
+ * Function: zbx_dvsprintf *
+ * *
+ * Purpose: dinamical formatted output conversion *
+ * *
+ * Return value: formated string *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: required free allocated string with function 'zbx_free' *
+ * *
+ ******************************************************************************/
+char* zbx_dvsprintf(const char *f, va_list args)
+{
+ char *string = NULL;
+ int n, size = MAX_STRING_LEN >> 1;
+
+ while(1) {
+ string = zbx_malloc(size);
+
+ n = vsnprintf(string, size, f, args);
+
+ if(n >= 0 && n < size)
+ break;
+
+ if(n >= size) size = n + 3;
+ else size = size * 3 / 2 + 1;
+
+ zbx_free(string);
+ }
+
+ return string;
+}
+
diff --git a/src/libs/zbxdbhigh/db.c b/src/libs/zbxdbhigh/db.c
index 3924fa61..e9fe7cf9 100644
--- a/src/libs/zbxdbhigh/db.c
+++ b/src/libs/zbxdbhigh/db.c
@@ -284,26 +284,22 @@ void DBrollback(void)
*/
int DBexecute(const char *fmt, ...)
{
- char sql[ZBX_MAX_SQL_LEN];
-
va_list args;
+ char *sql = NULL;
+ int ret = SUCCEED;
+
#ifdef HAVE_POSTGRESQL
PGresult *result;
#endif
-#ifdef HAVE_ORACLE
- int ret;
-#endif
#ifdef HAVE_SQLITE3
- int ret = SUCCEED;
- int sql_ret = SUCCEED;
char *error=0;
#endif
va_start(args, fmt);
- vsnprintf(sql, ZBX_MAX_SQL_LEN-1, fmt, args);
- va_end(args);
+
+ sql = zbx_dvsprintf(fmt, args);
- sql[ZBX_MAX_SQL_LEN-1]='\0';
+ va_end(args);
zabbix_log( LOG_LEVEL_DEBUG, "Executing query:%s", sql);
#ifdef HAVE_MYSQL
@@ -311,9 +307,12 @@ int DBexecute(const char *fmt, ...)
{
zabbix_log( LOG_LEVEL_ERR, "Query::%s",sql);
zabbix_log(LOG_LEVEL_ERR, "Query failed:%s [%d]", mysql_error(&mysql), mysql_errno(&mysql) );
- return FAIL;
+ ret = FAIL;
+ }
+ else
+ {
+ ret = (int)mysql_affected_rows(&mysql);
}
- return (long)mysql_affected_rows(&mysql);
#endif
#ifdef HAVE_POSTGRESQL
result = PQexec(conn,sql);
@@ -322,20 +321,17 @@ int DBexecute(const char *fmt, ...)
{
zabbix_log( LOG_LEVEL_ERR, "Query::%s",sql);
zabbix_log(LOG_LEVEL_ERR, "Query failed:%s", "Result is NULL" );
- PQclear(result);
- return FAIL;
+ ret = FAIL;
}
- if( PQresultStatus(result) != PGRES_COMMAND_OK)
+ else if( PQresultStatus(result) != PGRES_COMMAND_OK)
{
zabbix_log( LOG_LEVEL_ERR, "Query::%s",sql);
zabbix_log(LOG_LEVEL_ERR, "Query failed:%s:%s",
PQresStatus(PQresultStatus(result)),
PQresultErrorMessage(result));
- PQclear(result);
- return FAIL;
+ ret = FAIL;
}
PQclear(result);
- return SUCCEED;
#endif
#ifdef HAVE_ORACLE
if ( (ret = sqlo_exec(oracle, sql))<0 )
@@ -346,7 +342,6 @@ int DBexecute(const char *fmt, ...)
zbx_error("Query failed:%s.", sqlo_geterror(oracle) );
ret = FAIL;
}
- return ret;
#endif
#ifdef HAVE_SQLITE3
if(!sqlite_transaction_started)
@@ -373,8 +368,10 @@ lbl_exec:
{
php_sem_release(&sqlite_access);
}
- return ret;
#endif
+
+ zbx_free(sql);
+ return ret;
}
@@ -399,12 +396,12 @@ void PG_DBfree_result(DB_RESULT result)
if(result->values)
{
result->fld_num = 0;
- free(result->values);
+ zbx_free(result->values);
result->values = NULL;
}
PQclear(result->pg_result);
- free(result);
+ zbx_free(result);
}
#endif
#ifdef HAVE_SQLITE3
@@ -418,7 +415,7 @@ void SQ_DBfree_result(DB_RESULT result)
sqlite3_free_table(result->data);
}
- free(result);
+ zbx_free(result);
}
#endif
@@ -437,7 +434,7 @@ DB_ROW DBfetch(DB_RESULT result)
/* free old data */
if(result->values)
{
- free(result->values);
+ zbx_free(result->values);
result->values = NULL;
}
@@ -449,7 +446,7 @@ DB_ROW DBfetch(DB_RESULT result)
if(result->fld_num > 0)
{
- result->values = malloc(sizeof(char*) * result->fld_num);
+ result->values = zbx_malloc(sizeof(char*) * result->fld_num);
for(i = 0; i < result->fld_num; i++)
{
result->values[i] = PQgetvalue(result->pg_result, result->cursor, i);
@@ -502,12 +499,10 @@ DB_ROW DBfetch(DB_RESULT result)
*/
DB_RESULT DBselect(const char *fmt, ...)
{
- char sql[ZBX_MAX_SQL_LEN];
-
va_list args;
-#if defined(HAVE_POSTGRESQL) || defined(HAVE_SQLITE3)
+ char *sql = NULL;
DB_RESULT result;
-#endif
+
#ifdef HAVE_ORACLE
sqlo_stmt_handle_t sth;
#endif
@@ -517,10 +512,10 @@ DB_RESULT DBselect(const char *fmt, ...)
#endif
va_start(args, fmt);
- vsnprintf(sql, ZBX_MAX_SQL_LEN-1, fmt, args);
- va_end(args);
+
+ sql = zbx_dvsprintf(fmt, args);
- sql[ZBX_MAX_SQL_LEN-1]='\0';
+ va_end(args);
zabbix_log( LOG_LEVEL_DEBUG, "Executing query:%s", sql);
@@ -532,10 +527,10 @@ DB_RESULT DBselect(const char *fmt, ...)
exit(FAIL);
}
- return mysql_store_result(&mysql);
+ result = mysql_store_result(&mysql);
#endif
#ifdef HAVE_POSTGRESQL
- result = malloc(sizeof(ZBX_PG_DB_RESULT));
+ result = zbx_malloc(sizeof(ZBX_PG_DB_RESULT));
result->pg_result = PQexec(conn,sql);
result->values = NULL;
result->cursor = 0;
@@ -558,7 +553,6 @@ DB_RESULT DBselect(const char *fmt, ...)
/* init rownum */
result->row_num = PQntuples(result->pg_result);
- return result;
#endif
#ifdef HAVE_ORACLE
if(0 > (sth = (sqlo_open(oracle, sql,0,NULL))))
@@ -567,7 +561,7 @@ DB_RESULT DBselect(const char *fmt, ...)
zabbix_log(LOG_LEVEL_ERR, "Query failed:%s", sqlo_geterror(oracle));
exit(FAIL);
}
- return sth;
+ result = sth;
#endif
#ifdef HAVE_SQLITE3
if(!sqlite_transaction_started)
@@ -575,16 +569,16 @@ DB_RESULT DBselect(const char *fmt, ...)
php_sem_acquire(&sqlite_access);
}
- result = malloc(sizeof(ZBX_SQ_DB_RESULT));
+ result = zbx_malloc(sizeof(ZBX_SQ_DB_RESULT));
result->curow = 0;
lbl_get_table:
- if(SQLITE_OK != (sql_ret = sqlite3_get_table(sqlite,sql,&result->data,&result->nrow, &result->ncolumn, &error)))
+ if(SQLITE_OK != (ret = sqlite3_get_table(sqlite,sql,&result->data,&result->nrow, &result->ncolumn, &error)))
{
- if(sql_ret == SQLITE_BUSY) goto lbl_get_table; /* attention deadlock!!! */
+ if(ret == SQLITE_BUSY) goto lbl_get_table; /* attention deadlock!!! */
zabbix_log( LOG_LEVEL_ERR, "Query::%s",sql);
- zabbix_log(LOG_LEVEL_ERR, "Query failed [%i]:%s", sql_ret, error);
+ zabbix_log(LOG_LEVEL_ERR, "Query failed [%i]:%s", ret, error);
sqlite3_free(error);
if(!sqlite_transaction_started)
{
@@ -597,8 +591,10 @@ lbl_get_table:
{
php_sem_release(&sqlite_access);
}
- return result;
#endif
+
+ zbx_free(sql);
+ return result;
}
/*
@@ -1563,12 +1559,7 @@ int DBadd_history_text(zbx_uint64_t itemid, char *value, int clock)
zabbix_log(LOG_LEVEL_DEBUG,"In add_history_text()");
value_esc_max_len = strlen(value)+1024;
- value_esc = malloc(value_esc_max_len);
- if(value_esc == NULL)
- {
- zabbix_log(LOG_LEVEL_DEBUG,"Can't allocate required memory");
- goto lbl_exit;
- }
+ value_esc = zbx_malloc(value_esc_max_len);
DBescape_string(value, value_esc, value_esc_max_len-1);
value_esc_max_len = strlen(value_esc);
@@ -1629,7 +1620,7 @@ lbl_exit_loblp:
lbl_exit:
if(sth >= 0) sqlo_close(sth);
- if(value_esc) free(value_esc);
+ zbx_free(value_esc);
sqlo_autocommit_on(oracle);
@@ -1644,11 +1635,7 @@ lbl_exit:
zabbix_log(LOG_LEVEL_DEBUG,"In add_history_str()");
value_esc_max_len = strlen(value)+1024;
- value_esc = malloc(value_esc_max_len);
- if(value_esc == NULL)
- {
- return FAIL;
- }
+ value_esc = zbx_malloc(value_esc_max_len);
sql_max_len = value_esc_max_len+100;
@@ -1656,7 +1643,7 @@ lbl_exit:
DBexecute("insert into history_text (clock,itemid,value) values (%d," ZBX_FS_UI64 ",'%s')",
clock,itemid,value_esc);
- free(value_esc);
+ zbx_free(value_esc);
return SUCCEED;
@@ -1876,23 +1863,40 @@ int DBget_queue_count(void)
int DBadd_alert(zbx_uint64_t actionid, zbx_uint64_t userid, zbx_uint64_t triggerid, zbx_uint64_t mediatypeid, char *sendto, char *subject, char *message, int maxrepeats, int repeatdelay)
{
int now;
- char sendto_esc[MAX_STRING_LEN];
- char subject_esc[MAX_STRING_LEN];
- char message_esc[MAX_STRING_LEN];
+
+ char *sendto_esc = NULL;
+ char *subject_esc = NULL;
+ char *message_esc = NULL;
+
+ int size;
zabbix_log(LOG_LEVEL_DEBUG,"In add_alert(triggerid[%d])",triggerid);
now = time(NULL);
/* Does not work on PostgreSQL */
/* zbx_snprintf(sql,sizeof(sql),"insert into alerts (alertid,actionid,clock,mediatypeid,sendto,subject,message,status,retries) values (NULL,%d,%d,%d,'%s','%s','%s',0,0)",actionid,now,mediatypeid,sendto,subject,message);*/
- DBescape_string(sendto,sendto_esc,MAX_STRING_LEN);
- DBescape_string(subject,subject_esc,MAX_STRING_LEN);
- DBescape_string(message,message_esc,MAX_STRING_LEN);
+
+ size = strlen(sendto) * 3 / 2 + 1;
+ sendto_esc = zbx_malloc(size);
+ DBescape_string(sendto, sendto_esc, size);
+
+ size = strlen(subject) * 3 / 2 + 1;
+ subject_esc = zbx_malloc(size);
+ DBescape_string(subject,subject_esc,size);
+
+ size = strlen(message) * 3 / 2 + 1;
+ message_esc = zbx_malloc(size);
+ DBescape_string(message,message_esc,size);
+
DBexecute("insert into alerts (alertid, actionid,triggerid,userid,clock,mediatypeid,sendto,subject,message,status,retries,maxrepeats,delay)"
" values (" ZBX_FS_UI64 "," ZBX_FS_UI64 "," ZBX_FS_UI64 "," ZBX_FS_UI64 ",%d," ZBX_FS_UI64 ",'%s','%s','%s',0,0,%d,%d)",
DBget_maxid("alerts","alertid"),
actionid,triggerid,userid,now,mediatypeid,sendto_esc,subject_esc,message_esc, maxrepeats, repeatdelay);
+ zbx_free(sendto_esc);
+ zbx_free(subject_esc);
+ zbx_free(message_esc);
+
return SUCCEED;
}
diff --git a/src/zabbix_get/Makefile.am b/src/zabbix_get/Makefile.am
index b38e4ff8..740c8d33 100644
--- a/src/zabbix_get/Makefile.am
+++ b/src/zabbix_get/Makefile.am
@@ -1,4 +1,4 @@
SUBDIRS =
bin_PROGRAMS = zabbix_get
zabbix_get_SOURCES = zabbix_get.c
-zabbix_get_LDADD = ../libs/zbxlog/libzbxlog.a ../libs/zbxcommon/libzbxcommon.a ../libs/zbxsys/libzbxsys.a
+zabbix_get_LDADD = ../libs/zbxcommon/libzbxcommon.a ../libs/zbxlog/libzbxlog.a ../libs/zbxcrypto/libzbxcrypto.a ../libs/zbxsys/libzbxsys.a ../libs/zbxconf/libzbxconf.a
diff --git a/src/zabbix_sender/Makefile.am b/src/zabbix_sender/Makefile.am
index 5d98d9f0..7b356bc0 100644
--- a/src/zabbix_sender/Makefile.am
+++ b/src/zabbix_sender/Makefile.am
@@ -1,4 +1,4 @@
SUBDIRS =
bin_PROGRAMS = zabbix_sender
zabbix_sender_SOURCES = zabbix_sender.c
-zabbix_sender_LDADD = ../libs/zbxlog/libzbxlog.a ../libs/zbxcommon/libzbxcommon.a ../libs/zbxsys/libzbxsys.a ../libs/zbxcrypto/libzbxcrypto.a
+zabbix_sender_LDADD = ../libs/zbxcommon/libzbxcommon.a ../libs/zbxlog/libzbxlog.a ../libs/zbxsys/libzbxsys.a ../libs/zbxcrypto/libzbxcrypto.a ../libs/zbxconf/libzbxconf.a
diff --git a/src/zabbix_server/actions.c b/src/zabbix_server/actions.c
index bc7ab037..d0aa37bb 100644
--- a/src/zabbix_server/actions.c
+++ b/src/zabbix_server/actions.c
@@ -533,7 +533,7 @@ static int check_action_condition(DB_EVENT *event, DB_CONDITION *condition)
}
else if(condition->conditiontype == CONDITION_TYPE_TRIGGER_VALUE)
{
- zabbix_log( LOG_LEVEL_DEBUG, "CONDITION_TYPE_TRIGGER_VALUE [%s:%s]", event->value, condition->value);
+ zabbix_log( LOG_LEVEL_DEBUG, "CONDITION_TYPE_TRIGGER_VALUE [%d:%s]", event->value, condition->value);
if(condition->operator == CONDITION_OPERATOR_EQUAL)
{
if(event->value == atoi(condition->value))
@@ -713,15 +713,23 @@ void apply_actions(DB_EVENT *event)
ZBX_STR2UINT64(action.userid, row[1]);
strscpy(action.subject,row[2]);
- strscpy(action.message,row[3]);
- substitute_macros(event, &action, action.message, sizeof(action.message));
- substitute_macros(event, &action, action.subject, sizeof(action.subject));
+
+ action.message_len = strlen(row[3]) * 3 / 2 + 1;
+ action.message = zbx_malloc(action.message_len);
- action.recipient=atoi(row[4]);
- action.maxrepeats=atoi(row[5]);
- action.repeatdelay=atoi(row[6]);
+ strnscpy(action.message,row[3], action.message_len);
+
+ action.recipient = atoi(row[4]);
+ action.maxrepeats = atoi(row[5]);
+ action.repeatdelay = atoi(row[6]);
strscpy(action.scripts,row[7]);
- action.actiontype=atoi(row[8]);
+ action.actiontype = atoi(row[8]);
+
+ substitute_macros(event, &action, action.message, action.message_len);
+ substitute_macros(event, &action, action.subject, sizeof(action.subject));
+
+zabbix_log(LOG_LEVEL_CRIT,"Original [%d]: %s", strlen(row[3]), row[3]); // TMP!!!
+zabbix_log(LOG_LEVEL_CRIT,"Substituted [%d,%d]: %s", strlen(action.message), action.message_len, action.message); // TMP!!!
if(action.actiontype == ACTION_TYPE_MESSAGE)
send_to_user(event,&action);
@@ -730,6 +738,8 @@ void apply_actions(DB_EVENT *event)
/* zbx_snprintf(sql,sizeof(sql),"update actions set nextcheck=%d where actionid=%d",now+action.delay,action.actionid);
DBexecute(sql);*/
+
+ zbx_free(action.message);
}
else
{
diff --git a/src/zabbix_server/expression.c b/src/zabbix_server/expression.c
index 8d64ed28..292b6334 100644
--- a/src/zabbix_server/expression.c
+++ b/src/zabbix_server/expression.c
@@ -549,7 +549,7 @@ int evaluate(int *result,char *exp, char *error, int maxerrlen)
* Parameters: trigger - trigger structure *
* action - action structure (NULL if uncnown) *
* data - data string *
- * dala_max_len - max length of data string,include '\0' *
+ * data_max_len - max length of data string,include '\0' *
* *
* Return value: *
* *
@@ -582,10 +582,12 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in
char
*pl = NULL,
*pr = NULL,
- str_out[MAX_STRING_LEN],
- replace_to[MAX_STRING_LEN];
+ *str_out = NULL,
+ *replace_to = NULL;
int
- outlen,
+ replace_to_len,
+ str_out_len,
+ str_out_fill,
var_len;
time_t now;
@@ -596,17 +598,22 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in
zabbix_log(LOG_LEVEL_DEBUG, "In substitute_simple_macros [%s]",data);
- *str_out = '\0';
- outlen = sizeof(str_out) - 1;
+ replace_to_len = strlen(data);
+ replace_to = zbx_malloc(replace_to_len);
+
+ str_out_fill = 0;
+ str_out_len = strlen(data) * 3 / 2 + 1;
+ str_out = zbx_malloc(str_out_len + 1);
+ *str_out = '\0';
+
pl = data;
- while((pr = strchr(pl, '{')) && outlen > 0)
+ while((pr = strchr(pl, '{')) && str_out_fill < str_out_len)
{
pr[0] = '\0';
- zbx_strlcat(str_out, pl, outlen);
- outlen -= MIN(strlen(pl), outlen);
+ str_out_fill = zbx_strlcat(str_out, pl, str_out_len);
pr[0] = '{';
- zbx_snprintf(replace_to, sizeof(replace_to), "{");
+ zbx_snprintf(replace_to, replace_to_len, "{");
var_len = 1;
if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) &&
@@ -614,15 +621,15 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in
{
var_len = strlen(MVAR_TRIGGER_NAME);
- zbx_snprintf(replace_to, sizeof(replace_to), "%s", event->trigger_description);
- substitute_simple_macros(event, action, replace_to, sizeof(replace_to), MACRO_TYPE_TRIGGER_DESCRIPTION);
+ zbx_snprintf(replace_to, replace_to_len, "%s", event->trigger_description);
+ substitute_simple_macros(event, action, replace_to, replace_to_len, MACRO_TYPE_TRIGGER_DESCRIPTION);
}
else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) &&
strncmp(pr, MVAR_TRIGGER_COMMENT, strlen(MVAR_TRIGGER_COMMENT)) == 0)
{
var_len = strlen(MVAR_TRIGGER_COMMENT);
- zbx_snprintf(replace_to, sizeof(replace_to), "%s", event->trigger_comments);
+ zbx_snprintf(replace_to, replace_to_len, "%s", event->trigger_comments);
}
else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY | MACRO_TYPE_TRIGGER_DESCRIPTION) &&
strncmp(pr, MVAR_HOST_NAME, strlen(MVAR_HOST_NAME)) == 0)
@@ -642,11 +649,11 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in
zabbix_syslog("No hostname in substitute_simple_macros. Triggerid [" ZBX_FS_UI64 "]",
event->triggerid);
- zbx_snprintf(replace_to, sizeof(replace_to), "%s", STR_UNKNOWN_VARIAVLE);
+ zbx_snprintf(replace_to, replace_to_len, "%s", STR_UNKNOWN_VARIAVLE);
}
else
{
- zbx_snprintf(replace_to, sizeof(replace_to), "%s", row[0]);
+ zbx_snprintf(replace_to, replace_to_len, "%s", row[0]);
}
DBfree_result(result);
}
@@ -672,7 +679,7 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in
}
else
{
- zbx_snprintf(replace_to, sizeof(replace_to), "%s", row[0]);
+ zbx_snprintf(replace_to, replace_to_len, "%s", row[0]);
}
DBfree_result(result);
@@ -695,11 +702,11 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in
zabbix_syslog("No hostname in substitute_simple_macros. Triggerid [" ZBX_FS_UI64 "]",
event->triggerid);
- zbx_snprintf(replace_to, sizeof(replace_to), "%s", STR_UNKNOWN_VARIAVLE);
+ zbx_snprintf(replace_to, replace_to_len, "%s", STR_UNKNOWN_VARIAVLE);
}
else
{
- zbx_snprintf(replace_to, sizeof(replace_to), "%s", row[0]);
+ zbx_snprintf(replace_to, replace_to_len, "%s", row[0]);
}
DBfree_result(result);
}
@@ -710,7 +717,7 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in
now = time(NULL);
tm = localtime(&now);
- zbx_snprintf(replace_to, sizeof(replace_to)-1, "%.4d.%.2d.%.2d", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday);
+ zbx_snprintf(replace_to, replace_to_len-1, "%.4d.%.2d.%.2d", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday);
}
else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY)&&
strncmp(pr, MVAR_TIME, strlen(MVAR_TIME)) == 0)
@@ -719,7 +726,7 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in
now = time(NULL);
tm = localtime(&now);
- zbx_snprintf(replace_to, sizeof(replace_to), "%.2d:%.2d:%.2d",tm->tm_hour,tm->tm_min,tm->tm_sec);
+ zbx_snprintf(replace_to, replace_to_len, "%.2d:%.2d:%.2d",tm->tm_hour,tm->tm_min,tm->tm_sec);
}
else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) &&
@@ -729,9 +736,9 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in
var_len = strlen(MVAR_TRIGGER_STATUS);
if(event->value == TRIGGER_VALUE_TRUE)
- zbx_snprintf(replace_to, sizeof(replace_to), "OFF");
+ zbx_snprintf(replace_to, replace_to_len, "OFF");
else
- zbx_snprintf(replace_to, sizeof(replace_to), "ON");
+ zbx_snprintf(replace_to, replace_to_len, "ON");
}
else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) &&
strncmp(pr, MVAR_TRIGGER_STATUS_OLD, strlen(MVAR_TRIGGER_STATUS_OLD)) == 0)
@@ -740,9 +747,9 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in
var_len = strlen(MVAR_TRIGGER_STATUS_OLD);
if(event->value == TRIGGER_VALUE_TRUE)
- zbx_snprintf(replace_to, sizeof(replace_to), "OFF");
+ zbx_snprintf(replace_to, replace_to_len, "OFF");
else
- zbx_snprintf(replace_to, sizeof(replace_to), "ON");
+ zbx_snprintf(replace_to, replace_to_len, "ON");
}
else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) &&
strncmp(pr, MVAR_TRIGGER_ID, strlen(MVAR_TRIGGER_ID)) == 0)
@@ -750,7 +757,7 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in
/* NOTE: if you make changes for this bloc, don't forgot MVAR_TRIGGER_STATUS block */
var_len = strlen(MVAR_TRIGGER_ID);
- zbx_snprintf(replace_to, sizeof(replace_to), ZBX_FS_UI64, event->triggerid);
+ zbx_snprintf(replace_to, replace_to_len, ZBX_FS_UI64, event->triggerid);
}
else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) &&
strncmp(pr, MVAR_TRIGGER_URL, strlen(MVAR_TRIGGER_URL)) == 0)
@@ -758,7 +765,7 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in
/* NOTE: if you make changes for this bloc, don't forgot MVAR_TRIGGER_STATUS block */
var_len = strlen(MVAR_TRIGGER_URL);
- zbx_snprintf(replace_to, sizeof(replace_to), "%s", event->trigger_url);
+ zbx_snprintf(replace_to, replace_to_len, "%s", event->trigger_url);
}
else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) &&
strncmp(pr, MVAR_EVENT_ID, strlen(MVAR_EVENT_ID)) == 0)
@@ -766,31 +773,32 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in
/* NOTE: if you make changes for this bloc, don't forgot MVAR_TRIGGER_STATUS block */
var_len = strlen(MVAR_EVENT_ID);
- zbx_snprintf(replace_to, sizeof(replace_to), ZBX_FS_UI64, event->eventid);
+ zbx_snprintf(replace_to, replace_to_len, ZBX_FS_UI64, event->eventid);
}
else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) &&
strncmp(pr, MVAR_TRIGGER_SEVERITY, strlen(MVAR_TRIGGER_SEVERITY)) == 0)
{
var_len = strlen(MVAR_TRIGGER_SEVERITY);
- if(event->trigger_priority == 0) zbx_snprintf(replace_to, sizeof(replace_to), "Not classified");
- else if(event->trigger_priority == 1) zbx_snprintf(replace_to, sizeof(replace_to), "Information");
- else if(event->trigger_priority == 2) zbx_snprintf(replace_to, sizeof(replace_to), "Warning");
- else if(event->trigger_priority == 3) zbx_snprintf(replace_to, sizeof(replace_to), "Average");
- else if(event->trigger_priority == 4) zbx_snprintf(replace_to, sizeof(replace_to), "High");
- else if(event->trigger_priority == 5) zbx_snprintf(replace_to, sizeof(replace_to), "Disaster");
- else zbx_snprintf(replace_to, sizeof(replace_to), "Unknown");
+ if(event->trigger_priority == 0) zbx_snprintf(replace_to, replace_to_len, "Not classified");
+ else if(event->trigger_priority == 1) zbx_snprintf(replace_to, replace_to_len, "Information");
+ else if(event->trigger_priority == 2) zbx_snprintf(replace_to, replace_to_len, "Warning");
+ else if(event->trigger_priority == 3) zbx_snprintf(replace_to, replace_to_len, "Average");
+ else if(event->trigger_priority == 4) zbx_snprintf(replace_to, replace_to_len, "High");
+ else if(event->trigger_priority == 5) zbx_snprintf(replace_to, replace_to_len, "Disaster");
+ else zbx_snprintf(replace_to, replace_to_len, "Unknown");
}
- zbx_strlcat(str_out, replace_to, outlen);
- outlen -= MIN(strlen(replace_to), outlen);
+ str_out_fill = zbx_strlcat(str_out, replace_to, str_out_len);
pl = pr + var_len;
}
- zbx_strlcat(str_out, pl, outlen);
- outlen -= MIN(strlen(pl), outlen);
+ str_out_fill = zbx_strlcat(str_out, pl, str_out_len);
zbx_snprintf(data, data_max_len, "%s", str_out);
+ zbx_free(str_out);
+ zbx_free(replace_to);
+
zabbix_log( LOG_LEVEL_DEBUG, "Result expression [%s]", data );
}
@@ -802,7 +810,7 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in
* *
* Parameters: trigger - trigger structure *
* action - action structure *
- * dala_max_len - max length of data string,include '\0' *
+ * data_max_len - max length of data string,include '\0' *
* data - data string *
* *
* Return value: *
@@ -812,11 +820,11 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in
* Comments: example: "{127.0.0.1:system[procload].last(0)}" to "1.34" *
* *
******************************************************************************/
-void substitute_macros(DB_EVENT *event, DB_ACTION *action, char *data, int dala_max_len)
+void substitute_macros(DB_EVENT *event, DB_ACTION *action, char *data, int data_max_len)
{
char
- str_out[MAX_STRING_LEN],
- replace_to[MAX_STRING_LEN],
+ *str_out = NULL,
+ *replace_to = NULL,
*pl = NULL,
*pr = NULL,
*pms = NULL,
@@ -829,18 +837,25 @@ void substitute_macros(DB_EVENT *event, DB_ACTION *action, char *data, int dala_
parameter[MAX_STRING_LEN];
int
- outlen,
+ replace_to_len,
+ str_out_len,
+ str_out_fill,
var_len;
-
zabbix_log(LOG_LEVEL_DEBUG, "In substitute_macros([%s])",data);
+
+ substitute_simple_macros(event, action, data, data_max_len, MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY);
- substitute_simple_macros(event, action, data, dala_max_len, MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY);
-
- *str_out = '\0';
- outlen = sizeof(str_out) - 1;
+ replace_to_len = strlen(data);
+ replace_to = zbx_malloc(replace_to_len);
+
+ str_out_fill = 0;
+ str_out_len = strlen(data) * 3 / 2 + 1;
+ str_out = zbx_malloc(str_out_len + 1);
+ *str_out = '\0';
+
pl = data;
- while((pr = strchr(pl, '{')) && outlen > 0)
+ while((pr = strchr(pl, '{')) && str_out_fill < str_out_len)
{
if((pme = strchr(pr, '}')) == NULL)
break;
@@ -851,13 +866,12 @@ void substitute_macros(DB_EVENT *event, DB_ACTION *action, char *data, int dala_
/* copy left side */
pr[0] = '\0';
- zbx_strlcat(str_out, pl, outlen);
- outlen -= MIN(strlen(pl), outlen);
+ str_out_fill = zbx_strlcat(str_out, pl, str_out_len);
pr[0] = '{';
/* copy original name of variable */
- zbx_snprintf(replace_to, sizeof(replace_to), "%s}", pr); /* in format used '}' */
+ zbx_snprintf(replace_to, replace_to_len, "%s}", pr); /* in format used '}' */
/* cose in 'pr' string symbol '}' is changed to '\0' by 'pme'*/
var_len = strlen(replace_to);
@@ -889,7 +903,7 @@ void substitute_macros(DB_EVENT *event, DB_ACTION *action, char *data, int dala_
pms = p + 1;
if(evaluate_FUNCTION2(replace_to,host,key,function,parameter) != SUCCEED)
- zbx_snprintf(replace_to, sizeof(replace_to), "%s", STR_UNKNOWN_VARIAVLE);
+ zbx_snprintf(replace_to, replace_to_len, "%s", STR_UNKNOWN_VARIAVLE);
}
}
}
@@ -897,14 +911,15 @@ void substitute_macros(DB_EVENT *event, DB_ACTION *action, char *data, int dala_
}
pme[0] = '}';
- zbx_strlcat(str_out, replace_to, outlen);
- outlen -= MIN(strlen(replace_to), outlen);
+ str_out_fill = zbx_strlcat(str_out, replace_to, str_out_len);
pl = pr + var_len;
}
- zbx_strlcat(str_out, pl, outlen);
- outlen -= MIN(strlen(pl), outlen);
+ str_out_fill = zbx_strlcat(str_out, pl, str_out_len);
+
+ zbx_snprintf(data, data_max_len, "%s", str_out);
- zbx_snprintf(data, dala_max_len, "%s", str_out);
+ zbx_free(str_out);
+ zbx_free(replace_to);
zabbix_log( LOG_LEVEL_DEBUG, "Result expression:%s", data );
}
diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c
index de131349..103a354c 100644
--- a/src/zabbix_server/server.c
+++ b/src/zabbix_server/server.c
@@ -326,102 +326,14 @@ int tcp_listen(const char *host, int port, socklen_t *addrlenp)
* *
******************************************************************************/
-/*#define TEST */
+/* #define TEST */
#ifdef TEST
-#define ZBX_LIM_PRINT(msg, str_len, str, limit) \
- printf(msg "(%i): %." #limit "s<br/>\n", str_len, str, str_len > limit ? "..." : "")
-
-//#define ZBX_LIM_PRINT(msg, str_len, str, limit)
-
-size_t HEADERFUNCTION( void *ptr, size_t size, size_t nmemb, void *stream)
-{
- ZBX_LIM_PRINT("HEADERFUNCTION", size*nmemb, ptr, 300);
-
- return size*nmemb;
-}
-
-size_t WRITEFUNCTION( void *ptr, size_t size, size_t nmemb, void *stream)
-{
- size_t s = size*nmemb + 1;
- char *str_dat = calloc(1, s);
-
- zbx_snprintf(str_dat,s,ptr);
- ZBX_LIM_PRINT("WRITEFUNCTION", s, str_dat, 65535);
-
- return size*nmemb;
-}
-
-#define XBX_CURL_ERR(msg) \
- printf("ERROR: " msg " [%s]\n", curl_easy_strerror(err))
-
-#define ZBX_CURL_SET_OPT(opt_name, opt_val) \
- if(CURLE_OK != (err = curl_easy_setopt(easyhandle, opt_name, opt_val))) \
- XBX_CURL_ERR("curl_easy_setopt(" #opt_name ")")
-
-typedef struct s_zbx_step
-{
- char *url;
- char *post;
-} zbx_step;
-
void test()
{
- int err = CURLE_OK;
- CURL *easyhandle = NULL;
- zbx_step *stp = NULL;
- zbx_step steps[] = {
- /* URL POST */
- {"http://localhost/", NULL},
-/* {"http://www.zabbix.com/forum/", NULL},
- {"http://www.zabbix.com/forum/login.php", "vb_login_username=Eugene"
- "&cookieuser="
- "&vb_login_password="
- "&s="
- "&do=login"
- "&forceredirect=1"
- "&vb_login_md5password=ec5287c45f0e70ec22d52e8bcbeeb640"
- "&vb_login_md5password_utf=ec5287c45f0e70ec22d52e8bcbeeb640"},
- {"http://www.zabbix.com/forum/", NULL},
- {"http://www.zabbix.com/forum/usercp.php?", NULL},
- {"http://www.zabbix.com/forum/login.php?do=logout", NULL},
- {"http://www.zabbix.com/forum/", NULL},*/
- {NULL, NULL}
- };
-
-
printf("-= Test Started =-\n");
-
- if(NULL != (easyhandle = curl_easy_init()))
- {
- ZBX_CURL_SET_OPT(CURLOPT_COOKIEFILE, "");
- ZBX_CURL_SET_OPT(CURLOPT_FOLLOWLOCATION, 1);
- ZBX_CURL_SET_OPT(CURLOPT_HEADERFUNCTION, HEADERFUNCTION);
- ZBX_CURL_SET_OPT(CURLOPT_WRITEFUNCTION, WRITEFUNCTION);
-
- for(stp=&steps[0];(*stp).url; stp++)
- {
- printf("****************************************************************\n");
- printf("{{ %s }}\n", stp->url);
- printf("****************************************************************\n");
-
- if(stp->post) ZBX_CURL_SET_OPT(CURLOPT_POSTFIELDS, stp->post);
-
- ZBX_CURL_SET_OPT(CURLOPT_URL, stp->url);
-
- if(CURLE_OK != curl_easy_perform(easyhandle)) /* post away! */
- XBX_CURL_ERR("curl_easy_perform()");
-
- fflush(stdout);
- }
- (void)curl_easy_cleanup(easyhandle);
- }
- else
- {
- XBX_CURL_ERR("curl_easy_init()");
- }
-
+
printf("\n-= Test completed =-\n");
}
#endif /* TEST */