summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-06-25 12:02:22 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-06-25 12:02:22 +0000
commit80312add3bb092cd15615d8c0ed715628e747164 (patch)
tree70be5fe6c3897686a3d1fe7ff77a80123baa4cf1 /src
parent94e492c52f83dbfa3ffa15b96bdabe19aee0d600 (diff)
downloadzabbix-80312add3bb092cd15615d8c0ed715628e747164.tar.gz
zabbix-80312add3bb092cd15615d8c0ed715628e747164.tar.xz
zabbix-80312add3bb092cd15615d8c0ed715628e747164.zip
- merged rev. 4357:4358 branches/1.4.1/ (Eugene) [fixed and improved log monitoring]
git-svn-id: svn://svn.zabbix.com/trunk@4359 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src')
-rw-r--r--src/zabbix_agent/active.c113
-rw-r--r--src/zabbix_agent/logfiles.c88
2 files changed, 128 insertions, 73 deletions
diff --git a/src/zabbix_agent/active.c b/src/zabbix_agent/active.c
index e5ec81c5..bcfc1262 100644
--- a/src/zabbix_agent/active.c
+++ b/src/zabbix_agent/active.c
@@ -130,7 +130,7 @@ static void add_check(char *key, int refresh, long lastlogsize)
active_metrics[i].nextcheck = 0;
}
active_metrics[i].refresh = refresh;
- active_metrics[i].lastlogsize = lastlogsize;
+ /* active_metrics[i].lastlogsize = lastlogsize; *//* don't update lastlogsize for exsted items */
active_metrics[i].status = ITEM_STATUS_ACTIVE;
return;
@@ -379,11 +379,11 @@ static int send_value(
static int process_active_checks(char *server, unsigned short port)
{
- register int i, count;
+ register int i, s_count, p_count;
char **pvalue;
- int now, ret = SUCCEED;
+ int now, send_err = SUCCEED, ret = SUCCEED;
unsigned long timestamp;
char *source = NULL;
@@ -402,7 +402,7 @@ static int process_active_checks(char *server, unsigned short port)
now = (int)time(NULL);
- for(i=0; NULL != active_metrics[i].key && SUCCEED == ret; i++)
+ for(i=0; NULL != active_metrics[i].key && SUCCEED == send_err; i++)
{
if(active_metrics[i].nextcheck > now) continue;
if(active_metrics[i].status != ITEM_STATUS_ACTIVE) continue;
@@ -419,18 +419,21 @@ static int process_active_checks(char *server, unsigned short port)
filename = params;
- if( (pattern = strchr(params, ',')) )
+ if( (pattern = strchr(params, ',')) ) /* TODO: rewrite for get_param */
{
*pattern = '\0';
pattern++;
}
- count = 0;
- while( 0 == process_log(filename, &active_metrics[i].lastlogsize, &value) )
+ s_count = 0;
+ p_count = 0;
+ while( SUCCEED == (ret = process_log(filename, &active_metrics[i].lastlogsize, &value)) )
{
- if(!pattern || zbx_regexp_match(value, pattern, NULL) != NULL)
+ if( !value ) /* EOF */ break;
+
+ if( !pattern || NULL != zbx_regexp_match(value, pattern, NULL) )
{
- ret = send_value(
+ send_err = send_value(
server,
port,
CONFIG_HOSTNAME,
@@ -442,23 +445,38 @@ static int process_active_checks(char *server, unsigned short port)
NULL
);
- if( strstr(value,"ZBX_NOTSUPPORTED") )
- {
- active_metrics[i].status = ITEM_STATUS_NOTSUPPORTED;
- zabbix_log( LOG_LEVEL_WARNING, "Active check [%s] is not supported. Disabled.",
- active_metrics[i].key);
-
- zbx_free(value);
- break;
- }
-
+ s_count++;
}
+ p_count++;
+
zbx_free(value);
- count++;
/* Do not flood ZABBIX server if file grows too fast */
- if(count >= (MAX_LINES_PER_SECOND * active_metrics[i].refresh)) break;
+ if(s_count >= (MAX_LINES_PER_SECOND * active_metrics[i].refresh)) break;
+
+ /* Do not flood local system if file grows too fast */
+ if(p_count >= (4 * MAX_LINES_PER_SECOND * active_metrics[i].refresh)) break;
+ }
+
+ if( FAIL == ret )
+ {
+ active_metrics[i].status = ITEM_STATUS_NOTSUPPORTED;
+ zabbix_log( LOG_LEVEL_WARNING, "Active check [%s] is not supported. Disabled.",
+ active_metrics[i].key);
+
+ send_err = send_value(
+ server,
+ port,
+ CONFIG_HOSTNAME,
+ active_metrics[i].key,
+ "ZBX_NOTSUPPORTED",
+ &active_metrics[i].lastlogsize,
+ NULL,
+ NULL,
+ NULL
+ );
}
+
}while(0); /* simple try realization */
}
/* Special processing for eventlog */
@@ -479,12 +497,13 @@ static int process_active_checks(char *server, unsigned short port)
pattern++;
}
- count = 0;
- while( 0 == process_eventlog(filename,&active_metrics[i].lastlogsize, &timestamp, &source, &severity, &value) )
+ s_count = 0;
+ p_count = 0;
+ while( SUCCEED == (ret = process_eventlog(filename,&active_metrics[i].lastlogsize, &timestamp, &source, &severity, &value)) )
{
- if(!pattern || NULL != zbx_regexp_match(value, pattern, NULL) )
+ if( !pattern || NULL != zbx_regexp_match(value, pattern, NULL) )
{
- ret = send_value(
+ send_err = send_value(
server,
port,
CONFIG_HOSTNAME,
@@ -496,23 +515,37 @@ static int process_active_checks(char *server, unsigned short port)
&severity
);
- zbx_free(source);
-
- if( strstr(value,"ZBX_NOTSUPPORTED") )
- {
- active_metrics[i].status = ITEM_STATUS_NOTSUPPORTED;
- zabbix_log( LOG_LEVEL_WARNING, "Active check [%s] is not supported. Disabled.",
- active_metrics[i].key);
-
- zbx_free(value);
- break;
- }
+ s_count++;
}
+ p_count++;
+
+ zbx_free(source);
zbx_free(value);
- count++;
/* Do not flood ZABBIX server if file grows too fast */
- if(count >= (MAX_LINES_PER_SECOND * active_metrics[i].refresh)) break;
+ if(s_count >= (MAX_LINES_PER_SECOND * active_metrics[i].refresh)) break;
+
+ /* Do not flood local system if file grows too fast */
+ if(p_count >= (4 * MAX_LINES_PER_SECOND * active_metrics[i].refresh)) break;
+ }
+
+ if( FAIL == ret )
+ {
+ active_metrics[i].status = ITEM_STATUS_NOTSUPPORTED;
+ zabbix_log( LOG_LEVEL_WARNING, "Active check [%s] is not supported. Disabled.",
+ active_metrics[i].key);
+
+ send_err = send_value(
+ server,
+ port,
+ CONFIG_HOSTNAME,
+ active_metrics[i].key,
+ "ZBX_NOTSUPPORTED",
+ &active_metrics[i].lastlogsize,
+ NULL,
+ NULL,
+ NULL
+ );
}
}while(0); /* simple try realization NOTE: never loop */
}
@@ -528,7 +561,7 @@ static int process_active_checks(char *server, unsigned short port)
{
zabbix_log( LOG_LEVEL_DEBUG, "For key [%s] received value [%s]", active_metrics[i].key, *pvalue);
- ret = send_value(
+ send_err = send_value(
server,
port,
CONFIG_HOSTNAME,
@@ -540,7 +573,7 @@ static int process_active_checks(char *server, unsigned short port)
NULL
);
- if( strstr(*pvalue,"ZBX_NOTSUPPORTED") )
+ if( 0 == strcmp(*pvalue,"ZBX_NOTSUPPORTED") )
{
active_metrics[i].status = ITEM_STATUS_NOTSUPPORTED;
zabbix_log( LOG_LEVEL_WARNING, "Active check [%s] is not supported. Disabled.", active_metrics[i].key);
diff --git a/src/zabbix_agent/logfiles.c b/src/zabbix_agent/logfiles.c
index 9ae00bed..ec3b49df 100644
--- a/src/zabbix_agent/logfiles.c
+++ b/src/zabbix_agent/logfiles.c
@@ -22,6 +22,27 @@
#include "log.h"
#include "logfiles.h"
+/******************************************************************************
+ * *
+ * Function: process_log *
+ * *
+ * Purpose: Get message from logfile *
+ * *
+ * Parameters: filename - logfile name *
+ * lastlogsize - offset for message *
+ * value - pointer for logged message *
+ * *
+ * Return value: returns SUCCEED on succesfull reading, *
+ * FAIL on other cases *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: *
+ * This function allocate memory for 'value', because use zbx_free. *
+ * Return SUCCEED and NULL value if end of file received. *
+ * *
+ * *
+ ******************************************************************************/
int process_log(
char *filename,
long *lastlogsize,
@@ -30,6 +51,7 @@ int process_log(
{
FILE *f = NULL;
struct stat buf;
+ int ret = FAIL;
assert(filename);
assert(lastlogsize);
@@ -38,47 +60,47 @@ int process_log(
zabbix_log( LOG_LEVEL_DEBUG, "In process log (%s,%li)", filename, *lastlogsize);
/* Handling of file shrinking */
- if(stat(filename,&buf) == 0)
+ if( 0 != stat(filename,&buf) )
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Cannot open [%s] [%s]", filename, strerror(errno));
+ }
+ else
{
if(buf.st_size<*lastlogsize)
{
*lastlogsize=0;
}
- }
- else
- {
- zabbix_log( LOG_LEVEL_WARNING, "Cannot open [%s] [%s]", filename, strerror(errno));
- *value = strdup("ZBX_NOTSUPPORTED\n");
- return 1;
- }
- if(NULL == (f = fopen(filename,"r") ))
- {
- zabbix_log( LOG_LEVEL_WARNING, "Cannot open [%s] [%s]", filename, strerror(errno));
- *value = strdup("ZBX_NOTSUPPORTED\n");
- return 1;
- }
-
- if(-1 == fseek(f,*lastlogsize,SEEK_SET))
- {
- zabbix_log( LOG_LEVEL_WARNING, "Cannot set postition to [%li] for [%s] [%s]", *lastlogsize, filename, strerror(errno));
- *value = strdup("ZBX_NOTSUPPORTED\n");
- zbx_fclose(f);
- return 1;
- }
+ if(NULL == (f = fopen(filename,"r") ))
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Cannot open [%s] [%s]", filename, strerror(errno));
+ }
+ else
+ {
+ if(-1 == fseek(f,*lastlogsize,SEEK_SET))
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Cannot set postition to [%li] for [%s] [%s]", *lastlogsize, filename, strerror(errno));
+ }
+ else
+ {
+ *value = zbx_malloc(*value, MAX_BUF_LEN);
+ memset(*value, 0, MAX_BUF_LEN);
- *value = zbx_malloc(*value, MAX_BUF_LEN);
- memset(*value, 0, MAX_BUF_LEN);
+ if(NULL == fgets(*value, MAX_BUF_LEN-1, f))
+ {
+ /* EOF */
+ zbx_free(*value);
+ }
+ else
+ {
+ *lastlogsize += (long)strlen(*value);
+ }
- if(NULL == fgets(*value, MAX_BUF_LEN-1, f))
- {
- /* EOF */
- zbx_fclose(f);
- return 1;
+ ret = SUCCEED;
+ }
+ zbx_fclose(f);
+ }
}
- zbx_fclose(f);
-
- *lastlogsize += (long)strlen(*value);
- return 0;
+ return ret;
}