diff options
| author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-03-12 15:24:16 +0000 |
|---|---|---|
| committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-03-12 15:24:16 +0000 |
| commit | 883163bc42892ffe0885e94b701ef9da4da3cf70 (patch) | |
| tree | d9b8592102201e0396de3807a223d5b87c72f1bd /src/libs/zbxsysinfo/simple | |
| parent | e929cc4053168b46b81475715e98230eed01badc (diff) | |
| download | zabbix-883163bc42892ffe0885e94b701ef9da4da3cf70.tar.gz zabbix-883163bc42892ffe0885e94b701ef9da4da3cf70.tar.xz zabbix-883163bc42892ffe0885e94b701ef9da4da3cf70.zip | |
- fixed system.cpu.util[] (Eugene)
- improved configuration script (Eugene)
- fixed floats values (Eugene)
- developed agent result convertion (Eugene)
- more fixes
- TODO: WinXX agent \!\!\!
git-svn-id: svn://svn.zabbix.com/trunk@3886 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/libs/zbxsysinfo/simple')
| -rw-r--r-- | src/libs/zbxsysinfo/simple/Makefile.am | 7 | ||||
| -rw-r--r-- | src/libs/zbxsysinfo/simple/ntp.c | 369 | ||||
| -rw-r--r-- | src/libs/zbxsysinfo/simple/ntp.h | 24 | ||||
| -rw-r--r-- | src/libs/zbxsysinfo/simple/simple.c | 434 | ||||
| -rw-r--r-- | src/libs/zbxsysinfo/simple/simple.h | 29 |
5 files changed, 863 insertions, 0 deletions
diff --git a/src/libs/zbxsysinfo/simple/Makefile.am b/src/libs/zbxsysinfo/simple/Makefile.am new file mode 100644 index 00000000..6a50dc4c --- /dev/null +++ b/src/libs/zbxsysinfo/simple/Makefile.am @@ -0,0 +1,7 @@ +## Process this file with automake to produce Makefile.in + +noinst_LIBRARIES = libsimplesysinfo.a + +libsimplesysinfo_a_SOURCES = \ + simple.c simple.h \ + ntp.c ntp.h diff --git a/src/libs/zbxsysinfo/simple/ntp.c b/src/libs/zbxsysinfo/simple/ntp.c new file mode 100644 index 00000000..5023196f --- /dev/null +++ b/src/libs/zbxsysinfo/simple/ntp.c @@ -0,0 +1,369 @@ +/* +** 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 "sysinfo.h" +#include "zbxsock.h" +#include "log.h" +#include "cfg.h" + +#define NTP_SCALE 4294967296.0 /* 2^32, of course! */ + +#define NTP_PACKET_MIN 48 /* Without authentication */ +#define NTP_PACKET_MAX 68 /* With authentication (ignored) */ +#define NTP_DISP_FIELD 8 /* Offset of dispersion field */ +#define NTP_REFERENCE 16 /* Offset of reference timestamp */ +#define NTP_ORIGINATE 24 /* Offset of originate timestamp */ +#define NTP_RECEIVE 32 /* Offset of receive timestamp */ +#define NTP_TRANSMIT 40 /* Offset of transmit timestamp */ + +#define NTP_LI_FUDGE 0 /* The current 'status' */ +#define NTP_VERSION 3 /* The current version */ +#define NTP_VERSION_MAX 4 /* The maximum valid version */ +#define NTP_STRATUM 15 /* The current stratum as a server */ +#define NTP_STRATUM_MAX 15 /* The maximum valid stratum */ +#define NTP_POLLING 8 /* The current 'polling interval' */ +#define NTP_PRECISION 0 /* The current 'precision' - 1 sec. */ + +#define NTP_ACTIVE 1 /* NTP symmetric active request */ +#define NTP_PASSIVE 2 /* NTP symmetric passive response */ +#define NTP_CLIENT 3 /* NTP client request */ +#define NTP_SERVER 4 /* NTP server response */ +#define NTP_BROADCAST 5 /* NTP server broadcast */ + +#define NTP_INSANITY 3600.0 /* Errors beyond this are hopeless */ +#define RESET_MIN 15 /* Minimum period between resets */ +#define ABSCISSA 3.0 /* Scale factor for standard errors */ + +typedef struct ntp_data_s { + + unsigned char + status, + version, + mode, + stratum, + polling, + precision; + double + dispersion, + reference, + originate, + receive, + transmit, + current; + +} ntp_data; + +static void make_packet (ntp_data *data) +{ + data->status = NTP_LI_FUDGE<<6; + data->stratum = NTP_STRATUM; + data->reference = data->dispersion = 0.0; + + data->version = NTP_VERSION; + data->mode = 1; + data->polling = NTP_POLLING; + data->precision = NTP_PRECISION; + data->receive = data->originate = 0.0; + data->current = data->transmit = zbx_current_time(); +} + +static void pack_ntp (unsigned char *packet, int length, ntp_data *data) +{ + +/* Pack the essential data into an NTP packet, bypassing struct layout and +endian problems. Note that it ignores fields irrelevant to SNTP. */ + + int i, k; + double d; + + assert(length >= (NTP_TRANSMIT + 8)); + + memset(packet,0,(size_t)length); + + packet[0] = (data->status << 6) | (data->version << 3) | data->mode; + packet[1] = data->stratum; + packet[2] = data->polling; + packet[3] = data->precision; + + d = data->originate / NTP_SCALE; + for (i = 0; i < 8; ++i) { + if ((k = (int)(d *= 256.0)) >= 256) k = 255; + packet[NTP_ORIGINATE + i] = k; + d -= k; + } + + d = data->receive / NTP_SCALE; + for (i = 0; i < 8; ++i) { + if ((k = (int)(d *= 256.0)) >= 256) k = 255; + packet[NTP_RECEIVE + i] = k; + d -= k; + } + + d = data->transmit / NTP_SCALE; + for (i = 0; i < 8; ++i) { + if ((k = (int)(d *= 256.0)) >= 256) k = 255; + packet[NTP_TRANSMIT + i] = k; + d -= k; + } +} + +static void unpack_ntp (ntp_data *data, unsigned char *packet, int length) { + +/* Unpack the essential data from an NTP packet, bypassing struct layout and +endian problems. Note that it ignores fields irrelevant to SNTP. */ + + int i; + double d; + + memset(data, 0, sizeof(ntp_data)); + + if(length == 0) + return; + + assert(length >= (NTP_TRANSMIT + 8)); + + data->current = zbx_current_time(); /* Best to come first */ + data->status = (packet[0] >> 6); + data->version = (packet[0] >> 3) & 0x07; + data->mode = packet[0] & 0x07; + data->stratum = packet[1]; + data->polling = packet[2]; + data->precision = packet[3]; + + d = 0.0; + for (i = 0; i < 4; ++i) d = 256.0 * d + packet[NTP_DISP_FIELD + i]; + data->dispersion = d / 65536.0; + d = 0.0; + for (i = 0; i < 8; ++i) d = 256.0 * d + packet[NTP_REFERENCE + i]; + data->reference = d / NTP_SCALE; + d = 0.0; + for (i = 0; i < 8; ++i) d = 256.0 * d + packet[NTP_ORIGINATE + i]; + data->originate = d / NTP_SCALE; + d = 0.0; + for (i = 0; i < 8; ++i) d = 256.0 * d + packet[NTP_RECEIVE + i]; + data->receive = d / NTP_SCALE; + d = 0.0; + for (i = 0; i < 8; ++i) d = 256.0 * d + packet[NTP_TRANSMIT + i]; + data->transmit = d / NTP_SCALE; +} + +/* +static void display_data (ntp_data *data) { + + printf("sta = %d ver = %d mod = %d str = %d pol = %d dis = " ZBX_FS_DBL_EXT(6) " ref = " ZBX_FS_DBL_EXT(6) "\n", + data->status,data->version,data->mode,data->stratum,data->polling, + data->dispersion,data->reference); + printf("ori = " ZBX_FS_DBL_EXT(6) " rec = " ZBX_FS_DBL_EXT(6) "\n",data->originate, data->receive); + printf("tra = " ZBX_FS_DBL_EXT(6) " cur = " ZBX_FS_DBL_EXT(6) "\n",data->transmit, data->current); +} +*/ + +#if OFF + +static time_t convert_time (double value, int *millisecs) { + +/* Convert the time to the ANSI C form. */ + + time_t result = (time_t)value; + + if ((*millisecs = (int)(1000.0*(value-result))) >= 1000) { + *millisecs = 0; + ++result; + } + return result; +} + +/* !!! damaged function !!! for using correct tham !!! */ +static int format_time ( + char *text, + int length, + double offset, + double error, /* not USED */ + double drift, /* not USED */ + double drifterr /* not USED */ + ) { + +/* Format the current time into a string, with the extra information as +requested. Note that the rest of the program uses the correction needed, which +is what is printed for diagnostics, but this formats the error in the local +system for display to users. So the results from this are the negation of +those printed by the verbose options. */ + + int + milli, + len; + time_t + now; + struct tm + *gmt; + static const char + *months[] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + }; + + +/* Work out and format the current local time. Note that some semi-ANSI +systems do not set the return value from (s)printf. */ + + now = convert_time(zbx_time() + offset,&milli); + errno = 0; + + if ((gmt = localtime(&now)) == NULL) + { + zbx_error("unable to work out local time"); + return -1; + } + len = 24; + if (length <= len) + { + zbx_error("internal error calling format_time"); + return -1; + } + + errno = 0; + printf("%.4d %s %.2d %.2d:%.2d:%.2d.%.3d\n", + gmt->tm_year+1900,months[gmt->tm_mon],gmt->tm_mday, + gmt->tm_hour,gmt->tm_min,gmt->tm_sec,milli); + + return now; +} + +#endif /* OFF */ + +int check_ntp(char *host, unsigned short port, int *value_int) +{ + + ZBX_SOCKET s; + ZBX_SOCKADDR servaddr_in; + + int len; + unsigned char buf[MAX_STRING_LEN]; + + struct hostent *hp; + + ntp_data data; + unsigned char packet[NTP_PACKET_MIN]; + + *value_int = 0; + + if(NULL == (hp = zbx_gethost(host)) ) + { + return SYSINFO_RET_OK; + } + + servaddr_in.sin_family = AF_INET; + servaddr_in.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr; + servaddr_in.sin_port = htons(port); + + if( SOCKET_ERROR == (s = (ZBX_SOCKET)socket(AF_INET,SOCK_DGRAM,0)) ) + { + zabbix_log(LOG_LEVEL_DEBUG, "Cannot create socket for NTP server. [%s]", strerror_from_system(errno)); + return SYSINFO_RET_OK; + } + + if(SOCKET_ERROR == connect(s, (struct sockaddr *)&servaddr_in, sizeof(ZBX_SOCKADDR)) ) + { + switch (errno) + { + case EINTR: + zabbix_log(LOG_LEVEL_DEBUG, "Timeout while connecting to NTP server."); + break; + case EHOSTUNREACH: + zabbix_log(LOG_LEVEL_DEBUG, "No route to NTP server."); + break; + default: + zabbix_log(LOG_LEVEL_DEBUG, "Cannot connect to NTP server. [%s]", strerror(errno)); + break; + } + goto lbl_error; + } + + make_packet(&data); + +/* display_data(&data); */ + + pack_ntp(packet, sizeof(packet), &data); + + if(SOCKET_ERROR == zbx_sock_write(s, packet, sizeof(packet))) + { + switch (errno) + { + case EINTR: + zabbix_log(LOG_LEVEL_DEBUG, "Timeout while sending data to NTP server."); + break; + default: + zabbix_log(LOG_LEVEL_DEBUG, "Error while sending data to NTP server. [%s]", strerror(errno)); + break; + } + goto lbl_error; + } + + memset(buf, 0, sizeof(buf)); + + if( SOCKET_ERROR == (len = zbx_sock_read(s, buf, sizeof(buf), CONFIG_TIMEOUT))) + { + switch (errno) + { + case EINTR: + zabbix_log( LOG_LEVEL_DEBUG,"Timeout while receiving data from NTP server"); + break; + case ECONNRESET: + zabbix_log( LOG_LEVEL_DEBUG,"Connection to NTP server reseted by peer."); + break; + default: + zabbix_log( LOG_LEVEL_DEBUG,"Error while receiving data from NTP server [%s]", strerror(errno)); + break; + } + goto lbl_error; + } + + unpack_ntp(&data, buf, len); + + zbx_sock_close(s); + +/* display_data(&data); */ + +/* format_time(text,sizeof(text),offset,error,0.0,-1.0);*/ + +/* if (dispersion < data->dispersion) dispersion = data->dispersion; + x = data->receive-data->originate; + y = (data->transmit == 0.0 ? 0.0 : data->transmit-data->current); + *off = 0.5*(x+y); + *err = x-y; + x = data->current-data->originate; + if (0.5*x > *err) *err = 0.5*x; */ + +/* *value_int = format_time(text,sizeof(text),0,0,0.0,-1.0); */ + +#if OFF + *value_int = time(NULL); /* local time */ +#else + *value_int = (data.receive > 0) ? (int)(data.receive - ZBX_JAN_1970_IN_SEC) : 0; /* server time */ +#endif + + return SYSINFO_RET_OK; + +lbl_error: + zbx_sock_close(s); + + return SYSINFO_RET_OK; +} + diff --git a/src/libs/zbxsysinfo/simple/ntp.h b/src/libs/zbxsysinfo/simple/ntp.h new file mode 100644 index 00000000..2805b36a --- /dev/null +++ b/src/libs/zbxsysinfo/simple/ntp.h @@ -0,0 +1,24 @@ +/* +** 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. +**/ + +#if !defined(SYSINFO_SYMPLE_NTP_H_INCLUDED) + +int check_ntp(char *host, unsigned short port, int *value_int); + +#endif /* SYSINFO_SYMPLE_NTP_H_INCLUDED */ diff --git a/src/libs/zbxsysinfo/simple/simple.c b/src/libs/zbxsysinfo/simple/simple.c new file mode 100644 index 00000000..b5f0fac4 --- /dev/null +++ b/src/libs/zbxsysinfo/simple/simple.c @@ -0,0 +1,434 @@ +/* +** 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 "sysinfo.h" +#include "zbxsock.h" +#include "log.h" +#include "cfg.h" + +#include "../common/net.h" +#include "ntp.h" + +#include "simple.h" + +ZBX_METRIC parameters_simple[]= +/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */ + { + {"net.tcp.service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"}, + {"net.tcp.service.perf",CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"}, + {0} + }; + +#ifdef HAVE_LDAP + +static int check_ldap(char *hostname, short port, int *value_int) +{ + LDAP *ldap = NULL; + LDAPMessage *res = NULL; + LDAPMessage *msg = NULL; + BerElement *ber = NULL; + + char *attrs[2] = { "namingContexts", NULL }; + + char *attr = NULL; + char **valRes = NULL; + + int ldapErr = 0; + + assert(value_int); + + *value_int = 0; + + if(NULL == (ldap = ldap_init(hostname, port)) ) + { + zabbix_log( LOG_LEVEL_DEBUG, "LDAP - initialization failed [%s:%u]",hostname, port); + return SYSINFO_RET_OK; + } + + if( LDAP_SUCCESS != (ldapErr = ldap_search_s( + ldap, + "", + LDAP_SCOPE_BASE, + "(objectClass=*)", + attrs, + 0, + &res)) ) + { + zabbix_log( LOG_LEVEL_DEBUG, "LDAP - serching failed [%s] [%s]",hostname, ldap_err2string(ldapErr)); + goto lbl_ret; + } + + if(NULL == (msg = ldap_first_entry(ldap, res)) ) + { + zabbix_log( LOG_LEVEL_DEBUG, " LDAP - empty sort result. [%s] [%s]", hostname, ldap_err2string(ldapErr)); + goto lbl_ret; + } + + attr = ldap_first_attribute (ldap, msg, &ber); + + valRes = ldap_get_values( ldap, msg, attr ); + + *value_int = 1; + +lbl_ret: + if(valRes) ldap_value_free(valRes); + if(attr) ldap_memfree(attr); + if(ber) ber_free(ber, 0); + if(res) ldap_msgfree(res); + if(res) ldap_unbind(ldap); + + return SYSINFO_RET_OK; +} +#endif + + +/* + * 0- NOT OK + * 1 - OK + * */ +static int check_ssh(const char *hostname, short port, int *value_int) +{ + + ZBX_SOCKET s; + ZBX_SOCKADDR servaddr_in; + + struct hostent *hp; + + char buf[MAX_BUF_LEN]; + char buf2[MAX_BUF_LEN]; + char *ssh_server, + *ssh_proto; + + int len; + + assert(hostname); + assert(value_int); + + *value_int = 0; + + if(NULL == (hp = zbx_gethost(hostname)) ) + { + return SYSINFO_RET_OK; + } + + memset(&servaddr_in, 0, sizeof(ZBX_SOCKADDR)); + + servaddr_in.sin_family = AF_INET; + servaddr_in.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr; + servaddr_in.sin_port = htons(port); + + if(INVALID_SOCKET == (s = (ZBX_SOCKET)socket(AF_INET,SOCK_STREAM,0))) + { + zabbix_log( LOG_LEVEL_DEBUG, "Error in socket() [%s:%u] [%s]", hostname, port, strerror_from_system(errno)); + return SYSINFO_RET_OK; + } + + if(SOCKET_ERROR == connect(s,(struct sockaddr *)&servaddr_in,sizeof(ZBX_SOCKADDR))) + { + zabbix_log( LOG_LEVEL_WARNING, "Error in connect() [%s:%u] [%s]",hostname, port, strerror_from_system(errno)); + zbx_sock_close(s); + return SYSINFO_RET_OK; + } + + memset(buf, 0, sizeof(buf)); + + if(SOCKET_ERROR == (len = zbx_sock_read(s, buf, sizeof(buf)-1, CONFIG_TIMEOUT))) + { + zabbix_log( LOG_LEVEL_DEBUG, "Error in reading() [%s:%u] [%s]",hostname, port, strerror_from_system(errno)); + zbx_sock_close(s); + return SYSINFO_RET_OK; + } + + buf[sizeof(buf)-1] = '\0'; + + if ( strncmp(buf, "SSH", 3) == 0 ) + { + ssh_server = ssh_proto = buf + 4; + ssh_server += strspn (ssh_proto, "0123456789-. ") ; + ssh_server[-1] = '\0'; + + zbx_snprintf(buf2,sizeof(buf2),"SSH-%s-%s\n", ssh_proto, "zabbix_agent"); + *value_int = 1; + } + else + { + zbx_snprintf(buf2,sizeof(buf2),"0\n"); + *value_int = 0; + } + + if(SOCKET_ERROR == zbx_sock_write(s, buf2, (int)strlen(buf2))) + { + zabbix_log( LOG_LEVEL_DEBUG, "Error during sending [%s:%u] [%s]",hostname, port, strerror_from_system(errno)); + } + + zbx_sock_close(s); + + return SYSINFO_RET_OK; +} + +/* Example check_service[ssh], check_service[smtp,29],check_service[ssh,127.0.0.1,22]*/ +/* check_service[ssh,127.0.0.1,ssh] */ +int CHECK_SERVICE_PERF(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) +{ + unsigned short port=0; + char service[MAX_STRING_LEN]; + char ip[MAX_STRING_LEN]; + char str_port[MAX_STRING_LEN]; + + double start_time = 0; + + int ret = SYSINFO_RET_OK; + int value_int; + + assert(result); + + init_result(result); + + start_time = zbx_time(); + + if(num_param(param) > 3) + { + return SYSINFO_RET_FAIL; + } + + if(get_param(param, 1, service, MAX_STRING_LEN) != 0) + { + return SYSINFO_RET_FAIL; + } + + if(get_param(param, 2, ip, MAX_STRING_LEN) != 0) + { + ip[0] = '\0'; + } + + if(ip[0] == '\0') + { + strscpy(ip, "127.0.0.1"); + } + + if(get_param(param, 3, str_port, MAX_STRING_LEN) != 0) + { + str_port[0] = '\0'; + } + + if(str_port[0] != '\0') + { + port = atoi(str_port); + } + else + { + port = 0; + } + +/* printf("IP:[%s]",ip); + printf("Service:[%s]",service); + printf("Port:[%d]",port);*/ + + if(strcmp(service,"ssh") == 0) + { + if(port == 0) port=22; + ret=check_ssh(ip,port,&value_int); + } +#ifdef HAVE_LDAP + else if(strcmp(service,"ldap") == 0) + { + if(port == 0) port=389; + ret=check_ldap(ip,port,&value_int); + } +#endif + else if(strcmp(service,"smtp") == 0) + { + if(port == 0) port=25; + ret=tcp_expect(ip,port,NULL,"220","QUIT\n",&value_int); + } + else if(strcmp(service,"ftp") == 0) + { + if(port == 0) port=21; + ret=tcp_expect(ip,port,NULL,"220","",&value_int); + } + else if(strcmp(service,"http") == 0) + { + if(port == 0) port=80; + ret=tcp_expect(ip,port,NULL,NULL,"",&value_int); + } + else if(strcmp(service,"pop") == 0) + { + if(port == 0) port=110; + ret=tcp_expect(ip,port,NULL,"+OK","",&value_int); + } + else if(strcmp(service,"nntp") == 0) + { + if(port == 0) port=119; +/* 220 is incorrect */ +/* ret=tcp_expect(ip,port,"220","");*/ + ret=tcp_expect(ip,port,NULL,"200","",&value_int); + } + else if(strcmp(service,"imap") == 0) + { + if(port == 0) port=143; + ret=tcp_expect(ip,port,NULL,"* OK","a1 LOGOUT\n",&value_int); + } + else if(strcmp(service,"tcp") == 0) + { + if(port == 0) port=80; + ret=tcp_expect(ip,port,NULL,NULL,"",&value_int); + } + else + { + return SYSINFO_RET_FAIL; + } + + if(SYSINFO_RET_OK == ret) + { + if(value_int) + { + SET_DBL_RESULT(result, zbx_time() - start_time); + } + else + { + SET_DBL_RESULT(result, 0.0); + } + } + + + return ret; +} + +/* Example check_service[ssh], check_service[smtp,29],check_service[ssh,127.0.0.1,22]*/ +/* check_service[ssh,127.0.0.1,ssh] */ +int CHECK_SERVICE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) +{ + unsigned short port=0; + char service[MAX_STRING_LEN]; + char ip[MAX_STRING_LEN]; + char str_port[MAX_STRING_LEN]; + + int ret; + int value_int = 0; + + assert(result); + + init_result(result); + + if(num_param(param) > 3) + { + return SYSINFO_RET_FAIL; + } + + if(get_param(param, 1, service, MAX_STRING_LEN) != 0) + { + return SYSINFO_RET_FAIL; + } + + if(get_param(param, 2, ip, MAX_STRING_LEN) != 0) + { + ip[0] = '\0'; + } + + if(ip[0] == '\0') + { + strscpy(ip, "127.0.0.1"); + } + + if(get_param(param, 3, str_port, MAX_STRING_LEN) != 0) + { + str_port[0] = '\0'; + } + + if(str_port[0] != '\0') + { + port = atoi(str_port); + } + else + { + port = 0; + } + +/* printf("IP:[%s]",ip); + printf("Service:[%s]",service); + printf("Port:[%d]",port);*/ + + if(strcmp(service,"ssh") == 0) + { + if(port == 0) port=22; + ret=check_ssh(ip,port,&value_int); + } + else if(strcmp(service,"service.ntp") == 0) + { + if(port == 0) port=123; + ret=check_ntp(ip,port,&value_int); + } +#ifdef HAVE_LDAP + else if(strcmp(service,"ldap") == 0) + { + if(port == 0) port=389; + ret=check_ldap(ip,port,&value_int); + } +#endif + else if(strcmp(service,"smtp") == 0) + { + if(port == 0) port=25; + ret=tcp_expect(ip,port,NULL,"220","QUIT\n",&value_int); + } + else if(strcmp(service,"ftp") == 0) + { + if(port == 0) port=21; + ret=tcp_expect(ip,port,NULL,"220","",&value_int); + } + else if(strcmp(service,"http") == 0) + { + if(port == 0) port=80; + ret=tcp_expect(ip,port,NULL,NULL,"",&value_int); + } + else if(strcmp(service,"pop") == 0) + { + if(port == 0) port=110; + ret=tcp_expect(ip,port,NULL,"+OK","",&value_int); + } + else if(strcmp(service,"nntp") == 0) + { + if(port == 0) port=119; +/* 220 is incorrect */ +/* ret=tcp_expect(ip,port,"220","");*/ + ret=tcp_expect(ip,port,NULL,"200","",&value_int); + } + else if(strcmp(service,"imap") == 0) + { + if(port == 0) port=143; + ret=tcp_expect(ip,port,NULL,"* OK","a1 LOGOUT\n",&value_int); + } + else if(strcmp(service,"tcp") == 0) + { + if(port == 0) port=80; + ret=tcp_expect(ip,port,NULL,NULL,"",&value_int); + } + else + { + return SYSINFO_RET_FAIL; + } + + if(SYSINFO_RET_OK == ret) + { + SET_UI64_RESULT(result, value_int); + } + + return ret; +} + diff --git a/src/libs/zbxsysinfo/simple/simple.h b/src/libs/zbxsysinfo/simple/simple.h new file mode 100644 index 00000000..cc00e2ce --- /dev/null +++ b/src/libs/zbxsysinfo/simple/simple.h @@ -0,0 +1,29 @@ +/* +** 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. +**/ + +#if !defined(SYSINFO_SIMPLE_H_INCLUDED) + +#include "sysinfo.h" + +extern ZBX_METRIC parameters_simple[]; + +int CHECK_SERVICE_PERF(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result); +int CHECK_SERVICE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result); + +#endif /* SYSINFO_SIMPLE_H_INCLUDED */ |
