--- zabbix_sender.c_old	2015-08-10 14:56:47.000000000 +0600
+++ zabbix_sender.c	2015-10-26 00:50:30.090410622 +0600
@@ -29,7 +29,7 @@
 const char	*progname = NULL;
 const char	title_message[] = "Zabbix Sender";
 const char	syslog_app_name[] = "zabbix_sender";
-const char	usage_message[] = "[-Vhv] {[-zpsI] -ko | [-zpI] -T -i <file> -r} [-c <file>]";
+const char	usage_message[] = "[-Vhv] {[-zpsI] -ko | [-zpI] -T -N -i <file> -r} [-c <file>]";
 
 const char	*help_message[] = {
 	"Options:",
@@ -49,6 +49,9 @@
 	"  -T --with-timestamps                 Each line of file contains whitespace delimited: <hostname> <key> <timestamp> <value>",
 	"                                       This can be used with --input-file option",
 	"                                       Timestamp should be specified in Unix timestamp format",
+	"  -N --with-ns                         Each line of file contains whitespace delimited: <hostname> <key> <timestamp> <ns> <value>",
+	"                                       This can be used with --input-file option",
+	"                                       NS is nanoseconds",
 	"  -r --real-time                       Send metrics one by one as soon as they are received",
 	"                                       This can be used when reading from standard input",
 	"",
@@ -74,6 +77,7 @@
 	{"value",		1,	NULL,	'o'},
 	{"input-file",		1,	NULL,	'i'},
 	{"with-timestamps",	0,	NULL,	'T'},
+	{"with-ns",			0,	NULL,	'N'},
 	{"real-time",		0,	NULL,	'r'},
 	{"verbose",		0,	NULL,	'v'},
 	{"help",		0,	NULL,	'h'},
@@ -82,7 +86,7 @@
 };
 
 /* short options */
-static char	shortopts[] = "c:I:z:p:s:k:o:Ti:rvhV";
+static char	shortopts[] = "c:I:z:p:s:k:o:TNi:rvhV";
 
 /* end of COMMAND LINE OPTIONS */
 
@@ -90,6 +94,7 @@
 
 static char	*INPUT_FILE = NULL;
 static int	WITH_TIMESTAMPS = 0;
+static int	WITH_NS = 0;
 static int	REAL_TIME = 0;
 
 static char	*CONFIG_SOURCE_IP = NULL;
@@ -441,6 +446,9 @@
 			case 'T':
 				WITH_TIMESTAMPS = 1;
 				break;
+			case 'N':
+				WITH_NS = 1;
+				break;
 			case 'r':
 				REAL_TIME = 1;
 				break;
@@ -472,7 +480,7 @@
 {
 	FILE			*in;
 	char			in_line[MAX_BUFFER_LEN], hostname[MAX_STRING_LEN], key[MAX_STRING_LEN],
-				key_value[MAX_BUFFER_LEN], clock[32];
+				key_value[MAX_BUFFER_LEN], clock[32], ns[32];
 	int			total_count = 0, succeed_count = 0, buffer_count = 0, read_more = 0, ret = FAIL;
 	double			last_send = 0;
 	const char		*p;
@@ -578,6 +586,16 @@
 				}
 			}
 
+			if (1 == WITH_NS)
+			{
+				if ('\0' == *p || NULL == (p = get_string(p, ns, sizeof(ns))) || '\0' == *ns)
+				{
+					zabbix_log(LOG_LEVEL_WARNING, "[line %d] 'NS' required", total_count);
+					ret = FAIL;
+					break;
+				}
+			}
+
 			if ('\0' != *p && '"' != *p)
 			{
 				zbx_strlcpy(key_value, p, sizeof(key_value));
@@ -601,6 +619,8 @@
 			zbx_json_addstring(&sentdval_args.json, ZBX_PROTO_TAG_VALUE, key_value, ZBX_JSON_TYPE_STRING);
 			if (1 == WITH_TIMESTAMPS)
 				zbx_json_adduint64(&sentdval_args.json, ZBX_PROTO_TAG_CLOCK, atoi(clock));
+			if (1 == WITH_NS)
+				zbx_json_adduint64(&sentdval_args.json, ZBX_PROTO_TAG_NS, atoi(ns));
 			zbx_json_close(&sentdval_args.json);
 
 			succeed_count++;
@@ -640,6 +660,9 @@
 				if (1 == WITH_TIMESTAMPS)
 					zbx_json_adduint64(&sentdval_args.json, ZBX_PROTO_TAG_CLOCK, (int)time(NULL));
 
+				if (1 == WITH_NS)
+					zbx_json_adduint64(&sentdval_args.json, ZBX_PROTO_TAG_NS, 0);
+
 				last_send = zbx_time();
 
 				ret = update_exit_status(ret, zbx_thread_wait(zbx_thread_start(send_value, &thread_args)));
@@ -659,6 +682,9 @@
 			if (1 == WITH_TIMESTAMPS)
 				zbx_json_adduint64(&sentdval_args.json, ZBX_PROTO_TAG_CLOCK, (int)time(NULL));
 
+			if (1 == WITH_NS)
+				zbx_json_adduint64(&sentdval_args.json, ZBX_PROTO_TAG_NS, 0);
+
 			ret = update_exit_status(ret, zbx_thread_wait(zbx_thread_start(send_value, &thread_args)));
 		}
 
