summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoralex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-03-24 19:18:47 +0000
committeralex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-03-24 19:18:47 +0000
commit2f6b4a23edbb0e8556e1e8deee20c99eb2d830fd (patch)
treedb9be0d8df2205f4b3191e9b54cfcfc5fe806ed8 /src
parent643a4913561d844a4292cb28d9d83d7a66dfe623 (diff)
downloadzabbix-2f6b4a23edbb0e8556e1e8deee20c99eb2d830fd.tar.gz
zabbix-2f6b4a23edbb0e8556e1e8deee20c99eb2d830fd.tar.xz
zabbix-2f6b4a23edbb0e8556e1e8deee20c99eb2d830fd.zip
- added server-side support of external checks. Thanks to Mike Nestor. (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@3918 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src')
-rw-r--r--src/zabbix_server/poller/Makefile.am1
-rw-r--r--src/zabbix_server/poller/checks_external.c114
-rw-r--r--src/zabbix_server/poller/checks_external.h36
-rw-r--r--src/zabbix_server/poller/poller.c5
-rw-r--r--src/zabbix_server/server.c7
5 files changed, 162 insertions, 1 deletions
diff --git a/src/zabbix_server/poller/Makefile.am b/src/zabbix_server/poller/Makefile.am
index f28cabf9..36d37997 100644
--- a/src/zabbix_server/poller/Makefile.am
+++ b/src/zabbix_server/poller/Makefile.am
@@ -8,4 +8,5 @@ libzbxpoller_a_SOURCES = \
checks_simple.c checks_simple.h \
checks_snmp.c checks_snmp.h \
checks_aggregate.c checks_aggregate.h \
+ checks_external.c \
poller.c poller.h
diff --git a/src/zabbix_server/poller/checks_external.c b/src/zabbix_server/poller/checks_external.c
new file mode 100644
index 00000000..b8be1dc4
--- /dev/null
+++ b/src/zabbix_server/poller/checks_external.c
@@ -0,0 +1,114 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "common.h"
+#include "checks_external.h"
+
+/******************************************************************************
+ * *
+ * Function: get_value_external *
+ * *
+ * Purpose: retrieve data from script executed on ZABBIX server *
+ * *
+ * Parameters: item - item we are interested in *
+ * *
+ * Return value: SUCCEED - data succesfully retrieved and stored in result *
+ * and result_str (as string) *
+ * NOTSUPPORTED - requested item is not supported *
+ * *
+ * Author: Mike Nestor *
+ * *
+ * Comments: *
+ * *
+ ************************************************** ****************************/
+int get_value_external(DB_ITEM *item, AGENT_RESULT *result)
+{
+ FILE* fp;
+ char scriptname[MAX_STRING_LEN];
+ char key[MAX_STRING_LEN];
+ char params[MAX_STRING_LEN];
+ char error[MAX_STRING_LEN];
+ char cmd[MAX_STRING_LEN];
+ char msg[MAX_STRING_LEN];
+ char *p,*p2;
+ int i;
+
+ int ret = SUCCEED;
+
+ zabbix_log( LOG_LEVEL_DEBUG, "In get_value_external([%s])",item->key);
+
+ init_result(result);
+
+ strscpy(key, item->key);
+ if((p2=strstr(key,"(")) != NULL)
+ {
+ *p2=0;
+ strscpy(scriptname,key);
+ *p2='(';
+ p2++;
+ }
+ else ret = NOTSUPPORTED;
+
+ if(ret == SUCCEED)
+ {
+ if((ret == SUCCEED) && (p=strstr(p2,")")) != NULL)
+ {
+ *p=0;
+ strscpy(params,p2);
+ *p=')';
+ p++;
+ }
+ else ret = NOTSUPPORTED;
+ }
+ else
+ {
+ zbx_snprintf(error,MAX_STRING_LEN-1,"External check [%s] is not supported", item->key);
+ zabbix_log( LOG_LEVEL_DEBUG, error);
+ SET_STR_RESULT(result, strdup(error));
+ return NOTSUPPORTED;
+ }
+
+ zbx_snprintf(cmd, MAX_STRING_LEN-1, "%s%s %s %s", CONFIG_EXTERNALSCRIPTS, scriptname, item->host_name, params);
+ zabbix_log( LOG_LEVEL_DEBUG, cmd );
+ if (NULL == (fp = popen(cmd, "r")))
+ {
+ zbx_snprintf(error,MAX_STRING_LEN-1,"External check [%s] is not supported, failed execution", item->key);
+ zabbix_log( LOG_LEVEL_DEBUG, error);
+ SET_STR_RESULT(result, strdup(error));
+ return NOTSUPPORTED;
+ }
+
+ /* we only care about the first line */
+ fgets(msg, sizeof(msg)-1, fp);
+ for (i = 0; i < MAX_STRING_LEN && msg[i] != 0; ++i)
+ {
+ if (msg[i] == '\n')
+ {
+ msg[i] = 0;
+ break;
+ }
+ }
+
+ set_result_type(result,item->value_type,strdup(msg));
+
+ /* cleanup */
+ pclose(fp);
+
+ return SUCCEED;
+}
diff --git a/src/zabbix_server/poller/checks_external.h b/src/zabbix_server/poller/checks_external.h
new file mode 100644
index 00000000..cdabbaab
--- /dev/null
+++ b/src/zabbix_server/poller/checks_external.h
@@ -0,0 +1,36 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_CHECKS_EXTERNAL_H
+#define ZABBIX_CHECKS_EXTERNAL_H
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+#include "db.h"
+#include "log.h"
+#include "sysinfo.h"
+
+extern char *CONFIG_EXTERNALSCRIPTS;
+
+extern int get_value_external(DB_ITEM *item, AGENT_RESULT *result);
+
+#endif
diff --git a/src/zabbix_server/poller/poller.c b/src/zabbix_server/poller/poller.c
index c4e56d4a..ef1b78e7 100644
--- a/src/zabbix_server/poller/poller.c
+++ b/src/zabbix_server/poller/poller.c
@@ -27,6 +27,7 @@
#include "checks_agent.h"
#include "checks_aggregate.h"
+#include "checks_external.h"
#include "checks_internal.h"
#include "checks_simple.h"
#include "checks_snmp.h"
@@ -81,6 +82,10 @@ int get_value(DB_ITEM *item, AGENT_RESULT *result)
{
res=get_value_aggregate(item, result);
}
+ else if(item->type == ITEM_TYPE_EXTERNAL)
+ {
+ res=get_value_external(item, result);
+ }
else
{
zabbix_log(LOG_LEVEL_WARNING, "Not supported item type:%d",
diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c
index 660fff6f..10a4379e 100644
--- a/src/zabbix_server/server.c
+++ b/src/zabbix_server/server.c
@@ -108,6 +108,7 @@ int CONFIG_UNREACHABLE_DELAY = 15;
int CONFIG_UNAVAILABLE_DELAY = 60;
int CONFIG_LOG_LEVEL = LOG_LEVEL_WARNING;
char *CONFIG_ALERT_SCRIPTS_PATH = NULL;
+char *CONFIG_EXTERNALSCRIPTS = NULL;
char *CONFIG_FPING_LOCATION = NULL;
char *CONFIG_DBHOST = NULL;
char *CONFIG_DBNAME = NULL;
@@ -170,6 +171,7 @@ void init_config(void)
{"PidFile",&APP_PID_FILE,0,TYPE_STRING,PARM_OPT,0,0},
{"LogFile",&CONFIG_LOG_FILE,0,TYPE_STRING,PARM_OPT,0,0},
{"AlertScriptsPath",&CONFIG_ALERT_SCRIPTS_PATH,0,TYPE_STRING,PARM_OPT,0,0},
+ {"ExternalScripts",&CONFIG_EXTERNALSCRIPTS,0,TYPE_STRING,PARM_OPT,0,0},
{"DBHost",&CONFIG_DBHOST,0,TYPE_STRING,PARM_OPT,0,0},
{"DBName",&CONFIG_DBNAME,0,TYPE_STRING,PARM_MAND,0,0},
{"DBUser",&CONFIG_DBUSER,0,TYPE_STRING,PARM_OPT,0,0},
@@ -205,7 +207,10 @@ void init_config(void)
{
CONFIG_FPING_LOCATION=strdup("/usr/sbin/fping");
}
-
+ if(CONFIG_EXTERNALSCRIPTS == NULL)
+ {
+ CONFIG_EXTERNALSCRIPTS=strdup("/etc/zabbix/externalscripts");
+ }
}
int tcp_listen(const char *host, int port, socklen_t *addrlenp)