summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-04-20 15:06:51 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-04-20 15:06:51 +0000
commit74dc9579c4c683ffc1c0d145f0bad129481b0907 (patch)
tree103c85eab5ed3259290b3841967151652bf502d1
parentf499e72b3edaeadd147e7b2527db8849cf3b5710 (diff)
downloadzabbix-74dc9579c4c683ffc1c0d145f0bad129481b0907.tar.gz
zabbix-74dc9579c4c683ffc1c0d145f0bad129481b0907.tar.xz
zabbix-74dc9579c4c683ffc1c0d145f0bad129481b0907.zip
- added 'command line' parameter for Linux proc.mem[] (Eugene)
- added parameter '-t key' for ZABBIX agent (Eugene) - added parameters '-h' '-v' for all ZABBIX applications (Eugene) git-svn-id: svn://svn.zabbix.com/trunk@2757 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r--ChangeLog3
-rwxr-xr-xdo11
-rw-r--r--include/common.h18
-rw-r--r--include/sysinfo.h4
-rw-r--r--src/libs/zbxcommon/str.c152
-rw-r--r--src/libs/zbxsysinfo/common/common.c39
-rw-r--r--src/libs/zbxsysinfo/linux/proc.c501
-rw-r--r--src/zabbix_agent/zabbix_agent.c95
-rw-r--r--src/zabbix_agent/zabbix_agentd.c69
-rw-r--r--src/zabbix_get/zabbix_get.c63
-rw-r--r--src/zabbix_sender/zabbix_sender.c19
-rw-r--r--src/zabbix_server/server.c49
-rw-r--r--src/zabbix_snmptrapper/zabbix_snmptrapper.c19
13 files changed, 651 insertions, 391 deletions
diff --git a/ChangeLog b/ChangeLog
index 65d11255..cbbe543e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
Changes for 1.1beta9:
+ - added 'command line' parameter for Linux proc.mem[] (Eugene)
+ - added parameter '-t key' for ZABBIX agent (Eugene)
+ - added parameters '-h' '-v' for all ZABBIX applications (Eugene)
- added support of aggregate items (Alexei)
- do not display disabled triggers and items in overview screens (Eugene)
- vertical hostnames in overview screens (Eugene)
diff --git a/do b/do
index 9feeb184..24a3765e 100755
--- a/do
+++ b/do
@@ -121,9 +121,14 @@ if [ "$dotest" = "yes" ]
then
echo "Testing..."
echo "Testing..." >> WARNINGS
- echo "------------------" >> WARNINGS
- echo " TEST RESULTS " >> WARNINGS
- echo "------------------" >> WARNINGS
+ ./src/zabbix_agent/zabbix_agent -v >> WARNINGS
+ ./src/zabbix_agent/zabbix_agentd -v >> WARNINGS
+ ./src/zabbix_get/zabbix_get -v >> WARNINGS
+ ./src/zabbix_sender/zabbix_sender -v >> WARNINGS
+ ./src/zabbix_server/zabbix_server -v >> WARNINGS
+ echo "------------------------" >> WARNINGS
+ echo " Agent TEST RESULTS " >> WARNINGS
+ echo "------------------------" >> WARNINGS
./src/zabbix_agent/zabbix_agentd -p >> WARNINGS
fi
diff --git a/include/common.h b/include/common.h
index f5c42006..85633e00 100644
--- a/include/common.h
+++ b/include/common.h
@@ -98,6 +98,7 @@
#define ZBX_FS_DBL "%f"
+#define ZABBIX_REVDATE "19 Apr 2006"
#define ZABBIX_VERSION "1.1beta8"
#define MAX_LOG_FILE_LEN (1024*1024)
@@ -364,6 +365,23 @@ AGENT_RESULT {
(res)->type &= ~AR_MESSAGE; \
}
+extern char *progname;
+extern char title_message[];
+extern char usage_message[];
+extern char *help_message[];
+
+void help();
+void usage();
+void version();
+
+#define ZBX_TASK_START 0
+#define ZBX_TASK_SHOW_HELP 1
+#define ZBX_TASK_SHOW_VERSION 2
+#define ZBX_TASK_PRINT_SUPPORTED 3
+#define ZBX_TASK_TEST_METRIC 4
+#define ZBX_TASK_SHOW_USAGE 5
+
+
void init_result(AGENT_RESULT *result);
int copy_result(AGENT_RESULT *src, AGENT_RESULT *dist);
void free_result(AGENT_RESULT *result);
diff --git a/include/sysinfo.h b/include/sysinfo.h
index d3c8d865..f062449d 100644
--- a/include/sysinfo.h
+++ b/include/sysinfo.h
@@ -44,13 +44,15 @@ ZBX_METRIC
/* flags for process */
-#define PF_TEST 1
+#define PROCESS_TEST 1
+#define PROCESS_USE_TEST_PARAM 2
int process(const char *in_command, unsigned flags, AGENT_RESULT *result);
void init_metrics();
void add_user_parameter(char *key,char *command);
void test_parameters(void);
+void test_parameter(char* key);
int check_ntp(char *host, int port, int *value_int);
diff --git a/src/libs/zbxcommon/str.c b/src/libs/zbxcommon/str.c
index 25cdb32c..090ac5af 100644
--- a/src/libs/zbxcommon/str.c
+++ b/src/libs/zbxcommon/str.c
@@ -3,6 +3,80 @@
#include <string.h>
#include <stdlib.h>
+#include "common.h"
+
+/******************************************************************************
+ * *
+ * Function: app_title *
+ * *
+ * Purpose: print title of application on stdout *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: title_message - is global variable which must be initialized *
+ * in each zabbix application *
+ * *
+ ******************************************************************************/
+static void app_title()
+{
+ printf("%s v%s (%s)\n", title_message, ZABBIX_VERSION, ZABBIX_REVDATE);
+}
+
+/******************************************************************************
+ * *
+ * Function: version *
+ * *
+ * Purpose: print version and compilation time of application on stdout *
+ * by application request with parameter '-v' *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ ******************************************************************************/
+void version()
+{
+ app_title();
+ printf("Compilation time: %s %s\n", __DATE__, __TIME__);
+}
+
+/******************************************************************************
+ * *
+ * Function: usage *
+ * *
+ * Purpose: print applicatin parameters on stdout *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: usage_message - is global variable which must be initialized *
+ * in each zabbix application *
+ * *
+ ******************************************************************************/
+void usage()
+{
+ printf("usage: %s %s\n", progname, usage_message);
+}
+
+/******************************************************************************
+ * *
+ * Function: help *
+ * *
+ * Purpose: print help of applicatin parameters on stdout by application *
+ * request with parameter '-h' *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: help_message - is global variable which must be initialized *
+ * in each zabbix application *
+ * *
+ ******************************************************************************/
+void help()
+{
+ char **p = help_message;
+
+ app_title();
+ usage();
+ while (*p) printf("%s\n", *p++);
+}
+
/******************************************************************************
* *
* Function: find_char *
@@ -10,27 +84,26 @@
* Purpose: locate a character in the string *
* *
* Parameters: str - string *
- * c - character to find *
+ * c - character to find *
* *
* Return value: position of the character *
* FAIL - otherwise *
* *
- * Author: Alexei Vladishev *
+ * Author: Eugene Grigorjev *
* *
- * Comments: *
+ * Comments: !!! beter use system functions like 'strchr' !!! *
* *
******************************************************************************/
int find_char(char *str,char c)
{
- int i;
+ char *p;
+ for(p = str; *p; p++)
+ if(*p == c) return (p - str);
- for(i=0;str[i]!=0;i++)
- {
- if(str[i]==c) return i;
- }
return FAIL;
}
+
/* Has to be rewritten to avoi malloc */
char *string_replace(char *str, const char *sub_str1, const char *sub_str2)
{
@@ -121,6 +194,25 @@ void del_zeroes(char *s)
}
+/******************************************************************************
+ * *
+ * Function: get_param *
+ * *
+ * Purpose: return parameter by index (num) from parameter list (param) *
+ * *
+ * Parameters: *
+ * param - parameter list *
+ * num - requested parameter index *
+ * buf - pointer og output buffer *
+ * maxlem - size of output buffer *
+ * *
+ * Return value: 1 - on error *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: delimeter vor parameters is ',' *
+ * *
+ ******************************************************************************/
int get_param(const char *param, int num, char *buf, int maxlen)
{
char tmp[MAX_STRING_LEN];
@@ -142,7 +234,7 @@ int get_param(const char *param, int num, char *buf, int maxlen)
{
tmp[i]='\0';
strncpy(buf, s, maxlen);
- tmp[i]=',';
+ tmp[i]=','; // restore source string
ret = 0;
break;
@@ -164,32 +256,22 @@ int get_param(const char *param, int num, char *buf, int maxlen)
return ret;
}
-/*
-int get_param(const char *param, int num, char *buf, int maxlen)
-{
- char tmp[MAX_STRING_LEN];
- char *s;
- int ret = 1;
- int i=0;
-
- strscpy(tmp,param);
- s=(char *)strtok(tmp,",");
- while(s!=NULL)
- {
- i++;
- if(i == num)
- {
- strncpy(buf,s,maxlen);
- ret = 0;
- break;
- }
- s=(char *)strtok(NULL,",");
- }
-
- return ret;
-}
-*/
-
+/******************************************************************************
+ * *
+ * Function: num_param *
+ * *
+ * Purpose: calculate count of parameters from parameter list (param) *
+ * *
+ * Parameters: *
+ * param - parameter list *
+ * *
+ * Return value: count of parameters *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: delimeter vor parameters is ',' *
+ * *
+ ******************************************************************************/
int num_param(const char *param)
{
int i;
diff --git a/src/libs/zbxsysinfo/common/common.c b/src/libs/zbxsysinfo/common/common.c
index ad08b079..b9e69297 100644
--- a/src/libs/zbxsysinfo/common/common.c
+++ b/src/libs/zbxsysinfo/common/common.c
@@ -306,6 +306,35 @@ int parse_command( /* return value: 0 - error; 1 - command without parameters; 2
return ret;
}
+void test_parameter(char* key)
+{
+ AGENT_RESULT result;
+
+ memset(&result, 0, sizeof(AGENT_RESULT));
+ process(key, PROCESS_TEST, &result);
+ if(result.type & AR_DOUBLE)
+ {
+ printf(" [d|" ZBX_FS_DBL "]", result.dbl);
+ }
+ if(result.type & AR_UINT64)
+ {
+ printf(" [u|" ZBX_FS_UI64 "]", result.ui64);
+ }
+ if(result.type & AR_STRING)
+ {
+ printf(" [s|%s]", result.str);
+ }
+ if(result.type & AR_MESSAGE)
+ {
+ printf(" [m|%s]", result.msg);
+ }
+
+ free_result(&result);
+ printf("\n");
+
+ fflush(stdout);
+}
+
void test_parameters(void)
{
int i;
@@ -315,7 +344,7 @@ void test_parameters(void)
for(i=0; 0 != commands[i].key; i++)
{
- process(commands[i].key, PF_TEST, &result);
+ process(commands[i].key, PROCESS_TEST | PROCESS_USE_TEST_PARAM, &result);
if(result.type & AR_DOUBLE)
{
printf(" [d|" ZBX_FS_DBL "]", result.dbl);
@@ -443,7 +472,7 @@ int process(const char *in_command, unsigned flags, AGENT_RESULT *result)
if(commands[i].flags & CF_USEUPARAM)
{
- if(flags & PF_TEST && commands[i].test_param)
+ if((flags & PROCESS_TEST) && (flags & PROCESS_USE_TEST_PARAM) && commands[i].test_param)
{
strncpy(usr_param, commands[i].test_param, MAX_STRING_LEN);
}
@@ -481,7 +510,7 @@ int process(const char *in_command, unsigned flags, AGENT_RESULT *result)
err = NOTSUPPORTED;
}
- if(flags & PF_TEST)
+ if(flags & PROCESS_TEST)
{
printf("%s", usr_cmd);
if(commands[i].flags & CF_USEUPARAM)
@@ -491,10 +520,10 @@ int process(const char *in_command, unsigned flags, AGENT_RESULT *result)
} else i = 0;
i += strlen(usr_cmd);
-#define COLUMN_2_X 45
+#define COLUMN_2_X 45 // max of spaces count
i = i > COLUMN_2_X ? 1 : (COLUMN_2_X - i);
- printf("%-*.*s", i, i, " ");
+ printf("%-*.*s", i, i, " "); // print spaces
}
if(err == NOTSUPPORTED)
diff --git a/src/libs/zbxsysinfo/linux/proc.c b/src/libs/zbxsysinfo/linux/proc.c
index 433a4e47..f43e8098 100644
--- a/src/libs/zbxsysinfo/linux/proc.c
+++ b/src/libs/zbxsysinfo/linux/proc.c
@@ -30,256 +30,285 @@
int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- DIR *dir;
- struct dirent *entries;
- struct stat buf;
- char filename[MAX_STRING_LEN];
- char line[MAX_STRING_LEN];
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+ char line[MAX_STRING_LEN];
+
+ char name1[MAX_STRING_LEN];
+ char name2[MAX_STRING_LEN];
+
+ char proccomm[MAX_STRING_LEN];
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
- char name1[MAX_STRING_LEN];
- char name2[MAX_STRING_LEN];
+ int comm_ok = 0;
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int do_task = DO_SUM;
- char procname[MAX_STRING_LEN];
- char usrname[MAX_STRING_LEN];
- char mode[MAX_STRING_LEN];
+ struct passwd *usrinfo = NULL;
+ zbx_uint64_t llvalue = 0;
- int proc_ok = 0;
- int usr_ok = 0;
- int do_task = DO_SUM;
+ FILE *f;
- struct passwd *usrinfo = NULL;
- zbx_uint64_t llvalue = 0;
+ zbx_uint64_t memsize;
+ int first=0;
+ zbx_uint64_t proccount = 0;
- FILE *f;
+ assert(result);
- zbx_uint64_t memsize;
- int first=0;
- zbx_uint64_t proccount = 0;
+ init_result(result);
- assert(result);
+ if(num_param(param) > 4)
+ {
+ return SYSINFO_RET_FAIL;
+ }
- init_result(result);
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ strscpy(mode, "sum");
+ }
+
+ if(strcmp(mode,"avg") == 0)
+ {
+ do_task = DO_AVG;
+ }
+ else if(strcmp(mode,"max") == 0)
+ {
+ do_task = DO_MAX;
+ }
+ else if(strcmp(mode,"min") == 0)
+ {
+ do_task = DO_MIN;
+ }
+ else if(strcmp(mode,"sum") == 0)
+ {
+ do_task = DO_SUM;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 4, proccomm, MAX_STRING_LEN) != 0)
+ {
+ proccomm[0] = '\0';
+ }
- if(num_param(param) > 3)
- {
- return SYSINFO_RET_FAIL;
- }
- if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
- {
- return SYSINFO_RET_FAIL;
- }
-
- if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
- {
- usrname[0] = 0;
- }
- else
- {
- if(usrname[0] != 0)
- {
- usrinfo = getpwnam(usrname);
- if(usrinfo == NULL)
- {
- /* incorrect user name */
- return SYSINFO_RET_FAIL;
- }
- }
- }
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
- {
- mode[0] = '\0';
- }
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ usr_ok = 0;
- if(mode[0] == '\0')
- {
- strscpy(mode, "sum");
- }
-
- if(strcmp(mode,"avg") == 0)
- {
- do_task = DO_AVG;
- }
- else if(strcmp(mode,"max") == 0)
- {
- do_task = DO_MAX;
- }
- else if(strcmp(mode,"min") == 0)
- {
- do_task = DO_MIN;
- }
- else if(strcmp(mode,"sum") == 0)
- {
- do_task = DO_SUM;
- }
- else
- {
- return SYSINFO_RET_FAIL;
- }
-
- dir=opendir("/proc");
- if(NULL == dir)
- {
- return SYSINFO_RET_FAIL;
- }
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/status",MAX_STRING_LEN);
- while((entries=readdir(dir))!=NULL)
- {
- proc_ok = 0;
- usr_ok = 0;
-
- strscpy(filename,"/proc/");
- strncat(filename,entries->d_name,MAX_STRING_LEN);
- strncat(filename,"/status",MAX_STRING_LEN);
-
- /* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
- /* Better approach: check if /proc/x/ is symbolic link */
- if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
- {
- continue;
- }
-
- if(stat(filename,&buf)==0)
- {
- f=fopen(filename,"r");
- if(f==NULL)
- {
- continue;
- }
-
- if(procname[0] != 0)
- {
- fgets(line,MAX_STRING_LEN,f);
- if(sscanf(line,"%s\t%s\n",name1,name2)==2)
- {
- if(strcmp(name1,"Name:") == 0)
- {
- if(strcmp(procname,name2)==0)
- {
- proc_ok = 1;
- }
- }
- }
-
- if(proc_ok == 0)
- {
- fclose(f);
- continue;
- }
- }
- else
- {
- proc_ok = 1;
- }
-
- if(usrinfo != NULL)
- {
- while(fgets(line, MAX_STRING_LEN, f) != NULL)
- {
-
- if(sscanf(line, "%s\t" ZBX_FS_UI64 "\n", name1, &llvalue) != 2)
- {
- continue;
- }
-
- if(strcmp(name1,"Uid:") != 0)
- {
- continue;
- }
-
- if(usrinfo->pw_uid == (uid_t)(llvalue))
- {
- usr_ok = 1;
- break;
- }
- }
- }
- else
- {
- usr_ok = 1;
- }
-
- if(proc_ok && usr_ok)
- {
- while(fgets(line, MAX_STRING_LEN, f) != NULL)
- {
+ /* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
+ /* Better approach: check if /proc/x/ is symbolic link */
+ if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
+ {
+ continue;
+ }
+
+ if(stat(filename,&buf)==0)
+ {
+ f=fopen(filename,"r");
+ if(f==NULL)
+ {
+ continue;
+ }
+
+ if(procname[0] != 0)
+ {
+ fgets(line,MAX_STRING_LEN,f);
+ if(sscanf(line,"%s\t%s\n",name1,name2)==2)
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
+
+ if(proc_ok == 0)
+ {
+ fclose(f);
+ continue;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t" ZBX_FS_UI64 "\n", name1, &llvalue) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"Uid:") != 0)
+ {
+ continue;
+ }
+
+ if(usrinfo->pw_uid == (uid_t)(llvalue))
+ {
+ usr_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ comm_ok = 0;
+ if(proccomm[0] != '\0')
+ {
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/cmdline",MAX_STRING_LEN);
+
+ if(stat(filename,&buf)!=0) continue;
+
+ f=fopen(filename,"r");
+ if(f==NULL) continue;
+
+ if(fgets(line, MAX_STRING_LEN, f) != NULL)
+ if(zbx_regexp_match(line,proccomm,NULL) != NULL)
+ comm_ok = 1;
+
+ fclose(f);
+ } else {
+ comm_ok = 1;
+ }
- if(sscanf(line, "%s\t" ZBX_FS_UI64 " %s\n", name1, &llvalue, name2) != 3)
- {
- continue;
- }
-
- if(strcmp(name1,"VmSize:") != 0)
- {
- continue;
- }
-
- proccount++;
-
- if(strcasecmp(name2, "kB") == 0)
- {
- llvalue <<= 10;
- }
- else if(strcasecmp(name2, "mB") == 0)
- {
- llvalue <<= 20;
- }
- else if(strcasecmp(name2, "GB") == 0)
- {
- llvalue <<= 30;
- }
- else if(strcasecmp(name2, "TB") == 0)
- {
- llvalue <<= 40;
- }
-
- if(first == 0)
- {
- memsize = llvalue;
- first = 1;
- }
- else
- {
- if(do_task == DO_MAX)
- {
- memsize = MAX(memsize, llvalue);
- }
- else if(do_task == DO_MIN)
- {
- memsize = MIN(memsize, llvalue);
- }
- else
- {
- memsize += llvalue;
- }
- }
-
- break;
- }
- }
-
-
- fclose(f);
- }
- }
- closedir(dir);
-
- if(first == 0)
- {
- /* incorrect process name */
- memsize = 0;
- }
-
- if(do_task == DO_AVG)
- {
- SET_DBL_RESULT(result, proccount == 0 ? 0 : ((double)memsize/(double)proccount));
- }
- else
- {
- SET_UI64_RESULT(result, memsize);
- }
- return SYSINFO_RET_OK;
+ if(proc_ok && usr_ok && comm_ok)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t" ZBX_FS_UI64 " %s\n", name1, &llvalue, name2) != 3)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"VmSize:") != 0)
+ {
+ continue;
+ }
+
+ proccount++;
+
+ if(strcasecmp(name2, "kB") == 0)
+ {
+ llvalue <<= 10;
+ }
+ else if(strcasecmp(name2, "mB") == 0)
+ {
+ llvalue <<= 20;
+ }
+ else if(strcasecmp(name2, "GB") == 0)
+ {
+ llvalue <<= 30;
+ }
+ else if(strcasecmp(name2, "TB") == 0)
+ {
+ llvalue <<= 40;
+ }
+
+ if(first == 0)
+ {
+ memsize = llvalue;
+ first = 1;
+ }
+ else
+ {
+ if(do_task == DO_MAX)
+ {
+ memsize = MAX(memsize, llvalue);
+ }
+ else if(do_task == DO_MIN)
+ {
+ memsize = MIN(memsize, llvalue);
+ }
+ else
+ {
+ memsize += llvalue;
+ }
+ }
+
+ break;
+ }
+ }
+
+
+ fclose(f);
+ }
+ }
+ closedir(dir);
+
+ if(first == 0)
+ {
+ /* incorrect process name */
+ memsize = 0;
+ }
+
+ if(do_task == DO_AVG)
+ {
+ SET_DBL_RESULT(result, proccount == 0 ? 0 : ((double)memsize/(double)proccount));
+ }
+ else
+ {
+ SET_UI64_RESULT(result, memsize);
+ }
+ return SYSINFO_RET_OK;
}
int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
diff --git a/src/zabbix_agent/zabbix_agent.c b/src/zabbix_agent/zabbix_agent.c
index 8aa7f3e3..99fbfe05 100644
--- a/src/zabbix_agent/zabbix_agent.c
+++ b/src/zabbix_agent/zabbix_agent.c
@@ -26,6 +26,20 @@
#include "security.h"
#include "zabbix_agent.h"
+char *progname = NULL;
+char title_message[] = "ZABBIX Agent";
+char usage_message[] = "[-vhp] [-c file] [-t metric]";
+char *help_message[] = {
+ "Options:",
+ " -c file Specify configuration file",
+ " -h give this help",
+ " -v display version number",
+ " -p print supported metrics and exit",
+ " -t test specified metric and exit",
+ 0 /* end of text */
+};
+
+char *CONFIG_FILE = NULL;
static char *CONFIG_HOSTS_ALLOWED = NULL;
static int CONFIG_TIMEOUT = AGENT_TIMEOUT;
int CONFIG_ENABLE_REMOTE_COMMANDS = 0;
@@ -70,28 +84,56 @@ void init_config(void)
{0}
};
- parse_cfg_file("/etc/zabbix/zabbix_agent.conf",cfg);
+ if(CONFIG_FILE == NULL)
+ {
+ CONFIG_FILE = strdup("/etc/zabbix/zabbix_agentd.conf");
+ }
+
+ parse_cfg_file(CONFIG_FILE,cfg);
}
-int main()
+int main(int argc, char **argv)
{
- char s[MAX_STRING_LEN];
- char value[MAX_STRING_LEN];
+ char s[MAX_STRING_LEN];
+ char value[MAX_STRING_LEN];
+ int ch;
+ int task = ZBX_TASK_START;
+ char *TEST_METRIC = NULL;
AGENT_RESULT result;
-
- memset(&result, 0, sizeof(AGENT_RESULT));
-#ifdef TEST_PARAMETERS
- init_metrics();
-/* init_config();*/
- test_parameters();
- return SUCCEED;
-#endif
+ memset(&result, 0, sizeof(AGENT_RESULT));
- signal( SIGINT, signal_handler );
- signal( SIGQUIT, signal_handler );
- signal( SIGTERM, signal_handler );
- signal( SIGALRM, signal_handler );
+ progname = argv[0];
+
+/* Parse the command-line. */
+ while ((ch = getopt(argc, argv, "c:hvpt:")) != EOF)
+ switch ((char) ch) {
+ case 'c':
+ CONFIG_FILE = optarg;
+ break;
+ case 'h':
+ help();
+ exit(-1);
+ break;
+ case 'v':
+ version();
+ exit(-1);
+ break;
+ case 'p':
+ if(task == ZBX_TASK_START)
+ task = ZBX_TASK_PRINT_SUPPORTED;
+ break;
+ case 't':
+ if(task == ZBX_TASK_START)
+ {
+ task = ZBX_TASK_TEST_METRIC;
+ TEST_METRIC = optarg;
+ }
+ break;
+ default:
+ task = ZBX_TASK_SHOW_USAGE;
+ break;
+ }
/* Must be before init_config() */
init_metrics();
@@ -100,6 +142,27 @@ int main()
/* Do not create debug files */
zabbix_open_log(LOG_TYPE_SYSLOG,LOG_LEVEL_EMPTY,NULL);
+ switch(task)
+ {
+ case ZBX_TASK_PRINT_SUPPORTED:
+ test_parameters();
+ exit(-1);
+ break;
+ case ZBX_TASK_TEST_METRIC:
+ test_parameter(TEST_METRIC);
+ exit(-1);
+ break;
+ case ZBX_TASK_SHOW_USAGE:
+ usage();
+ exit(-1);
+ break;
+ }
+
+ signal( SIGINT, signal_handler );
+ signal( SIGQUIT, signal_handler );
+ signal( SIGTERM, signal_handler );
+ signal( SIGALRM, signal_handler );
+
alarm(CONFIG_TIMEOUT);
if(check_security(0,CONFIG_HOSTS_ALLOWED,0) == FAIL)
diff --git a/src/zabbix_agent/zabbix_agentd.c b/src/zabbix_agent/zabbix_agentd.c
index f5201667..82bbb054 100644
--- a/src/zabbix_agent/zabbix_agentd.c
+++ b/src/zabbix_agent/zabbix_agentd.c
@@ -61,11 +61,26 @@
#define LISTENQ 1024
+
+char *progname = NULL;
+char title_message[] = "ZABBIX Agent (daemon)";
+char usage_message[] = "[-vhp] [-c file] [-t metric]";
+char *help_message[] = {
+ "Options:",
+ " -c file Specify configuration file",
+ " -h give this help",
+ " -v display version number",
+ " -p print supported metrics and exit",
+ " -t test specified metric and exit",
+ 0 /* end of text */
+};
+
static pid_t *pids=NULL;
int parent=0;
/* Number of processed requests */
int stats_request=0;
+
char *CONFIG_HOSTS_ALLOWED = NULL;
char *CONFIG_HOSTNAME = NULL;
char *CONFIG_FILE = NULL;
@@ -219,17 +234,6 @@ int add_parameter(char *value)
return SUCCEED;
}
-void usage(char *prog)
-{
- printf("zabbix_agentd - ZABBIX agent (daemon) v1.1\n");
- printf("Usage: %s [-h] [-c <file>] [-p]\n", prog);
- printf("\nOptions:\n");
- printf(" -c <file> Specify configuration file\n");
- printf(" -p Print supported metrics and exit\n");
- printf(" -h Help\n");
- exit(-1);
-}
-
void init_config(void)
{
struct cfg_line cfg[]=
@@ -259,7 +263,7 @@ void init_config(void)
if(CONFIG_FILE == NULL)
{
- CONFIG_FILE=strdup("/etc/zabbix/zabbix_agentd.conf");
+ CONFIG_FILE = strdup("/etc/zabbix/zabbix_agentd.conf");
}
parse_cfg_file(CONFIG_FILE,cfg);
@@ -466,10 +470,6 @@ pid_t child_passive_make(int i,int listenfd, int addrlen)
return 0;
}
-#define ZBX_START_DAEMON 0
-#define ZBX_USAGE 1
-#define ZBX_SUPPORTED 2
-
int main(int argc, char **argv)
{
int listenfd;
@@ -479,24 +479,40 @@ int main(int argc, char **argv)
char host[128];
int ch;
char *s;
- int task = ZBX_START_DAEMON;
+ int task = ZBX_TASK_START;
+ char *TEST_METRIC = NULL;
static struct sigaction phan;
+ progname = argv[0];
+
/* Parse the command-line. */
- while ((ch = getopt(argc, argv, "c:hp")) != EOF)
+ while ((ch = getopt(argc, argv, "c:hvpt:")) != EOF)
switch ((char) ch) {
case 'c':
CONFIG_FILE = optarg;
break;
case 'h':
- task = ZBX_USAGE;
+ help();
+ exit(-1);
+ break;
+ case 'v':
+ version();
+ exit(-1);
break;
case 'p':
- task = ZBX_SUPPORTED;
+ if(task == ZBX_TASK_START)
+ task = ZBX_TASK_PRINT_SUPPORTED;
+ break;
+ case 't':
+ if(task == ZBX_TASK_START)
+ {
+ task = ZBX_TASK_TEST_METRIC;
+ TEST_METRIC = optarg;
+ }
break;
default:
- task = ZBX_USAGE;
+ task = ZBX_TASK_SHOW_USAGE;
break;
}
@@ -513,12 +529,17 @@ int main(int argc, char **argv)
switch(task)
{
- case ZBX_SUPPORTED:
+ case ZBX_TASK_PRINT_SUPPORTED:
test_parameters();
exit(-1);
break;
- case ZBX_USAGE:
- usage(argv[0]);
+ case ZBX_TASK_TEST_METRIC:
+ test_parameter(TEST_METRIC);
+ exit(-1);
+ break;
+ case ZBX_TASK_SHOW_USAGE:
+ usage();
+ exit(-1);
break;
}
diff --git a/src/zabbix_get/zabbix_get.c b/src/zabbix_get/zabbix_get.c
index eb881069..f68c8d6f 100644
--- a/src/zabbix_get/zabbix_get.c
+++ b/src/zabbix_get/zabbix_get.c
@@ -43,6 +43,22 @@
#include "common.h"
+char *progname = NULL;
+char title_message[] = "ZABBIX get - Communicate with ZABBIX agent";
+char usage_message[] = "[-hv] -s<host name or IP> [-p<port number>] -k<key>";
+char *help_message[] = {
+ "Options:",
+ " -p <port number> Specify port number of agent running on the host. Default is 10050.",
+ " -s <host name or IP> Specify host name or IP address of a host.",
+ " -k <key of metric> Specify metric name (key) we want to retrieve.",
+ " -h give this help",
+ " -v display version number",
+ "",
+ "Example: zabbix_get -s127.0.0.1 -p10050 -k\"system[procload]\"",
+ 0 /* end of text */
+};
+
+
/******************************************************************************
* *
* Function: signal_handler *
@@ -75,35 +91,6 @@ static void signal_handler( int sig )
/******************************************************************************
* *
- * Function: usage *
- * *
- * Purpose: print information about command line parameters and exit *
- * *
- * Parameters: prog - name of process, normally 'zabbix_get' *
- * *
- * Return value: *
- * *
- * Author: Alexei Vladishev *
- * *
- * Comments: *
- * *
- ******************************************************************************/
-static void usage(char *prog)
-{
- printf("zabbix_get - Communicate with ZABBIX agent %s\n", ZABBIX_VERSION);
- printf("Usage: %s [-h] -s<host name or IP> [-p<port number>] -k<key>\n", prog);
- printf("\nOptions:\n");
- printf(" -p <port number> Specify port number of agent running on the host. Default is 10050.\n");
- printf(" -s <host name or IP> Specify host name or IP address of a host.\n");
- printf(" -k <key of metric> Specify metric name (key) we want to retrieve.\n");
- printf(" -h Help\n");
- printf("\nExample: zabbix_get -s127.0.0.1 -p10050 -k\"system[procload]\"\n");
- exit(-1);
-}
-
-
-/******************************************************************************
- * *
* Function: get_value *
* *
* Purpose: connect to ZABBIX agent and receive value for given key *
@@ -218,8 +205,10 @@ int main(int argc, char **argv)
char *key=NULL;
int ch;
+ progname = argv[0];
+
/* Parse the command-line. */
- while ((ch = getopt(argc, argv, "k:p:s:h")) != EOF)
+ while ((ch = getopt(argc, argv, "k:p:s:hv")) != EOF)
switch ((char) ch) {
case 'k':
key = optarg;
@@ -231,16 +220,22 @@ int main(int argc, char **argv)
host = optarg;
break;
case 'h':
- usage(argv[0]);
+ help();
+ exit(-1);
+ break;
+ case 'v':
+ version();
+ exit(-1);
break;
default:
- usage(argv[0]);
- break;
+ usage();
+ exit(-1);
+ break;
}
if( (host==NULL) || (key==NULL))
{
- usage(argv[0]);
+ usage();
ret = FAIL;
}
diff --git a/src/zabbix_sender/zabbix_sender.c b/src/zabbix_sender/zabbix_sender.c
index b6e978d7..9ab8d46e 100644
--- a/src/zabbix_sender/zabbix_sender.c
+++ b/src/zabbix_sender/zabbix_sender.c
@@ -39,6 +39,18 @@
#include "common.h"
+char *progname = NULL;
+char title_message[] = "ZABBIX send";
+char usage_message[] = "[<Zabbix server> <port> <server> <key> <value>]";
+char *help_message[] = {
+ "",
+ " If no arguments are given, zabbix_sender expects list of parameters",
+ " from standard input.",
+ "",
+ 0 /* end of text */
+};
+
+
void signal_handler( int sig )
{
if( SIGALRM == sig )
@@ -155,6 +167,8 @@ int main(int argc, char **argv)
char value[MAX_STRING_LEN];
char *s;
+ progname = argv[0];
+
signal( SIGINT, signal_handler );
signal( SIGQUIT, signal_handler );
signal( SIGTERM, signal_handler );
@@ -194,10 +208,7 @@ int main(int argc, char **argv)
}
else
{
- printf("Usage: zabbix_sender <Zabbix server> <port> <server> <key> <value>\n");
- printf("If no arguments are given, zabbix_sender expects list of parameters\n");
- printf("from standard input.\n");
-
+ help();
ret = FAIL;
}
diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c
index 24b2ccd5..dd0c364f 100644
--- a/src/zabbix_server/server.c
+++ b/src/zabbix_server/server.c
@@ -61,6 +61,17 @@
#define LISTENQ 1024
+char *progname = NULL;
+char title_message[] = "ZABBIX Server (daemon)";
+char usage_message[] = "[-hv] [-c <file>]";
+char *help_message[] = {
+ "Options:",
+ " -c file Specify configuration file",
+ " -h give this help",
+ " -v display version number",
+ 0 /* end of text */
+};
+
pid_t *pids=NULL;
int server_num=0;
@@ -269,31 +280,6 @@ void daemon_init(void)
/******************************************************************************
* *
- * Function: usage *
- * *
- * Purpose: print infor about command line parameters and exit *
- * *
- * Parameters: prog - name of process, normally 'zabbix_server' *
- * *
- * Return value: *
- * *
- * Author: Alexei Vladishev *
- * *
- * Comments: *
- * *
- ******************************************************************************/
-void usage(char *prog)
-{
- printf("zabbix_server - ZABBIX server process %s\n", ZABBIX_VERSION);
- printf("Usage: %s [-h] [-c <file>]\n", prog);
- printf("\nOptions:\n");
- printf(" -c <file> Specify configuration file. Default is /etc/zabbix/zabbix_server.conf\n");
- printf(" -h Help\n");
- exit(-1);
-}
-
-/******************************************************************************
- * *
* Function: init_config *
* *
* Purpose: parse config file and update configuration parameters *
@@ -492,18 +478,25 @@ int main(int argc, char **argv)
char sql[MAX_STRING_LEN];
DB_RESULT *result;
+ progname = argv[0];
/* Parse the command-line. */
- while ((ch = getopt(argc, argv, "c:h")) != EOF)
+ while ((ch = getopt(argc, argv, "c:hv")) != EOF)
switch ((char) ch) {
case 'c':
CONFIG_FILE = optarg;
break;
case 'h':
- usage(argv[0]);
+ help();
+ exit(-1);
+ break;
+ case 'v':
+ version();
+ exit(-1);
break;
default:
- usage(argv[0]);
+ usage();
+ exit(-1);
break;
}
diff --git a/src/zabbix_snmptrapper/zabbix_snmptrapper.c b/src/zabbix_snmptrapper/zabbix_snmptrapper.c
index 844e8a77..00dd3fcb 100644
--- a/src/zabbix_snmptrapper/zabbix_snmptrapper.c
+++ b/src/zabbix_snmptrapper/zabbix_snmptrapper.c
@@ -41,6 +41,17 @@
#include "log.h"
#include "cfg.h"
+char *progname = NULL;
+char title_message[] = "ZABBIX SNMP trapper";
+char usage_message[] = "[<Zabbix server> <port> <server:key> <value>]";
+char *help_message[] = {
+ "",
+ " If no arguments are given, zabbix_sender expects list of parameters",
+ " from standard input.",
+ "",
+ 0 /* end of text */
+};
+
int CONFIG_SUCKERD_FORKS =SUCKER_FORKS;
int CONFIG_NOTIMEWAIT =0;
int CONFIG_TIMEOUT =SUCKER_TIMEOUT;
@@ -216,6 +227,8 @@ int main(int argc, char **argv)
printf("The binary is no ready yet! To be available in Zabbix 1.0beta11.\n");
exit(-1);
+ progname = argv[0];
+
signal( SIGINT, signal_handler );
signal( SIGQUIT, signal_handler );
signal( SIGTERM, signal_handler );
@@ -268,11 +281,7 @@ int main(int argc, char **argv)
/* No parameters are given */
else
{
- printf("Number of parameters given [%d], expected [7]\n", argc);
- printf("Usage: zabbix_sender <Zabbix server> <port> <server:key> <value>\n");
- printf("If no arguments are given, zabbix_sender expects list of parameters\n");
- printf("from standard input.\n");
-
+ help();
ret = FAIL;
}