#include "zbxlog.h"
#include "zbxgetopt.h"
#include "zbxembed.h"
#include "zbxmutexs.h"
#include "zbxstr.h"
#include "zbxnix.h"
#include "zbxbincommon.h"
ZBX_GET_CONFIG_VAR2(const char *, const char *, zbx_progname, NULL)
static const char title_message[] = "zabbix_js";
static const char syslog_app_name[] = "zabbix_js";
static const char *usage_message[] = {
"-s script-file", "-p input-param", "[-l log-level]", "[-t timeout]", NULL,
"-s script-file", "-i input-file", "[-l log-level]", "[-t timeout]", NULL,
"-h", NULL,
"-V", NULL,
NULL
};
#define ZBX_SERVICE_NAME_LEN 64
char zabbix_event_source[ZBX_SERVICE_NAME_LEN] = APPLICATION_NAME;
#undef ZBX_SERVICE_NAME_LEN
#define JS_TIMEOUT_MIN 1
#define JS_TIMEOUT_MAX 60
#define JS_TIMEOUT_DEF ZBX_ES_TIMEOUT
#define JS_TIMEOUT_MIN_STR ZBX_STR(JS_TIMEOUT_MIN)
#define JS_TIMEOUT_MAX_STR ZBX_STR(JS_TIMEOUT_MAX)
#define JS_TIMEOUT_DEF_STR ZBX_STR(JS_TIMEOUT_DEF)
static const char *help_message[] = {
"Execute script using Zabbix embedded scripting engine.",
"",
"General options:",
" -s,--script script-file Specify the filename of script to execute. Specify - for",
" standard input.",
" -i,--input input-file Specify input parameter file name. Specify - for",
" standard input.",
" -p,--param input-param Specify input parameter",
" -w,--webdriver url Specify webdriver URL",
" -l,--loglevel log-level Specify log level",
" -t --timeout timeout Specify the timeout in seconds. Valid range: " JS_TIMEOUT_MIN_STR "-"
JS_TIMEOUT_MAX_STR " seconds",
" (default: " JS_TIMEOUT_DEF_STR " seconds)",
" -h --help Display this help message",
" -V --version Display version number",
"",
"Example:",
" zabbix_js -s script-file.js -p example",
NULL
};
struct zbx_option longopts[] =
{
{"script", 1, NULL, 's'},
{"input", 1, NULL, 'i'},
{"param", 1, NULL, 'p'},
{"webdriver", 1, NULL, 'w'},
{"loglevel", 1, NULL, 'l'},
{"timeout", 1, NULL, 't'},
{"help", 0, NULL, 'h'},
{"version", 0, NULL, 'V'},
{0}
};
static char shortopts[] = "s:i:p:hVl:t:w:";
static char *read_file(const char *filename, char **error)
{
char buffer[4096];
int fd;
ssize_t n;
char *data = NULL;