From cca9b9f61d00f638b51ad9286da82865f63c4e08 Mon Sep 17 00:00:00 2001 From: sasha Date: Fri, 1 Aug 2008 08:19:27 +0000 Subject: - [DEV-195] added support of source ip address git-svn-id: svn://svn.zabbix.com/trunk@5858 97f52cf1-0a1b-0410-bd0e-c28be96e8082 --- src/zabbix_get/zabbix_get.c | 54 +++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 21 deletions(-) (limited to 'src/zabbix_get') diff --git a/src/zabbix_get/zabbix_get.c b/src/zabbix_get/zabbix_get.c index a9086e1f..c537cccb 100644 --- a/src/zabbix_get/zabbix_get.c +++ b/src/zabbix_get/zabbix_get.c @@ -27,30 +27,36 @@ char *progname = NULL; char title_message[] = "ZABBIX get - Communicate with ZABBIX agent"; -char usage_message[] = "[-hV] -s [-p] -k"; +char usage_message[] = "[-hV] -s [-p] [-I] -k"; #ifndef HAVE_GETOPT_LONG char *help_message[] = { "Options:", - " -p Specify port number of agent running on the host. Default is 10050.", - " -s Specify host name or IP address of a host.", - " -k Specify metric name (key) we want to retrieve.", - " -h give this help", - " -V display version number", + " -s --host Specify host name or IP address of a host.", + " -p --port Specify port number of agent running on the host. Default is 10050.", + " -I --source-address Specify source IP address", "", - "Example: zabbix_get -s127.0.0.1 -p10050 -k\"system[procload]\"", + " -k --key Specify metric name (key) we want to retrieve.", + "", + " -h --help Give this help", + " -V --version Display version number", + "", + "Example: zabbix_get -s127.0.0.1 -p10050 -k\"system.cpu.load[all,avg1]\"", 0 /* end of text */ }; #else char *help_message[] = { "Options:", - " -p --port Specify port number of agent running on the host. Default is 10050.", - " -s --host Specify host name or IP address of a host.", - " -k --key Specify metric name (key) we want to retrieve.", - " -h --help give this help", - " -V --version display version number", + " -s Specify host name or IP address of a host.", + " -p Specify port number of agent running on the host. Default is 10050.", + " -I Specify source IP address", + "", + " -k Specify metric name (key) we want to retrieve.", "", - "Example: zabbix_get -s127.0.0.1 -p10050 -k\"system[procload]\"", + " -h Give this help", + " -V Display version number", + "", + "Example: zabbix_get -s127.0.0.1 -p10050 -k\"system.cpu.load[all,avg1]\"", 0 /* end of text */ }; #endif @@ -60,17 +66,18 @@ char *help_message[] = { /* long options */ struct zbx_option longopts[] = { - {"port", 1, 0, 'p'}, - {"host", 1, 0, 's'}, - {"key", 1, 0, 'k'}, - {"help", 0, 0, 'h'}, - {"version", 0, 0, 'V'}, + {"host", 1, 0, 's'}, + {"port", 1, 0, 'p'}, + {"key", 1, 0, 'k'}, + {"source-address", 1, 0, 'I'}, + {"help", 0, 0, 'h'}, + {"version", 0, 0, 'V'}, {0,0,0,0} }; /* short options */ -static char shortopts[] = "k:p:s:hV"; +static char shortopts[] = "s:p:k:I:hV"; /* end of COMMAND LINE OPTIONS*/ @@ -129,6 +136,7 @@ void signal_handler( int sig ) * * ******************************************************************************/ static int get_value( + const char *source_ip, const char *host, unsigned short port, const char *key, @@ -144,7 +152,7 @@ static int get_value( *value = NULL; - if (SUCCEED == (ret = zbx_tcp_connect(&s, host, port, SENDER_TIMEOUT))) { + if (SUCCEED == (ret = zbx_tcp_connect(&s, source_ip, host, port, SENDER_TIMEOUT))) { zbx_snprintf(request, sizeof(request),"%s\n",key); if( SUCCEED == (ret = zbx_tcp_send(&s, request)) ) { @@ -185,6 +193,7 @@ int main(int argc, char **argv) char *value = NULL; char *host = NULL; char *key = NULL; + char *source_ip = NULL; char ch; progname = get_programm_name(argv[0]); @@ -201,6 +210,9 @@ int main(int argc, char **argv) case 's': host = strdup(zbx_optarg); break; + case 'I': + source_ip = strdup(zbx_optarg); + break; case 'h': help(); exit(-1); @@ -231,7 +243,7 @@ int main(int argc, char **argv) signal( SIGALRM, signal_handler ); #endif /* not WINDOWS */ - ret = get_value(host, port, key, &value); + ret = get_value(source_ip, host, port, key, &value); if(ret == SUCCEED) { -- cgit