diff --git a/.gitattributes b/.gitattributes index 2bce088de453..c3331df045d2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -38,7 +38,6 @@ create/data/images/UPS_small.png -text svneol=unset#unset create/data/images/Workstation.png -text svneol=unset#unset create/data/images/Workstation_small.png -text svneol=unset#unset create/schema/gen_php.php -text -docs/README -text frontends/php/api/.htaccess -text frontends/php/api/classes/class.apiexception.php -text frontends/php/api/classes/class.caction.php -text @@ -411,7 +410,6 @@ misc/init.d/fedora/core5/zabbix_agentd -text misc/init.d/freebsd/zabbix_agentd -text misc/init.d/freebsd/zabbix_server -text misc/init.d/tru64/zabbix_server -text -/splint -text src/libs/zbxalgo/Makefile.am -text src/libs/zbxalgo/algodefs.c -text src/libs/zbxalgo/binaryheap.c -text diff --git a/AUTHORS b/AUTHORS index 283ee601197a..0e6e59c3177d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3,8 +3,3 @@ Core developers * Alexei Vladishev Initial idea. - -Contributors -=============== - -Please, see Zabbix Manual for a complete list of contributors. diff --git a/FAQ b/FAQ deleted file mode 100644 index ab1f45f5bc5a..000000000000 --- a/FAQ +++ /dev/null @@ -1,10 +0,0 @@ - Frequently Asked Questions about the Zabbix - -This document tries to answer questions a user might have when installing -and using Zabbix. Please make sure you read this before sending questions or -bug reports to the maintainers. - -At the moment, the document is empty. If you have any questions you think -should be answered in this document, please let me know. - - alexei.vladishev@zabbix.com diff --git a/Makefile.am b/Makefile.am index 86354604a4d7..c85c54effa13 100644 --- a/Makefile.am +++ b/Makefile.am @@ -12,35 +12,26 @@ SUBDIRS = \ EXTRA_DIST = \ bin \ build \ - docs \ - FAQ \ frontends \ include \ CREDITS ## "dist-hook" run after the distribution directory is filled, but before the actual tar (or shar) file is created. dist-hook: -# Update revision in common.h @zabbix_revision=`svn info|grep "Last Changed Rev"|awk '{print $$4;}'`; \ cat $(top_distdir)/include/common.h|sed "s/{ZABBIX_REVISION}/$$zabbix_revision/g" >$(top_distdir)/include/common.h.new mv $(top_distdir)/include/common.h.new $(top_distdir)/include/common.h rm -rf `find $(top_distdir) -name ".svn"` + rm -f $(top_distdir)/include/config.h rm -f $(top_distdir)/frontends/php/conf/zabbix.conf.php - rm -f $(top_distdir)/do - rm -f $(top_distdir)/go - rm -f $(top_distdir)/splint - rm -rf $(top_distdir)/test - rm -f $(top_distdir)/TODO -##TODO mkdir $(top_distdir)/docs -##TODO cp ?????/ZABBIX Manual v1.4.pdf $(top_distdir)/docs/ dbschema: create/schema/gen.pl mysql > create/schema/mysql.sql create/schema/gen.pl postgresql > create/schema/postgresql.sql create/schema/gen.pl sqlite > create/schema/sqlite.sql create/schema/gen.pl oracle > create/schema/oracle.sql - create/schema/gen.pl c >src/libs/zbxdbhigh/dbschema.c + create/schema/gen.pl c > src/libs/zbxdbhigh/dbschema.c echo -e "\n#ifdef HAVE_MYSQL\nconst char *db_schema= {\"\\" >>src/libs/zbxdbhigh/dbschema.c create/schema/gen.pl mysql|tr -s '\t' ' '|sed -e 's/$$/\\/' >>src/libs/zbxdbhigh/dbschema.c echo -e "\"};\n#elif HAVE_POSTGRESQL\nconst char *db_schema = {\"\\" >>src/libs/zbxdbhigh/dbschema.c diff --git a/NEWS b/NEWS index f672c6931d9e..3fdfb31108fe 100644 --- a/NEWS +++ b/NEWS @@ -1 +1 @@ -Check http://www.zabbix.com/news.php +Please see http://www.zabbix.com/news.php. diff --git a/README b/README index 1e49d90f8371..2926ba269384 100644 --- a/README +++ b/README @@ -1 +1,2 @@ Please see http://www.zabbix.com/ for detailed information about Zabbix. +On-line Zabbix documentation is available at http://www.zabbix.com/documentation/1.8/. diff --git a/TODO b/TODO deleted file mode 100644 index 549ec4ca324b..000000000000 --- a/TODO +++ /dev/null @@ -1,204 +0,0 @@ -1.3: - - - add value mapping for messages - - parameter to disable log rotation - - fix order for displaying log files order by clock desc,id desc - - use of aggregates in triggers - - make grid 0,20,40,60,80,100 in graphs - - does ZABBIX maintain Host availability of monitored by SNMP - - when unlinking a host from template, add option (Unlink&Delete, Unlink Only) - - - remember different default values in different forms - - server side checks (new type of check) - - - new item status: not available. If agent doesn't accept parameter. - - new function for item status to enable sending of notification in case if an item changes status to unknown (for example) - - do zabbix_sender for windows - - http://www.zabbix.com/forum/showthread.php?t=1141&page=3&pp=10 - - update trigger value immediately after add or update - -TKOM: - - - alarms forwarding to external systems (using SNMP traps, for example) - - alarm/trigger sounds - - - rus/lat characters for graphs - -
- -
- -4. SNMP traps. Make possible action definition for the SNMP trap-related - events. - -OTHER: - - - multi-institution support - -'-' doesn't work in trigger expressions (a-b=0) - - - negative values in graphs - - check all screens if they are user friendly and present information in the best possible way - - possibility (a button) to recheck unsupported parameters - - add advanced task scheduler/executor to ZABBIX - - agent incorrectly returns amount of free/available memory on HP-UX (must be 24GB) - - - add icons to a map by clicking mouse - - Kak naschet dopolnenij k time & date: - * tipa month, day, year, hour, minute, ... - - Nu i k 'str' dodlstj csjakie vsjakosti tipa - * substr, length, poisk pozicii simvola/podstroki (FIND/SEARCH v Excel), - podscet kolichestva simvola (tipa skoljko tam zapjatih)... - - - add requirement for fping to the manual - - separate login.php and index.php - - remove icmpping and others from the QUEUE - - - summarising report about triggers/actions/items. Show items without triggers, -trigger wihout actions, etc etc - 5) When adding trigger, next page is without triggers of this host. Is - it possible after adding triger to go back to triggers of this host page ? - - - zabbix thinks that host is unrechable if it receives string for numeric item - - - think about implementation of sinchronised items like cpu[usr], cpu[sys], cpu[idle] - - - implement complex SLA calculation (donwtimes, working/non-working hours), etc. See -forum Open Discussion for more info. - - add selection of MIN/MAX/AVG for graphs - - stacked graphs - -LATER: - - - check return code for alert scripts - - trapper item. Source->Alarms do not grow when last status is unknown for -latest trigger (item type = TRAPPER) - - SNMP traps. Condition to switch expression off. New function which would return - status of the trigger could help. - - - when zabbix cannot evaluate expression it does not change status to UNKNOWN but adds ALARM (UNKNOWN) - - preset time for graphs - - - links to Zabbix frontend in alert emails - - strings items for graphs - - zabbix_trapperd does not start if PostgreSQL and DBConnectOnEach=1 - - - [10] Refresh stop ability. At least for graphs and triggers being selected. - - [10] IT Services. Show downtimes for weeks. - - [10] IT Services. User view, show algorithm. - - [10] BUG. When adding new service, service name is wrong. - - [10] IT Services. SLA for a period of time only (09:00-18:00) - -LS: - - - graphs. Dobavljatj item so smescheniem vo vremeni - - check permissions for zabbix_agentd when started under root - - add item to group (not to all) - - update host from template - -trend(N) - linejnaja aproksimacija sled.znachenija po interval vremeni N; -trend(N,M) - tozhe, no ne sled.znachenie, a vpered na interval vremeni M; - -nu i massu matematicheskih mozhno - dlja super-advanced chuvakov: -* SQRT, LOG, LOG10, trigonometricheskie, ... - - - if 'Update', then default action (button 'Enter') must be Update - - do not check SNMP port existance if Item is not SNMP - - add item to host group - - add descriptions to items - - link host (group) to template - -graphs: - - - min value (0 or automatic) - - customisation of font size - - link items to show them in one graph (network in/out) - - - snmp oid symbolic representation - - Latest values->Host->[Show not monitored] - -HP: - - - add threshold,min,max line for user-defined graphs - - - [4] Latest values. Link to page which shows list of all triggers-related - to the item. - - [4] users.php. Link to page which shows all actions defined for this user. - - [5] Configuration of items/triggers. Add Select. - - [7] SLA algorithm (A - 0%, B - 100% -> availability of AB = 50%) - - [7] IT Service % must start at 01.01.20xx, not first day of the week - - [7] ALARMS. Ability to select events by specifying date from/to. - - [9] History of who and when changed trigger comment. As starting point: who and when - did latest changes. - - [9] ... the history to be used to see who did changes and who wrote specific parts - of comments to know who is in charge for the instructions - - [9] ... find outdated instructions to initiate its renewal (review) - -LS: - - - detailed description for items - -TOP PRIORITY: - - - fix update of 'status'. When added it never gets updated, if server is already unreachable. - - add more checks for forms (check all possible wrong values) - - support of fetch_html[*] - - zabbix_agentd to support swap[*] and memory[*] onder AIX - -BUGS: - - - add protection from IT Service looping - -DIFFERENT TASKS: - - - SNMP trapping - - distributed monitoring - - personalisation (refresh rate, graph size, default graph period, etc) - - SNMP-walk in WEB interface - - add UserParameter without restart of an agent - -TODO: - -- Agent - 1. An API so that I can build and active agent into - the centralized monitoring point of my application. - 2. max/min/average values during the poll pause along with last value to catch -CPU spikes otherwise invisible (have had these problems with BMC Patrol). - 3. Ability to add a library of userwritten c-functions with dlopen/dlsym to -the agent with a predefined API that can return values to suckerd. - -Not ready yet: - -1. Monitoring of Windows (2000) services via SNMP -This is an extension I wrote based on your SNMP checker that scans through the Windows SNMP mib to check if a specified -+process is running. I thought it may be able to be used in a similar situation to the new SIMPLE check. - -2. Basic schedule to monitor certain items during specified period. -I made changes to the PHP frontend and zabbix_sucker.c to enable the user to specify a time period (like between 9am-5pm) when -+the item should be checked. -(From: "Dave McCrudden" ) - - - - do not send notifications at certain periods of time. Do not monitor services at certain periods of time. - - decrease number of TCP connections between server and agent - - add triggers for all hosts at once - - check new Mariusz patches - - add support for downtimes, user availablity, etc - -HB: - - - LDAP authorisation (should work with MSWindows LDAP) - - OTHER: - - - collect network and other statistics using kstat() - - support for complex reports - - update trigger status to UNKNOWN if cannot evaluate function - - LATER: - - - setup demo site diff --git a/docs/README b/docs/README deleted file mode 100644 index 4b9c09ed9469..000000000000 --- a/docs/README +++ /dev/null @@ -1 +0,0 @@ -On-line Zabbix documentation is available at http://www.zabbix.com/documentation diff --git a/splint b/splint deleted file mode 100644 index 299fdb802d0d..000000000000 --- a/splint +++ /dev/null @@ -1 +0,0 @@ -splint expression.c +I/home/zabbix/trunk/include -I/usr/include/mysql -warnposix +sysdirs /usr/include +skip-sys-headers +I/usr/include/mysql +posixlib -DMYSQL_RES=int -DMYSQL_ROW="char *" diff --git a/src/alphacode/poller/go b/src/alphacode/poller/go deleted file mode 100755 index 2d50475a9d14..000000000000 --- a/src/alphacode/poller/go +++ /dev/null @@ -1,2 +0,0 @@ -gcc snmp.c -I/usr/include/net-snmp -I/usr/include/mysql -lsnmp -lmysqlclient -#gcc poller_epoll.c -o poller_epoll diff --git a/src/alphacode/poller/poller.c b/src/alphacode/poller/poller.c deleted file mode 100644 index f4bf1e778c36..000000000000 --- a/src/alphacode/poller/poller.c +++ /dev/null @@ -1,217 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -/* -** 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. -**/ - -#define NUM 256 - -#define ZBXPOOL struct zbxpool_type - -ZBXPOOL -{ - char ip[128]; - int port; - int socket; - int status; /* 0 - not connected, 1 - connected, 2 - wrote data */ -}; - -ZBXPOOL pool[NUM]; - -int s; - -struct pollfd poll_cli[NUM]; - -void init_pool() -{ - int i; - - for(i=0;ih_addr))->s_addr; - servaddr_in.sin_port=htons(port); - - s=socket(AF_INET,SOCK_STREAM,0); - - if(s == -1) - { - perror("socket() failed"); - } - - if(fcntl(s, F_SETFL, O_NONBLOCK) == -1) - { - perror("fcntl() failed\n"); - exit(-1); - } - - retval = connect(s,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); - if(retval == 0) - { - printf("Socket connected immediately"); - } - else if(retval == -1) - { - if(errno == EINPROGRESS) - { - printf("Connection in progress\n"); - } - else - { - perror("connect"); - exit(-1); - } - } - poll_cli[i].fd = s; - poll_cli[i].events = POLLOUT; - } - - wait_connect(); -} diff --git a/src/alphacode/poller/poller_epoll.c b/src/alphacode/poller/poller_epoll.c deleted file mode 100644 index c0fd61969d45..000000000000 --- a/src/alphacode/poller/poller_epoll.c +++ /dev/null @@ -1,151 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -/* -** 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. -**/ - -#define NUM 1000 - -int s; - -int epfd; -struct epoll_event ev; -struct epoll_event *events; - -void wait_connect() -{ - int len; - char c[1024]; - int retval,i,j; - - printf("Waiting for connect\n"); - - for(;;) - { - - printf("epfd [%d]\n", epfd); - printf("NUM [%d]\n", NUM); - events=malloc(NUM*sizeof(struct epoll_event)); - retval = epoll_wait(epfd, events, NUM, -1); - if(retval == -1) - { - perror("epoll_wait"); - printf("Retval [%d]\n", errno); - exit(-1); - } - printf("Retval [%d]\n", retval); - sleep(1); - continue; - - for(i=0;ih_addr))->s_addr; - - servaddr_in.sin_port=htons(port); - - s=socket(AF_INET,SOCK_STREAM,0); - - if(s == -1) - { - perror("socket() failed"); - } - - if(fcntl(s, F_SETFL, O_NONBLOCK) == -1) - { - perror("fcntl() failed\n"); - exit(-1); - } - - retval = connect(s,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); - if(retval == 0) - { - printf("Socket connected immediately"); - } - else if(retval == -1) - { - if(errno == EINPROGRESS) - { -/* printf("Connection in progress\n");*/ - } - else - { - perror("connect"); - exit(-1); - } - } - -/* if(fcntl(s, F_SETFL, O_NONBLOCK) == -1) - { - perror("fcntl() failed\n"); - exit(-1); - }*/ - - ev.events = EPOLLIN | EPOLLERR | EPOLLHUP | EPOLLOUT; - ev.data.fd = s; - if(epoll_ctl(epfd, EPOLL_CTL_ADD, s, &ev) < 0) - { - perror("epoll_ctl, adding listenfd\n"); - exit(1); - } -/* printf("epoll_ctl ok fd [%d]\n", s); */ - } - - wait_connect(); -} diff --git a/src/alphacode/poller/snmp.c b/src/alphacode/poller/snmp.c deleted file mode 100755 index d003f84621c1..000000000000 --- a/src/alphacode/poller/snmp.c +++ /dev/null @@ -1,444 +0,0 @@ -/* - * NET-SNMP demo - * - * This program demonstrates different ways to query a list of hosts - * for a list of variables. - * - * It would of course be faster just to send one query for all variables, - * but the intention is to demonstrate the difference between synchronous - * and asynchronous operation. - * - * Niels Baggesen (Niels.Baggesen@uni-c.dk), 1999. - */ - -#include -#include -#include -#include - -#include "mysql.h" -#include "errmsg.h" -#include "mysqld_error.h" - -MYSQL mysql; - -#define CONFIG_DBHOST "" -#define CONFIG_DBNAME "demo" -#define CONFIG_DBUSER "root" -#define CONFIG_DBPASSWORD "" - -/* - * a list of hosts to query - */ -struct host { - char *hostname; - char *community; -} hosts[10000] = { -/* { "192.168.1.60", "public" }, */ - { NULL } -}; - -/* - * a list of variables to query for - */ -struct oid { - const char *hostname; - const char *Name; - oid Oid[MAX_OID_LEN]; - int OidLen; -} oids[10000] = { -/* { "192.168.1.5", ".1.3.6.1.2.1.1.6.5" }, */ - { NULL } -}; - -char *DBget_field(MYSQL_RES *result, int rownum, int fieldnum) -{ - MYSQL_ROW row; - - mysql_data_seek(result, rownum); - row=mysql_fetch_row(result); - if(row == NULL) - { - printf("Error while mysql_fetch_row():Error [%s] Rownum [%d] Fieldnum [%d]\n", mysql_error(&mysql), rownum, fieldnum ); - exit(-1); - } - return row[fieldnum]; -} - -int DBnum_rows(MYSQL_RES *result) -{ - int rows; - - if(result == NULL) - { - return 0; - } -/* Order is important ! */ - rows = mysql_num_rows(result); - if(rows == 0) - { - return 0; - } - -/* This is necessary to exclude situations like - * atoi(DBget_field(result,0,0). This leads to coredump. - */ -/* This is required for empty results for count(*), etc */ - if(DBget_field(result,0,0) == 0) - { - return 0; - } - return rows; -} - -MYSQL_RES *DBselect(char *query) -{ - while(mysql_query(&mysql,query) != 0) - { - printf("Query:%s\n",query); - printf("Query failed:%s [%d]\n", mysql_error(&mysql), mysql_errno(&mysql) ); - - if( (ER_SERVER_SHUTDOWN != mysql_errno(&mysql)) && - (CR_SERVER_GONE_ERROR != mysql_errno(&mysql)) && - (CR_CONNECTION_ERROR != mysql_errno(&mysql))) - { - exit(-1); - } - } - - return mysql_store_result(&mysql); -} - -void load_oids(void) -{ - char sql[1024]; - char *hostname; - char *community; - char *oid; - MYSQL_RES *result; - int i; - - struct host *h; - struct oid *o; - - zbx_snprintf(sql, sizeof(sql), "select h.ip,i.snmp_community,i.snmp_oid from hosts h,items i where i.hostid=h.hostid and i.type=1 and i.status=0 and h.status=0 and h.useip=1"); - - result=DBselect(sql); - - for(i=0;ihostname) - { - if(strcmp(h->hostname,hostname)==0) break; - h++; - } - - if(!h->hostname) - { - h->hostname=strdup(hostname); - h->community=strdup(community); - h++; - h->hostname = NULL; - } - - o = oids; - while(o->hostname) - { - o++; - } - o->hostname=strdup(hostname); - o->Name=strdup(oid); - o++; - o->hostname = NULL; - } - - h = hosts; - i = 0; - while(h->hostname) - { - i++; - h++; - } - printf("Loaded [%d] hosts\n", i); - o = oids; - i = 0; - while(o->hostname) - { - i++; - o++; - } - printf("Loaded [%d] OIDs\n", i); -} - -/* - * initialize - */ -void initialize (void) -{ - struct oid *op; - - init_snmp("asynchapp"); - - load_oids(); - -/* parse the oids */ - op = oids; - while (op->hostname) { -/* printf("[%s]\n",op->hostname); */ - op->OidLen = sizeof(op->Oid)/sizeof(op->Oid[0]); - if (!read_objid(op->Name, op->Oid, &op->OidLen)) { - snmp_perror("read_objid"); - exit(1); - } - op++; - } - printf("Press Enter to start polling"); - getc(stdin); -} - -/* - * simple printing of returned data - */ -int print_result (int status, struct snmp_session *sp, struct snmp_pdu *pdu) -{ - char buf[1024]; - struct variable_list *vp; - int ix; - struct timeval now; - struct timezone tz; - struct tm *tm; - - gettimeofday(&now, &tz); - tm = localtime(&now.tv_sec); - fprintf(stdout, "%.2d:%.2d:%.2d.%.6d ", tm->tm_hour, tm->tm_min, tm->tm_sec, - now.tv_usec); - switch (status) { - case STAT_SUCCESS: - vp = pdu->variables; - if (pdu->errstat == SNMP_ERR_NOERROR) { - while (vp) { - snprint_variable(buf, sizeof(buf), vp->name, vp->name_length, vp); - fprintf(stdout, "%s: %s\n", sp->peername, buf); - vp = vp->next_variable; - } - } - else { - for (ix = 1; vp && ix != pdu->errindex; vp = vp->next_variable, ix++) - ; - if (vp) snprint_objid(buf, sizeof(buf), vp->name, vp->name_length); - else strcpy(buf, "(none)"); - fprintf(stdout, "%s: %s: %s\n", - sp->peername, buf, snmp_errstring(pdu->errstat)); - } - return 1; - case STAT_TIMEOUT: - fprintf(stdout, "%s: Timeout\n", sp->peername); - return 0; - case STAT_ERROR: - snmp_perror(sp->peername); - return 0; - } - return 0; -} - -/*****************************************************************************/ - -/* - * poll all hosts in parallel - */ -struct session { - struct snmp_session *sess; /* SNMP session data */ - struct oid *current_oid; /* How far in our poll are we */ -} sessions[sizeof(hosts)/sizeof(hosts[0])]; - -int active_hosts; /* hosts that we have not completed */ - -/* - * response handler - */ -int asynch_response(int operation, struct snmp_session *sp, int reqid, - struct snmp_pdu *pdu, void *magic) -{ - struct session *host = (struct session *)magic; - struct snmp_pdu *req; - struct oid *op; - - if (operation == NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE) { - if (print_result(STAT_SUCCESS, host->sess, pdu)) { -/* host->current_oid++; */ /* send next GET (if any) */ - op = host->current_oid; - op++; - while(op->hostname) - { -/* printf("[%s] [%s]\n",op->hostname, host->current_oid->hostname); */ - if(strcmp(op->hostname,host->current_oid->hostname)==0) { - host->current_oid = op; - break; - } - op++; - } - - if (op->hostname && host->current_oid->Name) { - req = snmp_pdu_create(SNMP_MSG_GET); - snmp_add_null_var(req, host->current_oid->Oid, host->current_oid->OidLen); - if (snmp_send(host->sess, req)) - return 1; - else { - snmp_perror("snmp_send"); - snmp_free_pdu(req); - } - } - else - { -/* printf("No more OIDs for [%s]\n", host->current_oid->hostname); */ - } - } - } - else - print_result(STAT_TIMEOUT, host->sess, pdu); - -/* something went wrong (or end of variables) -* this host not active any more -*/ - active_hosts--; - return 1; -} - -void asynchronous(void) -{ - struct session *hs; - struct host *hp; - struct oid *op; - -/* startup all hosts */ - - for (hs = sessions, hp = hosts; hp->hostname; hs++, hp++) { - struct snmp_pdu *req; - struct snmp_session sess; - snmp_sess_init(&sess); /* initialize session */ - sess.version = SNMP_VERSION_1; - /* sess.version = SNMP_VERSION_2c; */ - sess.peername = strdup(hp->hostname); - sess.community = strdup(hp->community); - sess.community_len = strlen(sess.community); - sess.callback = asynch_response; /* default callback */ - sess.callback_magic = hs; - if (!(hs->sess = snmp_open(&sess))) { - snmp_perror("snmp_open"); - continue; - } - op = oids; - while(op->hostname) - { - if(strcmp(op->hostname,hp->hostname)==0) { - hs->current_oid = op; - break; - } - op++; - } - if(!op->Name) { - printf("No OIDs for [%s]\n", hp->hostname); - continue; - } -/* printf("Sending request [%s] [%s]\n",hp->hostname, hs->current_oid->Name); */ - req = snmp_pdu_create(SNMP_MSG_GET); /* send the first GET */ - snmp_add_null_var(req, hs->current_oid->Oid, hs->current_oid->OidLen); - if (snmp_send(hs->sess, req)) - active_hosts++; - else { - snmp_perror("snmp_send"); - snmp_free_pdu(req); - } - } - -/* loop while any active hosts */ - - while (active_hosts) { - int fds = 0, block = 1; - fd_set fdset; - struct timeval timeout; - - FD_ZERO(&fdset); - snmp_select_info(&fds, &fdset, &timeout, &block); - fds = select(fds, &fdset, NULL, NULL, block ? NULL : &timeout); - if (fds < 0) { - perror("select failed"); - exit(1); - } - if (fds) - snmp_read(&fdset); - else - snmp_timeout(); - } - -/* cleanup */ - - for (hp = hosts, hs = sessions; hp->hostname; hs++, hp++) { - if (hs->sess) snmp_close(hs->sess); - } -} - -void DBclose(void) -{ - mysql_close(&mysql); -} - -void DBconnect(void) -{ - mysql_init(&mysql); - - if( ! mysql_real_connect( &mysql, CONFIG_DBHOST, CONFIG_DBUSER, CONFIG_DBPASSWORD, CONFIG_DBNAME, NULL, NULL,0 ) ) - { - printf("Failed to connect to database: Error: %s\n",mysql_error(&mysql)); - exit(-1); - } - else - { - if( mysql_select_db( &mysql, CONFIG_DBNAME ) != 0 ) - { - printf("Failed to select database: Error: %s\n",mysql_error(&mysql) ); - exit(-1); - } - } -} - -int DBexecute(char *query) -{ - while( mysql_query(&mysql,query) != 0) - { - printf("Query::%s\n",query); - printf("Query failed:%s [%d]\n", mysql_error(&mysql), mysql_errno(&mysql) ); - - if( (ER_SERVER_SHUTDOWN != mysql_errno(&mysql)) && - (CR_SERVER_GONE_ERROR != mysql_errno(&mysql)) && - (CR_CONNECTION_ERROR != mysql_errno(&mysql))) - { - return -1; - } - - DBclose(); - DBconnect(); - } -} - - - -/*****************************************************************************/ - -int main (int argc, char **argv) -{ - DBconnect(); - initialize(); - - printf("---------- asynchronous -----------\n"); - asynchronous(); - - return 0; -} diff --git a/src/alphacode/poller/snmp_orig.c b/src/alphacode/poller/snmp_orig.c deleted file mode 100755 index 95f8f24d1368..000000000000 --- a/src/alphacode/poller/snmp_orig.c +++ /dev/null @@ -1,353 +0,0 @@ -/* - * NET-SNMP demo - * - * This program demonstrates different ways to query a list of hosts - * for a list of variables. - * - * It would of course be faster just to send one query for all variables, - * but the intention is to demonstrate the difference between synchronous - * and asynchronous operation. - * - * Niels Baggesen (Niels.Baggesen@uni-c.dk), 1999. - */ - -#include -#include - -/* - * a list of hosts to query - */ -struct host { - const char *name; - const char *community; -} hosts[] = { - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { "192.168.1.5", "public" }, - { NULL } -}; - -/* - * a list of variables to query for - */ -struct oid { - const char *Name; - oid Oid[MAX_OID_LEN]; - int OidLen; -} oids[] = { - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { ".1.3.6.1.2.1.1.6.0" }, - { NULL } -}; - -/* - * initialize - */ -void initialize (void) -{ - struct oid *op = oids; - - init_snmp("asynchapp"); - - /* parse the oids */ - while (op->Name) { - op->OidLen = sizeof(op->Oid)/sizeof(op->Oid[0]); - if (!read_objid(op->Name, op->Oid, &op->OidLen)) { - snmp_perror("read_objid"); - exit(1); - } - op++; - } -} - -/* - * simple printing of returned data - */ -int print_result (int status, struct snmp_session *sp, struct snmp_pdu *pdu) -{ - char buf[1024]; - struct variable_list *vp; - int ix; - struct timeval now; - struct timezone tz; - struct tm *tm; - - gettimeofday(&now, &tz); - tm = localtime(&now.tv_sec); - fprintf(stdout, "%.2d:%.2d:%.2d.%.6d ", tm->tm_hour, tm->tm_min, tm->tm_sec, - now.tv_usec); - switch (status) { - case STAT_SUCCESS: - vp = pdu->variables; - if (pdu->errstat == SNMP_ERR_NOERROR) { - while (vp) { - snprint_variable(buf, sizeof(buf), vp->name, vp->name_length, vp); - fprintf(stdout, "%s: %s\n", sp->peername, buf); - vp = vp->next_variable; - } - } - else { - for (ix = 1; vp && ix != pdu->errindex; vp = vp->next_variable, ix++) - ; - if (vp) snprint_objid(buf, sizeof(buf), vp->name, vp->name_length); - else strcpy(buf, "(none)"); - fprintf(stdout, "%s: %s: %s\n", - sp->peername, buf, snmp_errstring(pdu->errstat)); - } - return 1; - case STAT_TIMEOUT: - fprintf(stdout, "%s: Timeout\n", sp->peername); - return 0; - case STAT_ERROR: - snmp_perror(sp->peername); - return 0; - } - return 0; -} - -/*****************************************************************************/ - -/* - * simple synchronous loop - */ -void synchronous (void) -{ - struct host *hp; - - for (hp = hosts; hp->name; hp++) { - struct snmp_session ss, *sp; - struct oid *op; - - snmp_sess_init(&ss); /* initialize session */ - ss.version = SNMP_VERSION_1; -/* ss.version = SNMP_VERSION_2c; */ - ss.peername = strdup(hp->name); - ss.community = strdup(hp->community); - ss.community_len = strlen(ss.community); - if (!(sp = snmp_open(&ss))) { - snmp_perror("snmp_open"); - continue; - } - for (op = oids; op->Name; op++) { - struct snmp_pdu *req, *resp; - int status; - req = snmp_pdu_create(SNMP_MSG_GET); - snmp_add_null_var(req, op->Oid, op->OidLen); - status = snmp_synch_response(sp, req, &resp); - if (!print_result(status, sp, resp)) break; - snmp_free_pdu(resp); - } - snmp_close(sp); - } -} - -/*****************************************************************************/ - -/* - * poll all hosts in parallel - */ -struct session { - struct snmp_session *sess; /* SNMP session data */ - struct oid *current_oid; /* How far in our poll are we */ -} sessions[sizeof(hosts)/sizeof(hosts[0])]; - -int active_hosts; /* hosts that we have not completed */ - -/* - * response handler - */ -int asynch_response(int operation, struct snmp_session *sp, int reqid, - struct snmp_pdu *pdu, void *magic) -{ - struct session *host = (struct session *)magic; - struct snmp_pdu *req; - - if (operation == NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE) { - if (print_result(STAT_SUCCESS, host->sess, pdu)) { - host->current_oid++; /* send next GET (if any) */ - if (host->current_oid->Name) { - req = snmp_pdu_create(SNMP_MSG_GET); - snmp_add_null_var(req, host->current_oid->Oid, host->current_oid->OidLen); - if (snmp_send(host->sess, req)) - return 1; - else { - snmp_perror("snmp_send"); - snmp_free_pdu(req); - } - } - } - } - else - print_result(STAT_TIMEOUT, host->sess, pdu); - - /* something went wrong (or end of variables) - * this host not active any more - */ - active_hosts--; - return 1; -} - -void asynchronous(void) -{ - struct session *hs; - struct host *hp; - - /* startup all hosts */ - - for (hs = sessions, hp = hosts; hp->name; hs++, hp++) { - struct snmp_pdu *req; - struct snmp_session sess; - snmp_sess_init(&sess); /* initialize session */ - sess.version = SNMP_VERSION_1; -/* sess.version = SNMP_VERSION_2c; */ - sess.peername = strdup(hp->name); - sess.community = strdup(hp->community); - sess.community_len = strlen(sess.community); - sess.callback = asynch_response; /* default callback */ - sess.callback_magic = hs; - if (!(hs->sess = snmp_open(&sess))) { - snmp_perror("snmp_open"); - continue; - } - hs->current_oid = oids; - req = snmp_pdu_create(SNMP_MSG_GET); /* send the first GET */ - snmp_add_null_var(req, hs->current_oid->Oid, hs->current_oid->OidLen); - if (snmp_send(hs->sess, req)) - active_hosts++; - else { - snmp_perror("snmp_send"); - snmp_free_pdu(req); - } - } - - /* loop while any active hosts */ - - while (active_hosts) { - int fds = 0, block = 1; - fd_set fdset; - struct timeval timeout; - - FD_ZERO(&fdset); - snmp_select_info(&fds, &fdset, &timeout, &block); - fds = select(fds, &fdset, NULL, NULL, block ? NULL : &timeout); - if (fds < 0) { - perror("select failed"); - exit(1); - } - if (fds) - snmp_read(&fdset); - else - snmp_timeout(); - } - - /* cleanup */ - - for (hp = hosts, hs = sessions; hp->name; hs++, hp++) { - if (hs->sess) snmp_close(hs->sess); - } -} - -/*****************************************************************************/ - -int main (int argc, char **argv) -{ - initialize(); - - printf("---------- synchronous -----------\n"); - synchronous(); - - printf("---------- asynchronous -----------\n"); - asynchronous(); - - return 0; -}