diff options
author | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2001-08-05 13:54:37 +0000 |
---|---|---|
committer | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2001-08-05 13:54:37 +0000 |
commit | bcad0d8ff2049311f84d6727190601999d63d4bd (patch) | |
tree | f368ccf3ea7bc47f4281f94f1bb06b86f49393e1 | |
parent | 31be0f053d6ce0073e84c8bfc27348cf1a290a61 (diff) | |
download | zabbix-bcad0d8ff2049311f84d6727190601999d63d4bd.tar.gz zabbix-bcad0d8ff2049311f84d6727190601999d63d4bd.tar.xz zabbix-bcad0d8ff2049311f84d6727190601999d63d4bd.zip |
Added zabbix_agentd. A lot of other changes.
git-svn-id: svn://svn.zabbix.com/trunk@160 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | create/data/data.sql | 6 | ||||
-rw-r--r-- | create/mysql/schema.sql | 1 | ||||
-rw-r--r-- | create/postgresql/schema.sql | 6 | ||||
-rw-r--r-- | doc/manual.txt | 106 | ||||
-rw-r--r-- | frontends/php/chart.html | 5 | ||||
-rw-r--r-- | frontends/php/chart2.html | 3 | ||||
-rw-r--r-- | frontends/php/history.html | 2 | ||||
-rw-r--r-- | frontends/php/map.html | 4 | ||||
-rw-r--r-- | frontends/php/report1.html | 2 | ||||
-rw-r--r-- | frontends/php/sysmap.html | 6 | ||||
-rw-r--r-- | frontends/php/trend.html | 6 | ||||
-rw-r--r-- | frontends/php/trends.html | 4 | ||||
-rw-r--r-- | frontends/php/users.html | 2 | ||||
-rw-r--r-- | include/db.c | 24 | ||||
-rw-r--r-- | include/db.h | 16 | ||||
-rw-r--r-- | src/zabbix_agent/Makefile.in | 4 | ||||
-rw-r--r-- | src/zabbix_agent/sysinfo.c | 117 | ||||
-rw-r--r-- | src/zabbix_agent/sysinfo.h | 11 | ||||
-rw-r--r-- | src/zabbix_agent/zabbix_agent.c | 148 | ||||
-rw-r--r-- | src/zabbix_agent/zabbix_agent.h | 8 | ||||
-rw-r--r-- | src/zabbix_agent/zabbix_agentd.c | 274 | ||||
-rw-r--r-- | src/zabbix_sucker/Makefile.in | 4 | ||||
-rw-r--r-- | src/zabbix_sucker/zabbix_sucker.c | 8 |
24 files changed, 532 insertions, 240 deletions
@@ -1,13 +1,14 @@ Changes for 1.0alpha8: + - zabbix_sucker renamed to zabbix_suckerd + - new high performance zabbix_agentd + - connect using IP address became possible - new columns - useip,ip were added to table hosts - - added bin/ - removed src/.../acconfig.h - removed src/.../configure.in - added Makefile.in,acconfig.h,configure.in - - added src/zabbix_sucker/acconfig.h and src/zabbix_trapper/acconfig.h - parameters net[listen_??] will use /proc filesystem - parameter system[proccount] uses call to sysinfo() function diff --git a/create/data/data.sql b/create/data/data.sql index fb8b2c8a..4d09c223 100644 --- a/create/data/data.sql +++ b/create/data/data.sql @@ -1,10 +1,4 @@ -- --- Data for table help --- - -insert into help (helpid,topic,description) values (1,"What is SMTP server ?","... Example help text ..."); - --- -- Data for table config -- diff --git a/create/mysql/schema.sql b/create/mysql/schema.sql index d99b8617..017cf659 100644 --- a/create/mysql/schema.sql +++ b/create/mysql/schema.sql @@ -43,6 +43,7 @@ CREATE TABLE sysmaps_hosts ( shostid int(4) NOT NULL auto_increment, sysmapid int(4) DEFAULT '0' NOT NULL, hostid int(4) DEFAULT '0' NOT NULL, + icon varchar(32) DEFAULT 'Server' NOT NULL, label varchar(128) DEFAULT '' NOT NULL, x int(4) DEFAULT '0' NOT NULL, y int(4) DEFAULT '0' NOT NULL, diff --git a/create/postgresql/schema.sql b/create/postgresql/schema.sql index 1b060b7d..46f4bf50 100644 --- a/create/postgresql/schema.sql +++ b/create/postgresql/schema.sql @@ -148,10 +148,11 @@ CREATE TABLE alarms ( clock int4 DEFAULT '0' NOT NULL, istrue int4 DEFAULT '0' NOT NULL, PRIMARY KEY (alarmid), - FOREIGN KEY (triggerid) REFERENCES triggers, - KEY (triggerid, clock) + FOREIGN KEY (triggerid) REFERENCES triggers ); +CREATE INDEX alarms_triggerid_clock on alarms (triggerid, clock); + -- -- Table structure for table 'functions' -- @@ -248,6 +249,7 @@ CREATE TABLE sysmaps_hosts ( shostid serial, sysmapid int4 DEFAULT '0' NOT NULL, hostid int4 DEFAULT '0' NOT NULL, + icon varchar(32) DEFAULT 'Server' NOT NULL, label varchar(128) DEFAULT '' NOT NULL, x int4 DEFAULT '0' NOT NULL, y int4 DEFAULT '0' NOT NULL, diff --git a/doc/manual.txt b/doc/manual.txt index fc43272e..2f85f3dd 100644 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -13,15 +13,16 @@ 2.5 Capacity planning 3. Chapter 3 (Structure) -3.1 zabbix_sucker +3.1 zabbix_suckerd 3.2 zabbix_agent -3.3 zabbix_trapper -3.4 zabbix_sender -3.5 Database -3.6 WEB-based frontend -3.6.1 Reports -3.6.1.1 Status of Zabbix -3.6.1.2 Availability report +3.3 zabbix_agentd +3.4 zabbix_trapper +3.5 zabbix_sender +3.6 Database +3.7 WEB-based frontend +3.8.1 Reports +3.8.1.1 Status of Zabbix +3.8.1.2 Availability report 4. Chapter 4 (Installation) @@ -151,13 +152,13 @@ value in the database. It is also possible to use trapping method. In tis case, monitored host sends information to Zabbix server. -3.1 zabbix_sucker +3.1 zabbix_suckerd The Zabbix server process. SYNOPSIS -zabbix_sucker +zabbix_suckerd DESCRIPTION @@ -165,17 +166,17 @@ The process periodically connects to agents (either Zabbix native or SNMP) to ge monitored. Also, the process periodically re-calculates status of triggers. It sends alerts to users if required. -By default, zabbix_sucker forks ten copies of itself. It means that Zabbix will be able to get ten monitored parameters +By default, zabbix_suckerd forks ten copies of itself. It means that Zabbix will be able to get ten monitored parameters simultaneously. Modify parameter SUCKER_FORKS in include/common.h if ten is not enough for you. -No switches are supported by zabbix_sucker. +No switches are supported by zabbix_suckerd. The process is run as daemon under non-priveledged user account, usually zabbix. Syslog is used to store debug information for the process. 3.2 zabbix_agent -The Zabbix agent. +The Zabbix agent (called from inetd). SYNOPSIS @@ -184,15 +185,40 @@ zabbix_agent DESCRIPTION The process lives on host being monitored. zabbix_agent provides requested information to -zabbix_sucker. zabbix_agent is called from inetd daemon. +zabbix_suckerd. zabbix_agent is made to be used with INETD daemon. Execution time of the process is limited. If agent was not able to get information during 3 seconds, it kills himself. -When executed, it reads /etc/zabbix/zabbix_agent.conf file. This file should exist and contain +When connection to zabbix_agent is made, the agent reads /etc/zabbix/zabbix_agent.conf file. This file should exist and contain IP address of Zabbix server. Connections from other IPs are rejected. -3.3 zabbix_trapper +If possible, use zabbix_agentd. It does not require extra fork() and exec() calls for every connection. + +3.3 zabbix_agentd + +Standalone Zabbix agent (daemon). + +SYNOPSIS + +zabbix_agentd + +DESCRIPTION + +The process runs on host being monitored. zabbix_agentd provides requested information to +zabbix_suckerd. + +When executed, it forks himself. Load is balanced between each copy (dafault is ten). + +When connection to zabbix_agentd is made, the agent reads /etc/zabbix/zabbix_agent.conf file. This file should exist and contain +IP address of Zabbix server. Connections from other IPs are rejected. + +No switches are supported by zabbix_agentd. + +The process is run as daemon under non-priveledged user account, usually zabbix. Syslog is used to store +debug information for the process. + +3.4 zabbix_trapper The Zabbix server process. @@ -205,7 +231,7 @@ DESCRIPTION The process is made to support traping. It constantly waits for connections from zabbix_sender agents. -3.4 zabbix_sender +3.5 zabbix_sender The Zabbix agent (trapping). @@ -229,30 +255,30 @@ zabbix_sender zabbix.abcde.com 10001 db.abcde.com:procload 2.34 It means, that zabbix_sender will send information about processor load on host db.abcde.com to Zabbix server located at zabbix.acbde.com. Processor load is 2.34. -3.5 Database +3.6 Database Database used by Zabbix play most important role. The database is the only source of configuration parameters and it stores all history of monitored values. Zabbix performance highly depends on officiency and speed of used database. -3.6 WEB-based frontend +3.7 WEB-based frontend The frontend provides convinient and platform independed way for accessing Zabbix. Information provided by the frontend can be either graphical (e.g. graph on disk space usage) or text format. Text representation of monitored parameters is made to allow easy way for export Zabbix data to other analytical tools. -3.6.1 Reports +3.7.1 Reports Zabbix reports represent collected information in structured way. All reports are produced in HTML format. Note that report generation could be very time consuming operation. Additionally, if you -use MySQL or ay other database with table locking, zabbix_sucker and zabbix_trapper will +use MySQL or ay other database with table locking, zabbix_suckerd and zabbix_trapper will wait until the report is finished. -3.6.1.1 Status of Zabbix +3.7.1.1 Status of Zabbix This report gives general information about Zabbix server including: @@ -260,7 +286,7 @@ This report gives general information about Zabbix server including: - are main Zabbix processes running ? - other information -3.6.1.2 Availability report +3.7.1.2 Availability report This report calculates amount of time a trigger spent in true and false states. @@ -302,7 +328,7 @@ However, Zabbix can work on previous versions of Apache, MySQL, PostgreSQL as we Debian Potato and Debian Woody are development and testing platforms I currently use. I've tried to run Zabbix on PostgreSQL 6.5x with no luck. PostgreSQL crashes after -one-tree minutes of zabbix_sucker running. So, PostgreSQL version 7.0.2 or later is strongly +one-tree minutes of zabbix_suckerd running. So, PostgreSQL version 7.0.2 or later is strongly recommended. For small installations MySQL is best choice. However, if you plan to monitor more than @@ -369,21 +395,11 @@ cat data.sql|psql -U <username> zabbix 4.2.4 Configure include/db.h -Use this for MySQL database: -#define USE_MYSQL 1 - -or - -Use this for PostgreSQL: -#define USE_POSTGRESQL 1 - -Parameters used regardless of database type: +Change the following parameters: #define DB_NAME "zabbix" -#define DB_USER "" -#define DB_PASSWD "" - -Change these values. +#define DB_USER "zabbix" +#define DB_PASSWD "password" 4.2.5 Configure and compile the source code for your system. @@ -403,11 +419,15 @@ zabbix_trap 10001/tcp 4.2.8 Configure /etc/inetd.conf -Add the following lines to /etc/inetd.conf: +Add the following line to /etc/inetd.conf: -zabbix_agent stream tcp nowait.3600 zabbix /opt/zabbix/bin/zabbix_agent zabbix_trap stream tcp nowait.3600 zabbix /opt/zabbix/bin/zabbix_trapper +If you plan to use zabbix_agent (zabbix_agentd does not require this!), the following line must be added as well: + +zabbix_agent stream tcp nowait.3600 zabbix /opt/zabbix/bin/zabbix_agent + + 4.2.9 Restart inetd killall -HUP inetd @@ -468,9 +488,13 @@ to "Not monitored". List of possible parameers for the host will be automaticall - Configure TRIGGERS - - Run zabbix_sucker + - Run zabbix_suckerd + +/opt/zabbix/bin/zabbix_suckerd + + - Run zabbix_agentd -/opt/zabbix/bin/zabbix_sucker +You should not run zabbix_agentd this if you use zabbix_agent ! Define actions for triggers you are interested in. Note, that you can always use macros in both email subject and email body. diff --git a/frontends/php/chart.html b/frontends/php/chart.html index b95d7596..19722d0b 100644 --- a/frontends/php/chart.html +++ b/frontends/php/chart.html @@ -21,7 +21,7 @@ $sizeY=200; $shiftX=10; - $shiftY=10; + $shiftY=13; $nodata=1; @@ -39,6 +39,7 @@ $yellow=ImageColorAllocate($im,255,255,0); $cyan=ImageColorAllocate($im,0,255,255); $black=ImageColorAllocate($im,0,0,0); + $gray=ImageColorAllocate($im,150,150,150); $x=imagesx($im); $y=imagesy($im); @@ -121,6 +122,8 @@ ImageString($im, 2,$sizeX/2 -50, $sizeY+$shiftY+3, "NO DATA FOUND FOR THIS PERIOD" , $red); } + ImageStringUp($im,0,2*$shiftX+$sizeX+40,$sizeY+2*$shiftY, "http://zabbix.sourceforge.net", $gray); + ImagePng($im); ImageDestroy($im); ?> diff --git a/frontends/php/chart2.html b/frontends/php/chart2.html index 6ee202c2..b906d2f6 100644 --- a/frontends/php/chart2.html +++ b/frontends/php/chart2.html @@ -163,7 +163,8 @@ ImageString($im, 2,$sizeX/2 -50, $sizeY+$shiftYup+3, "NO DATA FOR THIS PERIOD" , $red); } - ImageString($im,0,$shiftX+$sizeX-85,$sizeY+$shiftYup+25, "http://zabbix.sourceforge.net", $gray); +# ImageString($im,0,$shiftX+$sizeX-85,$sizeY+$shiftYup+25, "http://zabbix.sourceforge.net", $gray); + ImageStringUp($im,0,2*$shiftX+$sizeX+40,$sizeY+$shiftYdown+$shiftYup, "http://zabbix.sourceforge.net", $gray); ImagePng($im); ImageDestroy($im); diff --git a/frontends/php/history.html b/frontends/php/history.html index 0287696e..44f87333 100644 --- a/frontends/php/history.html +++ b/frontends/php/history.html @@ -158,7 +158,7 @@ if($action=="showhistory") { - show_history($itemid,$from,$period); + @show_history($itemid,$from,$period); show_footer(); exit; } diff --git a/frontends/php/map.html b/frontends/php/map.html index 694337ed..920fe032 100644 --- a/frontends/php/map.html +++ b/frontends/php/map.html @@ -14,7 +14,7 @@ $width=DBget_field($result,0,1); $height=DBget_field($result,0,2); -# Header( "Content-type: text/html"); +// Header( "Content-type: text/html"); Header( "Content-type: image/png"); Header( "Expires: Mon, 17 Aug 1998 12:51:50 GMT"); @@ -139,7 +139,7 @@ # ImageDestroy($img); } - ImageString($im,0,$width-147,$height-10, "http://zabbix.sourceforge.net", $gray); + ImageStringUp($im,0,$width-10,$height-4, "http://zabbix.sourceforge.net", $gray); ImagePng($im); ImageDestroy($im); diff --git a/frontends/php/report1.html b/frontends/php/report1.html index fc3d6553..77a4d920 100644 --- a/frontends/php/report1.html +++ b/frontends/php/report1.html @@ -28,7 +28,7 @@ <td><? echo $str; ?></td> </tr> - <tr bgcolor="#eeeeee"> + <tr bgcolor="#dddddd"> <td>Number of values stored in table history</td> <td><? echo $stats["history_count"]; ?></td> </tr> diff --git a/frontends/php/sysmap.html b/frontends/php/sysmap.html index dc8c49cd..6e3a178d 100644 --- a/frontends/php/sysmap.html +++ b/frontends/php/sysmap.html @@ -211,10 +211,8 @@ $icons=array(); $icons[0]="Server"; $icons[1]="Printer"; - $icons[2]="Router"; - $icons[3]="Hub"; - $icons[4]="Notebook"; - for($i=0;$i<5;$i++) + $icons[2]="Hub"; + for($i=0;$i<3;$i++) { if(isset($hostid) && ($icon==$icons[$i])) { diff --git a/frontends/php/trend.html b/frontends/php/trend.html index c70b5e97..81fa4f3d 100644 --- a/frontends/php/trend.html +++ b/frontends/php/trend.html @@ -165,7 +165,11 @@ ImageString($im, 2,$sizeX/2 -50, $sizeY+$shiftY+3, "NO DATA FOR THIS PERIOD" , $red); } - ImageString($im,0,$shiftX+$sizeX-85,$sizeY+$shiftY+28, "http://zabbix.sourceforge.net", $gray); + ImageString($im, 1,$shiftX, $sizeY+$shiftY+15, "MIN" , $green); + ImageString($im, 1,$shiftX+20, $sizeY+$shiftY+15, "AVG" , $yellow); + ImageString($im, 1,$shiftX+40, $sizeY+$shiftY+15, "MAX" , $red); + + ImageStringUp($im,0,2*$shiftX+$sizeX+40,$sizeY+2*$shiftY, "http://zabbix.sourceforge.net", $gray); ImagePng($im); ImageDestroy($im); diff --git a/frontends/php/trends.html b/frontends/php/trends.html index a0ba7b27..f53addc1 100644 --- a/frontends/php/trends.html +++ b/frontends/php/trends.html @@ -7,8 +7,8 @@ <? show_table_header_begin(); - $result=DBselect("select description from items where itemid=$itemid"); - echo "TRENDS [",DBget_field($result,0,0),"]"; + $result=DBselect("select i.description,h.host from items i,hosts h where i.hostid=h.hostid and i.itemid=$itemid"); + echo "TRENDS [",DBget_field($result,0,1),":",DBget_field($result,0,0),"]"; show_table_v_delimiter(); diff --git a/frontends/php/users.html b/frontends/php/users.html index 3c518a74..d85eec92 100644 --- a/frontends/php/users.html +++ b/frontends/php/users.html @@ -80,7 +80,7 @@ <? echo "<br>"; - insert_user_form($userid); + @insert_user_form($userid); ?> <? diff --git a/include/db.c b/include/db.c index 69b73733..5ac7ae64 100644 --- a/include/db.c +++ b/include/db.c @@ -5,11 +5,11 @@ #include "db.h" #include "common.h" -#ifdef USE_MYSQL +#ifdef HAVE_MYSQL MYSQL mysql; #endif -#ifdef USE_POSTGRESQL +#ifdef HAVE_PGSQL PGconn *conn; #endif @@ -19,7 +19,7 @@ */ void DBconnect( void ) { -#ifdef USE_MYSQL +#ifdef HAVE_MYSQL if( ! mysql_connect( &mysql, NULL, DB_USER, DB_PASSWD ) ) { syslog(LOG_ERR, "Failed to connect to database: Error: %s\n",mysql_error(&mysql) ); @@ -31,7 +31,7 @@ void DBconnect( void ) exit( FAIL ); } #endif -#ifdef USE_POSTGRESQL +#ifdef HAVE_PGSQL /* conn = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName); */ conn = PQsetdb(NULL, NULL, NULL, NULL, DB_NAME); @@ -52,7 +52,7 @@ void DBconnect( void ) int DBexecute(char *query) { -#ifdef USE_MYSQL +#ifdef HAVE_MYSQL syslog( LOG_DEBUG, "Executing query:%s\n",query); if( mysql_query(&mysql,query) != 0 ) @@ -62,7 +62,7 @@ int DBexecute(char *query) return FAIL; } #endif -#ifdef USE_POSTGRESQL +#ifdef HAVE_PGSQL PGresult *result; syslog( LOG_DEBUG, "Executing query:%s\n",query); @@ -92,7 +92,7 @@ int DBexecute(char *query) */ DB_RESULT *DBselect(char *query) { -#ifdef USE_MYSQL +#ifdef HAVE_MYSQL syslog( LOG_DEBUG, "Executing query:%s\n",query); if( mysql_query(&mysql,query) != 0 ) @@ -103,7 +103,7 @@ DB_RESULT *DBselect(char *query) } return mysql_store_result(&mysql); #endif -#ifdef USE_POSTGRESQL +#ifdef HAVE_PGSQL PGresult *result; syslog( LOG_DEBUG, "Executing query:%s\n",query); @@ -128,7 +128,7 @@ DB_RESULT *DBselect(char *query) */ char *DBget_field(DB_RESULT *result, int rownum, int fieldnum) { -#ifdef USE_MYSQL +#ifdef HAVE_MYSQL MYSQL_ROW row; mysql_data_seek(result, rownum); @@ -136,7 +136,7 @@ char *DBget_field(DB_RESULT *result, int rownum, int fieldnum) syslog(LOG_DEBUG, "Got field:%s", row[fieldnum] ); return row[fieldnum]; #endif -#ifdef USE_POSTGRESQL +#ifdef HAVE_PGSQL return PQgetvalue(result, rownum, fieldnum); #endif } @@ -146,10 +146,10 @@ char *DBget_field(DB_RESULT *result, int rownum, int fieldnum) */ int DBnum_rows(DB_RESULT *result) { -#ifdef USE_MYSQL +#ifdef HAVE_MYSQL return mysql_num_rows(result); #endif -#ifdef USE_POSTGRESQL +#ifdef HAVE_PGSQL return PQntuples(result); #endif } diff --git a/include/db.h b/include/db.h index 1bc3ee63..ff1f307d 100644 --- a/include/db.h +++ b/include/db.h @@ -1,13 +1,13 @@ -#define USE_MYSQL 1 - #ifndef MON_DB_H #define MON_DB_H - -#ifdef USE_MYSQL -#include "mysql.h" + +#include "config.h" + +#ifdef HAVE_MYSQL + #include "mysql.h" #endif -#ifdef USE_POSTGRESQL +#ifdef HAVE_PGSQL #include "libpq-fe.h" #endif @@ -21,12 +21,12 @@ #define DB_FUNCTION struct function_type #define DB_MEDIA struct media_type -#ifdef USE_MYSQL +#ifdef HAVE_MYSQL #define DB_RESULT MYSQL_RES #define DBfree_result mysql_free_result #endif -#ifdef USE_POSTGRESQL +#ifdef HAVE_PGSQL #define DB_RESULT PGresult #define DBfree_result PQclear #endif diff --git a/src/zabbix_agent/Makefile.in b/src/zabbix_agent/Makefile.in index 316edf59..f4bed3e4 100644 --- a/src/zabbix_agent/Makefile.in +++ b/src/zabbix_agent/Makefile.in @@ -2,9 +2,11 @@ all: - @CC@ -o ../../bin/zabbix_agent @CFLAGS@ -I../../include zabbix_agent.c sysinfo.c -Wall @LIBS@ + @CC@ -o ../../bin/zabbix_agent @CFLAGS@ -I../../include zabbix_agent.c sysinfo.c -Wall @LIBS@ + @CC@ -o ../../bin/zabbix_agentd @CFLAGS@ -I../../include zabbix_agentd.c sysinfo.c -Wall @LIBS@ clean: rm -fv *.o rm -fv ../../../zabbix_agent + rm -fv ../../../zabbix_agentd diff --git a/src/zabbix_agent/sysinfo.c b/src/zabbix_agent/sysinfo.c index 8cf2caf9..c58805e9 100644 --- a/src/zabbix_agent/sysinfo.c +++ b/src/zabbix_agent/sysinfo.c @@ -30,6 +30,123 @@ #include "common.h" #include "sysinfo.h" + +COMMAND commands[]= + { + {"memory[total]" ,TOTALMEM, 0}, + {"memory[shared]" ,SHAREDMEM, 0}, + {"memory[buffers]" ,BUFFERSMEM, 0}, + {"memory[cached]" ,CACHEDMEM, 0}, + {"memory[free]" ,FREEMEM, 0}, + + {"diskfree[/]" ,DF, "/"}, + {"diskfree[/opt]" ,DF, "/opt"}, + {"diskfree[/tmp]" ,DF, "/tmp"}, + {"diskfree[/usr]" ,DF, "/usr"}, + {"diskfree[/home]" ,DF, "/home"}, + {"diskfree[/var]" ,DF, "/var"}, + + {"inodefree[/]" ,INODE, "/"}, + {"inodefree[/opt]" ,INODE, "/opt"}, + {"inodefree[/tmp]" ,INODE, "/tmp"}, + {"inodefree[/usr]" ,INODE, "/usr"}, + {"inodefree[/home]" ,INODE, "/home"}, + {"inodefree[/var]" ,INODE, "/var"}, + + {"cksum[/etc/inetd_conf]" ,EXECUTE, "(cksum /etc/inetd.conf 2>/dev/null || echo '-2') | cut -f1 -d' '"}, + {"cksum[/etc/services]" ,EXECUTE, "(cksum /etc/services 2>/dev/null || echo '-2') | cut -f1 -d' '"}, + {"cksum[/vmlinuz]" ,EXECUTE, "(cksum /vmlinuz 2>/dev/null || echo '-2') | cut -f1 -d' '"}, + {"cksum[/etc/passwd]" ,EXECUTE, "(cksum /etc/passwd 2>/dev/null || echo '-2') | cut -f1 -d' '"}, + {"cksum[/usr/sbin/sshd]" ,EXECUTE, "(cksum /usr/sbin/sshd 2>/dev/null || echo '-2') | cut -f1 -d' '"}, + {"cksum[/usr/bin/ssh]" ,EXECUTE, "(cksum /usr/bin/ssh 2>/dev/null || echo '-2') | cut -f1 -d' '"}, + + {"filesize[/var/log/syslog]" ,FILESIZE, "/var/log/syslog"}, + + {"swap[free]" ,SWAPFREE, 0}, + {"swap[total]" ,SWAPTOTAL, 0}, + +/**************************************** + All these perameters require more than 1 second to retrieve. + + {"swap[in]" ,EXECUTE, "vmstat -n 1 2|tail -1|cut -b37-40"}, + {"swap[out]" ,EXECUTE, "vmstat -n 1 2|tail -1|cut -b41-44"}, + + {"io[in]" ,EXECUTE, "vmstat -n 1 2|tail -1|cut -b45-50"}, + {"io[out]" ,EXECUTE, "vmstat -n 1 2|tail -1|cut -b51-56"}, + + {"system[interrupts]" ,EXECUTE, "vmstat -n 1 2|tail -1|cut -b57-61"}, + {"system[switches]" ,EXECUTE, "vmstat -n 1 2|tail -1|cut -b62-67"}, +***************************************/ + + {"system[procload]" ,PROCLOAD, 0}, + {"system[procload5]" ,PROCLOAD5, 0}, + {"system[procload15]" ,PROCLOAD15, 0}, + {"system[proccount]" ,PROCCOUNT, 0}, + {"system[procrunning]" ,EXECUTE, "cat /proc/loadavg|cut -f1 -d'/'|cut -f4 -d' '"}, + {"system[uptime]" ,UPTIME, 0}, + {"system[users]" ,EXECUTE, "who|wc -l"}, + + {"ping" ,PING, 0}, + {"tcp_count" ,EXECUTE, "netstat -tn|grep EST|wc -l"}, + +/* {"net[listen_21]" ,EXECUTE, "netstat -lnt|grep -v grep|grep ':21 '|wc -l"}, */ +/* {"net[listen_21]" ,EXECUTE, "cat /proc/net/tcp|grep '0015 00000000:0000 0A'|wc -l"}, */ + {"net[listen_21]" ,TCP_LISTEN, "0015"}, + {"net[listen_22]" ,TCP_LISTEN, "0016"}, + {"net[listen_23]" ,TCP_LISTEN, "0017"}, + {"net[listen_25]" ,TCP_LISTEN, "0019"}, + {"net[listen_80]" ,TCP_LISTEN, "0050"}, + {"net[listen_110]" ,TCP_LISTEN, "006E"}, + {"net[listen_143]" ,TCP_LISTEN, "008F"}, + {0 ,0} + }; + +float process(char *command) +{ + char *p; + float result; + int i; + float (*function)(); + char *parameter = NULL; + + + for( p=command+strlen(command)-1; p>command && ( *p=='\r' || *p =='\n' || *p == ' ' ); --p ); + p[1]=0; + + + i=0; + for(;;) + { + if( commands[i].key == 0) + { + function=0; + break; + } + if( strcmp(commands[i].key,command) == 0) + { + function=commands[i].function; + parameter=commands[i].parameter; + break; + } + i++; + } + + if( function !=0 ) + { + result = function(parameter); + if( result == FAIL ) + { + result = NOTSUPPORTED; + } + } + else + { + result=NOTSUPPORTED; + } + + return result; +} + float FILESIZE(const char * filename) { struct stat buf; diff --git a/src/zabbix_agent/sysinfo.h b/src/zabbix_agent/sysinfo.h index 4ea17a52..906e3e16 100644 --- a/src/zabbix_agent/sysinfo.h +++ b/src/zabbix_agent/sysinfo.h @@ -1,6 +1,8 @@ #ifndef MON_SYSINFO_H #define MON_SYSINFO_H +float process(char *command); + float INODE(const char * mountPoint); float FILESIZE(const char * filename); float DF(const char * mountPoint); @@ -21,4 +23,13 @@ float TCP_LISTEN(const char *porthex); float UPTIME(void); float EXECUTE(char *command); +#define COMMAND struct command_type +COMMAND +{ + char *key; + void *function; + char *parameter; +}; + + #endif diff --git a/src/zabbix_agent/zabbix_agent.c b/src/zabbix_agent/zabbix_agent.c index 95de4a78..3db1439a 100644 --- a/src/zabbix_agent/zabbix_agent.c +++ b/src/zabbix_agent/zabbix_agent.c @@ -1,5 +1,3 @@ -/* #define TEST */ - #include "config.h" #include <stdlib.h> @@ -22,76 +20,6 @@ #include "sysinfo.h" #include "zabbix_agent.h" -COMMAND commands[]= - { - {"memory[total]" ,TOTALMEM, 0}, - {"memory[shared]" ,SHAREDMEM, 0}, - {"memory[buffers]" ,BUFFERSMEM, 0}, - {"memory[cached]" ,CACHEDMEM, 0}, - {"memory[free]" ,FREEMEM, 0}, - - {"diskfree[/]" ,DF, "/"}, - {"diskfree[/opt]" ,DF, "/opt"}, - {"diskfree[/tmp]" ,DF, "/tmp"}, - {"diskfree[/usr]" ,DF, "/usr"}, - {"diskfree[/home]" ,DF, "/home"}, - {"diskfree[/var]" ,DF, "/var"}, - - {"inodefree[/]" ,INODE, "/"}, - {"inodefree[/opt]" ,INODE, "/opt"}, - {"inodefree[/tmp]" ,INODE, "/tmp"}, - {"inodefree[/usr]" ,INODE, "/usr"}, - {"inodefree[/home]" ,INODE, "/home"}, - {"inodefree[/var]" ,INODE, "/var"}, - - {"cksum[/etc/inetd_conf]" ,EXECUTE, "(cksum /etc/inetd.conf 2>/dev/null || echo '-2') | cut -f1 -d' '"}, - {"cksum[/etc/services]" ,EXECUTE, "(cksum /etc/services 2>/dev/null || echo '-2') | cut -f1 -d' '"}, - {"cksum[/vmlinuz]" ,EXECUTE, "(cksum /vmlinuz 2>/dev/null || echo '-2') | cut -f1 -d' '"}, - {"cksum[/etc/passwd]" ,EXECUTE, "(cksum /etc/passwd 2>/dev/null || echo '-2') | cut -f1 -d' '"}, - {"cksum[/usr/sbin/sshd]" ,EXECUTE, "(cksum /usr/sbin/sshd 2>/dev/null || echo '-2') | cut -f1 -d' '"}, - {"cksum[/usr/bin/ssh]" ,EXECUTE, "(cksum /usr/bin/ssh 2>/dev/null || echo '-2') | cut -f1 -d' '"}, - - {"filesize[/var/log/syslog]" ,FILESIZE, "/var/log/syslog"}, - - {"swap[free]" ,SWAPFREE, 0}, - {"swap[total]" ,SWAPTOTAL, 0}, - -/**************************************** - All these perameters require more than 1 second to retrieve. - - {"swap[in]" ,EXECUTE, "vmstat -n 1 2|tail -1|cut -b37-40"}, - {"swap[out]" ,EXECUTE, "vmstat -n 1 2|tail -1|cut -b41-44"}, - - {"io[in]" ,EXECUTE, "vmstat -n 1 2|tail -1|cut -b45-50"}, - {"io[out]" ,EXECUTE, "vmstat -n 1 2|tail -1|cut -b51-56"}, - - {"system[interrupts]" ,EXECUTE, "vmstat -n 1 2|tail -1|cut -b57-61"}, - {"system[switches]" ,EXECUTE, "vmstat -n 1 2|tail -1|cut -b62-67"}, -***************************************/ - - {"system[procload]" ,PROCLOAD, 0}, - {"system[procload5]" ,PROCLOAD5, 0}, - {"system[procload15]" ,PROCLOAD15, 0}, - {"system[proccount]" ,PROCCOUNT, 0}, - {"system[procrunning]" ,EXECUTE, "cat /proc/loadavg|cut -f1 -d'/'|cut -f4 -d' '"}, - {"system[uptime]" ,UPTIME, 0}, - {"system[users]" ,EXECUTE, "who|wc -l"}, - - {"ping" ,PING, 0}, - {"tcp_count" ,EXECUTE, "netstat -tn|grep EST|wc -l"}, - -/* {"net[listen_21]" ,EXECUTE, "netstat -lnt|grep -v grep|grep ':21 '|wc -l"}, */ -/* {"net[listen_21]" ,EXECUTE, "cat /proc/net/tcp|grep '0015 00000000:0000 0A'|wc -l"}, */ - {"net[listen_21]" ,TCP_LISTEN, "0015"}, - {"net[listen_22]" ,TCP_LISTEN, "0016"}, - {"net[listen_23]" ,TCP_LISTEN, "0017"}, - {"net[listen_25]" ,TCP_LISTEN, "0019"}, - {"net[listen_80]" ,TCP_LISTEN, "0050"}, - {"net[listen_110]" ,TCP_LISTEN, "006E"}, - {"net[listen_143]" ,TCP_LISTEN, "008F"}, - {0 ,0} - }; - void signal_handler( int sig ) { if( SIGALRM == sig ) @@ -140,38 +68,17 @@ int check_security(void) return SUCCEED; } -int main() +float process_input() { - char *s,*p; - float result; - int i; - float (*function)(); - char *parameter = NULL; + char s[1024]; -#ifdef TEST - i=0; - for(;;) - { - if( commands[i].key == 0) - { - exit(0); - } - function=commands[i].function; - parameter=commands[i].parameter; + fgets(s,1024,stdin); - result=function(parameter); - if( result == FAIL ) - { - printf("%s - NOT SUPPORTED\n",commands[i].key); - } - else - { - printf("%s\t - %f\n",commands[i].key,result); - } - i++; - } -#endif + return process(s); +} +int main() +{ if(check_security() == FAIL) { exit(FAIL); @@ -184,49 +91,10 @@ int main() alarm(AGENT_TIMEOUT); - s=(char *) malloc( 1024 ); + printf("%f\n",process_input()); - fgets(s,1024,stdin); - - for( p=s+strlen(s)-1; p>s && ( *p=='\r' || *p =='\n' || *p == ' ' ); --p ); - p[1]=0; - - i=0; - for(;;) - { - if( commands[i].key == 0) - { - function=0; - break; - } - if( strcmp(commands[i].key,s) == 0) - { - function=commands[i].function; - parameter=commands[i].parameter; - break; - } - i++; - } - - if( function !=0 ) - { - result=function(parameter); - if( result == FAIL ) - { - printf("%d\n",NOTSUPPORTED); - } - else - { - printf("%f",result); - } - } - else - { - printf("%d\n",NOTSUPPORTED); - } fflush(stdout); - free(s); alarm(0); return SUCCEED; diff --git a/src/zabbix_agent/zabbix_agent.h b/src/zabbix_agent/zabbix_agent.h index 9f92f835..f421d1a2 100644 --- a/src/zabbix_agent/zabbix_agent.h +++ b/src/zabbix_agent/zabbix_agent.h @@ -1,12 +1,4 @@ #ifndef MON_MONAGENT_H #define MON_MONAGENT_H -#define COMMAND struct command_type -COMMAND -{ - char *key; - void *function; - char *parameter; -}; - #endif diff --git a/src/zabbix_agent/zabbix_agentd.c b/src/zabbix_agent/zabbix_agentd.c new file mode 100644 index 00000000..61ba4498 --- /dev/null +++ b/src/zabbix_agent/zabbix_agentd.c @@ -0,0 +1,274 @@ +#include "config.h" + +#include <string.h> + +#include <netdb.h> + +#include <syslog.h> + +#include <stdlib.h> +#include <stdio.h> + +#include <unistd.h> +#include <signal.h> + +#include <errno.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> + +/* For config file operations */ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#include "common.h" +#include "sysinfo.h" +#include "zabbix_agent.h" + +#define LISTENQ 1024 + +static pid_t *pids; + +void signal_handler( int sig ) +{ + if( SIGALRM == sig ) + { + signal( SIGALRM, signal_handler ); + syslog( LOG_WARNING, "Timeout while answering request"); + } + + if( SIGQUIT == sig || SIGINT == sig || SIGTERM == sig ) + { + syslog( LOG_WARNING, "Got signal. Exiting ..."); + exit( FAIL ); + } +} + +void daemon_init(void) +{ + int i; + pid_t pid; + + if( (pid = fork()) != 0 ) + { + exit( 0 ); + } + + setsid(); + + signal( SIGHUP, SIG_IGN ); + + if( (pid = fork()) !=0 ) + { + exit( 0 ); + } + + chdir("/"); + umask(0); + + for(i=0;i<MAXFD;i++) + { + close(i); + } +} + + +int check_security(int sockfd) +{ + char *sname; + char config[16]; + struct sockaddr_in name; + int i; + int file; + + if(getpeername(sockfd, (struct sockaddr *)&name, (size_t *)&i) == 0) + { + file=open("/etc/zabbix/zabbix_agent.conf",O_RDONLY); + if(file == -1) + { + syslog( LOG_CRIT, "Cannot open /etc/zabbix/zabbix_agent.conf"); + exit(1); + } + i=read(file, config, 16); + config[i-1]=0; + close(file); + + i=sizeof(struct sockaddr_in); + + sname=inet_ntoa(name.sin_addr); + if(strcmp(sname,config)!=0) + { + syslog( LOG_WARNING, "Connection from [%s] rejected",sname); + return FAIL; + } + } + return SUCCEED; +} + +void process_child(int sockfd) +{ + ssize_t nread; + char line[1024]; + char result[1024]; + double res; + void *sigfunc; + + for(;;) + { +// sigfunc = signal( SIGALRM, signal_handler ); +// alarm(AGENT_TIMEOUT); + + if( (nread = read(sockfd, line, 1024)) == 0) + return; + +// alarm(0); +// signal(SIGALRM, sigfunc); + + line[nread-1]=0; + +// printf("Got line:{%s}\n",line); + + syslog( LOG_DEBUG, "Got line:%s", line); + res=process(line); + sprintf(result,"%f",res); + syslog( LOG_DEBUG, "Sending back:%s", result); + write(sockfd,result,strlen(result)); + } +} + +int tcp_listen(const char *host, const char *serv, socklen_t *addrlenp) +{ + int listenfd, n; + const int on=1; + struct addrinfo hints, *res, *ressave; + + bzero(&hints,sizeof(struct addrinfo)); + hints.ai_flags = AI_PASSIVE; + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + + if( (n = getaddrinfo(host,serv, &hints, &res)) != 0) + { + perror("getaddrinfo()"); + exit(1); + } + + ressave = res; + + do { + listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + if( listenfd <0) + continue; + if(setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) !=0 ) + { + perror("setsockopt()"); + exit(1); + } + if(bind(listenfd,res->ai_addr,res->ai_addrlen) == 0) + break; + close(listenfd); + } while ((res = res ->ai_next) != NULL); + + if (res == NULL) + { + perror("tcp_listen"); + exit(1); + } + + if(listen(listenfd, LISTENQ) !=0 ) + { + perror("listen()"); + exit(1); + } + + if(addrlenp) + *addrlenp = res->ai_addrlen; + + freeaddrinfo(ressave); + + return (listenfd); +} + +void child_main(int i,int listenfd, int addrlen) +{ + int connfd; + socklen_t clilen; + struct sockaddr *cliaddr; + + cliaddr=malloc(addrlen); + + printf("child %ld started\n",(long)getpid()); + + for(;;) + { + clilen = addrlen; + connfd=accept(listenfd,cliaddr, &clilen); + if( check_security(connfd) == SUCCEED) + { + process_child(connfd); + } + close(connfd); + } +} + +pid_t child_make(int i,int listenfd, int addrlen) +{ + pid_t pid; + + if((pid = fork()) >0) + { + return (pid); + } + + /* never returns */ + child_main(i, listenfd, addrlen); + + /* avoid compilator warning */ + return 0; +} + +int main() +{ + int listenfd; + socklen_t addrlen; + int i, ret; + + char *host="127.0.0.1"; + char *port="10000"; + + daemon_init(); + + signal( SIGINT, signal_handler ); + signal( SIGQUIT, signal_handler ); + signal( SIGTERM, signal_handler ); + signal( SIGALRM, signal_handler ); + +// if(check_security() == FAIL) +// { +// exit(FAIL); +// } + + openlog("zabbix_agentd",LOG_PID,LOG_USER); +// ret=setlogmask(LOG_UPTO(LOG_DEBUG)); + ret=setlogmask(LOG_UPTO(LOG_WARNING)); + + syslog( LOG_WARNING, "zabbix_agentd started"); + + listenfd = tcp_listen(host,port,&addrlen); + + pids = calloc(10, sizeof(pid_t)); + + for(i = 0; i< 10; i++) + { + pids[i] = child_make(i, listenfd, addrlen); + syslog( LOG_WARNING, "zabbix_agentd #%d started", pids[i]); + } + + for(;;) + { + pause(); + } + + return SUCCEED; +} diff --git a/src/zabbix_sucker/Makefile.in b/src/zabbix_sucker/Makefile.in index ac5f253f..b9007f8b 100644 --- a/src/zabbix_sucker/Makefile.in +++ b/src/zabbix_sucker/Makefile.in @@ -5,9 +5,9 @@ LIBS = @LIBS@ @MYSQL_LFLAGS@ @PGSQL_LFLAGS@ all: - @CC@ -o ../../bin/zabbix_sucker @CFLAGS@ -I../../include $(INCLUDE) zabbix_sucker.c ../../include/db.c ../../include/functions.c ../../include/expression.c -Wall $(LIBS) + @CC@ -o ../../bin/zabbix_suckerd @CFLAGS@ -I../../include $(INCLUDE) zabbix_sucker.c ../../include/db.c ../../include/functions.c ../../include/expression.c -Wall $(LIBS) clean: rm -fv *.o - rm -fv ../../bin/zabbix_sucker + rm -fv ../../bin/zabbix_suckerd diff --git a/src/zabbix_sucker/zabbix_sucker.c b/src/zabbix_sucker/zabbix_sucker.c index b35b1556..9f0fde7c 100644 --- a/src/zabbix_sucker/zabbix_sucker.c +++ b/src/zabbix_sucker/zabbix_sucker.c @@ -93,7 +93,7 @@ int get_value_SNMPv1(double *result,DB_ITEM *item) /* Initialize the SNMP library - init_snmp("zabbix_sucker"); + init_snmp("zabbix_suckerd"); */ /* @@ -511,14 +511,14 @@ int main(int argc, char **argv) } } - openlog("zabbix_sucker",LOG_PID,LOG_USER); + openlog("zabbix_suckerd",LOG_PID,LOG_USER); // ret=setlogmask(LOG_UPTO(LOG_DEBUG)); ret=setlogmask(LOG_UPTO(LOG_WARNING)); - syslog( LOG_WARNING, "zabbix_sucker #%d started",sucker_num); + syslog( LOG_WARNING, "zabbix_suckerd #%d started",sucker_num); #ifdef HAVE_UCD_SNMP_UCD_SNMP_CONFIG_H - init_snmp("zabbix_sucker"); + init_snmp("zabbix_suckerd"); #endif DBconnect(); |