diff options
| author | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2002-03-31 12:52:37 +0000 |
|---|---|---|
| committer | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2002-03-31 12:52:37 +0000 |
| commit | 69ac0b14036019a94cc3ceb44d447773df4198d0 (patch) | |
| tree | 02c9c6fac12eedfad916693b50c76a3db9514328 | |
| parent | 1cae722c88b6402f0c59a8c8503441d7e338252b (diff) | |
| download | zabbix-69ac0b14036019a94cc3ceb44d447773df4198d0.tar.gz zabbix-69ac0b14036019a94cc3ceb44d447773df4198d0.tar.xz zabbix-69ac0b14036019a94cc3ceb44d447773df4198d0.zip | |
- added column value_type to table items_template (Alexei)
- support for system[uname] (Alexei)
- support for system[hostname] (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@342 97f52cf1-0a1b-0410-bd0e-c28be96e8082
| -rw-r--r-- | ChangeLog | 5 | ||||
| -rw-r--r-- | create/data/data.sql | 256 | ||||
| -rw-r--r-- | create/mysql/schema.sql | 1 | ||||
| -rw-r--r-- | create/postgresql/schema.sql | 1 | ||||
| -rw-r--r-- | frontends/php/history.php | 15 | ||||
| -rw-r--r-- | frontends/php/include/config.inc | 59 | ||||
| -rw-r--r-- | frontends/php/items.php | 4 | ||||
| -rw-r--r-- | frontends/php/latest.php | 10 | ||||
| -rw-r--r-- | include/cfg.c | 53 | ||||
| -rw-r--r-- | include/functions.c | 20 | ||||
| -rw-r--r-- | src/zabbix_agent/sysinfo.c | 280 | ||||
| -rw-r--r-- | src/zabbix_agent/sysinfo.h | 6 | ||||
| -rw-r--r-- | src/zabbix_agent/zabbix_agent.c | 31 | ||||
| -rw-r--r-- | src/zabbix_agent/zabbix_agentd.c | 12 | ||||
| -rw-r--r-- | src/zabbix_sucker/zabbix_sucker.c | 9 | ||||
| -rw-r--r-- | src/zabbix_trapper/zabbix_trapperd.c | 2 | ||||
| -rw-r--r-- | upgrades/dbpatches/1.0beta2_to_1.0beta3/mysql/patch.sql | 6 | ||||
| -rw-r--r-- | upgrades/dbpatches/1.0beta2_to_1.0beta3/postgresql/patch.sql | 5 |
18 files changed, 500 insertions, 275 deletions
@@ -1,10 +1,10 @@ Not ready yet: [ Common parser (cfg.c) ] -[ Support for system[uname] ] [ Update task status on SF ] +[ Support for Service Tree ] [ Support for flexible permissions ] [ Better validation of trigger expressions ] [ Support for nodata(). Do we need it ? ] @@ -16,6 +16,9 @@ Not ready yet: Changes for 1.0beta3: + - added column value_type to table items_template (Alexei) + - support for system[uname] (Alexei) + - support for system[hostname] (Alexei) - parameter Server can consist of list of Zabbix servers (Alexei) - SO_LINGER is default socket option for zabbix_sender (Alexei) - added support of NoTimeWait for zabbix_trapperd (Alexei) diff --git a/create/data/data.sql b/create/data/data.sql index 2f269587..7c015188 100644 --- a/create/data/data.sql +++ b/create/data/data.sql @@ -21,132 +21,136 @@ insert into users (userid,groupid,alias,name,surname,passwd) values (1,1,'Admin' -- Data for table items_template -- -insert into items_template (itemtemplateid,description,key_,delay) - values (1,'Free memory','memory[free]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (2,'Free disk space on /','diskfree[/]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (3,'Free disk space on /tmp','diskfree[/tmp]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (4,'Free disk space on /usr','diskfree[/usr]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (5,'Free number of inodes on /','inodefree[/]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (6,'Free number of inodes on /opt','inodefree[/opt]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (7,'Free number of inodes on /tmp','inodefree[/tmp]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (8,'Free number of inodes on /usr','inodefree[/usr]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (9,'Number of processes','system[proccount]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (10,'Processor load','system[procload]', 5); -insert into items_template (itemtemplateid,description,key_,delay) - values (11,'Processor load5','system[procload5]', 10); -insert into items_template (itemtemplateid,description,key_,delay) - values (12,'Processor load15','system[procload15]', 20); -insert into items_template (itemtemplateid,description,key_,delay) - values (13,'Number of running processes','system[procrunning]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (14,'Free swap space (Kb)','swap[free]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (16,'Size of /var/log/syslog','filesize[/var/log/syslog]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (17,'Number of users connected','system[users]', 30); ---insert into items_template (itemtemplateid,description,key_,delay) --- values (18,'Number of established TCP connections','tcp_count', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (19,'Checksum of /etc/inetd.conf','cksum[/etc/inetd.conf]', 600); -insert into items_template (itemtemplateid,description,key_,delay) - values (20,'Checksum of /vmlinuz','cksum[/vmlinuz]', 600); -insert into items_template (itemtemplateid,description,key_,delay) - values (21,'Checksum of /etc/passwd','cksum[/etc/passwd]', 600); -insert into items_template (itemtemplateid,description,key_,delay) - values (22,'Ping to the server (TCP)','ping', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (23,'Free disk space on /home','diskfree[/home]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (24,'Free number of inodes on /home','inodefree[/home]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (25,'Free disk space on /var','diskfree[/var]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (26,'Free disk space on /opt','diskfree[/opt]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (27,'Host uptime (in sec)','system[uptime]', 300); -insert into items_template (itemtemplateid,description,key_,delay) - values (28,'Total memory (kB)','memory[total]', 1800); -insert into items_template (itemtemplateid,description,key_,delay) - values (29,'Shared memory (kB)','memory[shared]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (30,'Buffers memory (kB)','memory[buffers]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (31,'Cached memory (kB)','memory[cached]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (32,'Total swap space (Kb)','swap[total]', 1800); ---insert into items_template (itemtemplateid,description,key_,delay) --- values (33,'Amount of memory swapped in from disk (kB/s)','swap[in]', 30); ---insert into items_template (itemtemplateid,description,key_,delay) --- values (34,'Amount of memory swapped to disk (kB/s)','swap[out]', 30); ---insert into items_template (itemtemplateid,description,key_,delay) --- values (35,'Blocks sent to a block device (blocks/s)','io[in]', 30); ---insert into items_template (itemtemplateid,description,key_,delay) --- values (36,'Blocks received from a block device (blocks/s)','io[out]', 30); ---insert into items_template (itemtemplateid,description,key_,delay) --- values (37,'The number of interrupts per second, including the clock','system[interrupts]', 30); ---insert into items_template (itemtemplateid,description,key_,delay) --- values (38,'The number of context switches per second','system[switches]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (39,'Email (SMTP) server is running','check_service[smtp]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (40,'FTP server is running','check_service[ftp]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (41,'SSH server is running','check_service[ssh]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (42,'Telnet server is running','net[listen_23]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (43,'WEB server is running','net[listen_80]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (44,'POP3 server is running','check_service[pop]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (45,'IMAP server is running','check_service[imap]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (46,'Checksum of /usr/sbin/sshd','cksum[/usr/sbin/sshd]', 600); -insert into items_template (itemtemplateid,description,key_,delay) - values (47,'Checksum of /usr/bin/ssh','cksum[/usr/bin/ssh]', 600); -insert into items_template (itemtemplateid,description,key_,delay) - values (48,'Checksum of /etc/services','cksum[/etc/services]', 600); -insert into items_template (itemtemplateid,description,key_,delay) - values (49,'Number of disks read/write operations','io[disk_io]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (50,'Number of disks read operations','io[disk_rio]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (51,'Number of disks write operations','io[disk_wio]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (52,'Number of block read from disks','io[disk_rblk]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (53,'Number of block written to disks','io[disk_wblk]', 30); -insert into items_template (itemtemplateid,description,key_,delay) - values (54,'News (NNTP) server is running','check_service[nntp]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (55,'Number of running processes inetd','proc_cnt[inetd]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (56,'Number of running processes apache','proc_cnt[httpd]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (57,'Number of running processes mysqld','proc_cnt[mysqld]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (58,'Number of running processes syslogd','proc_cnt[syslogd]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (59,'Number of running processes sshd','proc_cnt[sshd]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (60,'Number of running processes zabbix_agentd','proc_cnt[zabbix_agentd]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (61,'Number of running processes zabbix_suckerd','proc_cnt[zabbix_suckerd]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (62,'Number of running processes zabbix_trapperd','proc_cnt[zabbix_trapperd]', 60); -insert into items_template (itemtemplateid,description,key_,delay) - values (63,'Maximum number of processes','kern[maxproc]', 1800); -insert into items_template (itemtemplateid,description,key_,delay) - values (64,'Maximum number of opened files','kern[maxfiles]', 1800); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (1,'Free memory','memory[free]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (2,'Free disk space on /','diskfree[/]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (3,'Free disk space on /tmp','diskfree[/tmp]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (4,'Free disk space on /usr','diskfree[/usr]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (5,'Free number of inodes on /','inodefree[/]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (6,'Free number of inodes on /opt','inodefree[/opt]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (7,'Free number of inodes on /tmp','inodefree[/tmp]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (8,'Free number of inodes on /usr','inodefree[/usr]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (9,'Number of processes','system[proccount]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (10,'Processor load','system[procload]', 5, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (11,'Processor load5','system[procload5]', 10, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (12,'Processor load15','system[procload15]', 20, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (13,'Number of running processes','system[procrunning]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (14,'Free swap space (Kb)','swap[free]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (16,'Size of /var/log/syslog','filesize[/var/log/syslog]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (17,'Number of users connected','system[users]', 30, 0); +--insert into items_template (itemtemplateid,description,key_,delay,value_type) +-- values (18,'Number of established TCP connections','tcp_count', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (19,'Checksum of /etc/inetd.conf','cksum[/etc/inetd.conf]', 600, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (20,'Checksum of /vmlinuz','cksum[/vmlinuz]', 600, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (21,'Checksum of /etc/passwd','cksum[/etc/passwd]', 600, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (22,'Ping to the server (TCP)','ping', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (23,'Free disk space on /home','diskfree[/home]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (24,'Free number of inodes on /home','inodefree[/home]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (25,'Free disk space on /var','diskfree[/var]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (26,'Free disk space on /opt','diskfree[/opt]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (27,'Host uptime (in sec)','system[uptime]', 300, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (28,'Total memory (kB)','memory[total]', 1800, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (29,'Shared memory (kB)','memory[shared]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (30,'Buffers memory (kB)','memory[buffers]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (31,'Cached memory (kB)','memory[cached]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (32,'Total swap space (Kb)','swap[total]', 1800, 0); +--insert into items_template (itemtemplateid,description,key_,delay,value_type) +-- values (33,'Amount of memory swapped in from disk (kB/s)','swap[in]', 30, 0); +--insert into items_template (itemtemplateid,description,key_,delay,value_type) +-- values (34,'Amount of memory swapped to disk (kB/s)','swap[out]', 30, 0); +--insert into items_template (itemtemplateid,description,key_,delay,value_type) +-- values (35,'Blocks sent to a block device (blocks/s)','io[in]', 30, 0); +--insert into items_template (itemtemplateid,description,key_,delay,value_type) +-- values (36,'Blocks received from a block device (blocks/s)','io[out]', 30, 0); +--insert into items_template (itemtemplateid,description,key_,delay,value_type) +-- values (37,'The number of interrupts per second, including the clock','system[interrupts]', 30, 0); +--insert into items_template (itemtemplateid,description,key_,delay,value_type) +-- values (38,'The number of context switches per second','system[switches]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (39,'Email (SMTP) server is running','check_service[smtp]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (40,'FTP server is running','check_service[ftp]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (41,'SSH server is running','check_service[ssh]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (42,'Telnet server is running','net[listen_23]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (43,'WEB server is running','net[listen_80]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (44,'POP3 server is running','check_service[pop]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (45,'IMAP server is running','check_service[imap]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (46,'Checksum of /usr/sbin/sshd','cksum[/usr/sbin/sshd]', 600, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (47,'Checksum of /usr/bin/ssh','cksum[/usr/bin/ssh]', 600, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (48,'Checksum of /etc/services','cksum[/etc/services]', 600, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (49,'Number of disks read/write operations','io[disk_io]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (50,'Number of disks read operations','io[disk_rio]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (51,'Number of disks write operations','io[disk_wio]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (52,'Number of block read from disks','io[disk_rblk]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (53,'Number of block written to disks','io[disk_wblk]', 30, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (54,'News (NNTP) server is running','check_service[nntp]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (55,'Number of running processes inetd','proc_cnt[inetd]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (56,'Number of running processes apache','proc_cnt[httpd]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (57,'Number of running processes mysqld','proc_cnt[mysqld]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (58,'Number of running processes syslogd','proc_cnt[syslogd]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (59,'Number of running processes sshd','proc_cnt[sshd]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (60,'Number of running processes zabbix_agentd','proc_cnt[zabbix_agentd]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (61,'Number of running processes zabbix_suckerd','proc_cnt[zabbix_suckerd]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay, value_type) + values (62,'Number of running processes zabbix_trapperd','proc_cnt[zabbix_trapperd]', 60, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (63,'Maximum number of processes','kern[maxproc]', 1800, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (64,'Maximum number of opened files','kern[maxfiles]', 1800, 0); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (65,'Host name','system[hostname]', 1800, 1); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (66,'Host information','system[uname]', 1800, 1); -- -- Data for table triggers_template diff --git a/create/mysql/schema.sql b/create/mysql/schema.sql index 4d47b711..d9a1aeae 100644 --- a/create/mysql/schema.sql +++ b/create/mysql/schema.sql @@ -224,6 +224,7 @@ CREATE TABLE items_template ( description varchar(255) DEFAULT '' NOT NULL, key_ varchar(64) DEFAULT '' NOT NULL, delay int(4) DEFAULT '0' NOT NULL, + value_type int(4) DEFAULT '0' NOT NULL, PRIMARY KEY (itemtemplateid), UNIQUE (key_) ); diff --git a/create/postgresql/schema.sql b/create/postgresql/schema.sql index fae6aacf..0dfed834 100644 --- a/create/postgresql/schema.sql +++ b/create/postgresql/schema.sql @@ -224,6 +224,7 @@ CREATE TABLE items_template ( description varchar(255) DEFAULT '' NOT NULL, key_ varchar(64) DEFAULT '' NOT NULL, delay int4 DEFAULT '0' NOT NULL, + value_type int4 DEFAULT '0' NOT NULL, PRIMARY KEY (itemtemplateid) ); diff --git a/frontends/php/history.php b/frontends/php/history.php index fc23c468..621ab8db 100644 --- a/frontends/php/history.php +++ b/frontends/php/history.php @@ -127,8 +127,15 @@ echo "<TD><B>Value</B></TD>"; echo "</TR>"; - - $result=DBselect("select clock,value from history where itemid=$itemid and clock>$time and clock<$till order by clock desc"); + $item=get_item_by_itemid($itemid); + if($item["value_type"]==0) + { + $result=DBselect("select clock,value from history where itemid=$itemid and clock>$time and clock<$till order by clock desc"); + } + else + { + $result=DBselect("select clock,value from history_str where itemid=$itemid and clock>$time and clock<$till order by clock desc"); + } $col=0; for($i=0;$i<DBnum_rows($result);$i++) { @@ -148,9 +155,9 @@ echo "<TD>$value</TD>"; echo "</TR>"; } - echo "</TABLE><CENTER><BR>"; + echo "</TABLE><CENTER>"; - echo("</CENTER></BODY></HTML>\n"); +// echo("</CENTER></BODY></HTML>\n"); show_footer(); exit; diff --git a/frontends/php/include/config.inc b/frontends/php/include/config.inc index 7fb38dad..6b984a8e 100644 --- a/frontends/php/include/config.inc +++ b/frontends/php/include/config.inc @@ -4,6 +4,24 @@ $USER_DETAILS =""; $ERROR_MSG =""; + function get_item_by_itemid($itemid) + { + global $ERROR_MSG; + +// $sql="select itemid,type,snmp_community,snmp_oid,hostid,description,key_,delay,history,lastdelete, nextcheck,lastvalue, lastclock, prevvalue, status, value_type from items where itemid=$itemid"; + $sql="select * from items where itemid=$itemid"; + $result=DBselect($sql); + if(DBnum_rows($result) == 1) + { + return DBfetch($result); + } + else + { + $ERROR_MSG="No item with itemid=[$itemid]"; + } + return $item; + } + function select_trigger_by_triggerid($triggerid) { global $ERROR_MSG; @@ -488,7 +506,7 @@ ?> </font> </td> -<? /*?> + <td colspan=1 bgcolor=FFFFFF align=center valign="top" width="15%"> <font face="Arial,Helvetica" size=2> <a href="srv_status.php"> @@ -504,7 +522,7 @@ ?> </font> </td> -<? */?> + </tr> <tr> <td colspan=2 bgcolor=FFFFFF align=center valign="top" width="15%"> @@ -537,7 +555,7 @@ ?> </font> </td> - <td colspan=2 bgcolor=FFFFFF align=center valign="top" width="15%"> + <td colspan=3 bgcolor=FFFFFF align=center valign="top" width="15%"> <font face="Arial,Helvetica" size=2> <a href="report2.php"> <? @@ -663,7 +681,7 @@ ?> </font> </td> -<? /*?> + <td colspan=1 bgcolor=FFFFFF align=center valign="top" width="15%"> <font face="Arial,Helvetica" size=2> <a href="services.php"> @@ -679,7 +697,7 @@ ?> </font> </td> -<?*/?> + </tr> </table> </td> @@ -908,9 +926,9 @@ # Update Item definition - function update_item($itemid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid) + function update_item($itemid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type) { - $sql="update items set description='$description',key_='$key',hostid=$hostid,delay=$delay,history=$history,lastdelete=0,nextcheck=0,status=$status,type=$type,snmp_community='$snmp_community',snmp_oid='$snmp_oid' where itemid=$itemid"; + $sql="update items set description='$description',key_='$key',hostid=$hostid,delay=$delay,history=$history,lastdelete=0,nextcheck=0,status=$status,type=$type,snmp_community='$snmp_community',snmp_oid='$snmp_oid',value_type=$value_type where itemid=$itemid"; return DBexecute($sql); } @@ -1160,9 +1178,9 @@ # Add Item definition - function add_item($description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid) + function add_item($description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type) { - $sql="insert into items (description,key_,hostid,delay,history,lastdelete,nextcheck,status,type,snmp_community,snmp_oid) values ('$description','$key',$hostid,$delay,$history,0,0,$status,$type,'$snmp_community','$snmp_oid')"; + $sql="insert into items (description,key_,hostid,delay,history,lastdelete,nextcheck,status,type,snmp_community,snmp_oid,value_type) values ('$description','$key',$hostid,$delay,$history,0,0,$status,$type,'$snmp_community','$snmp_oid',$value_type)"; $result=DBexecute($sql); return DBinsert_id($result,"items","itemid"); } @@ -1346,15 +1364,16 @@ function add_from_templates($hostid,$host) { - $result=DBselect("select itemtemplateid,description,key_,delay from items_template"); + $result=DBselect("select itemtemplateid,description,key_,delay,value_type from items_template"); for($i=0;$i<DBnum_rows($result);$i++) { $itemtemplateid=DBget_field($result,$i,0); $description=DBget_field($result,$i,1); $key=DBget_field($result,$i,2); $delay=DBget_field($result,$i,3); + $value_type=DBget_field($result,$i,4); - $itemid=add_item($description,$key,$hostid,$delay,30*24*3600,0,0,"",""); + $itemid=add_item($description,$key,$hostid,$delay,30*24*3600,0,0,"","",$value_type); $result2=DBselect("select triggertemplateid,description,expression from triggers_template where itemtemplateid=$itemtemplateid"); for($j=0;$j<DBnum_rows($result2);$j++) @@ -1932,7 +1951,7 @@ { if(isset($itemid)) { - $result=DBselect("select i.description, i.key_, h.host, h.port, i.delay, i.history, i.status, i.type, i.snmp_community,i.snmp_oid from items i,hosts h where i.itemid=$itemid and h.hostid=i.hostid"); + $result=DBselect("select i.description, i.key_, h.host, h.port, i.delay, i.history, i.status, i.type, i.snmp_community,i.snmp_oid,i.value_type from items i,hosts h where i.itemid=$itemid and h.hostid=i.hostid"); $description=DBget_field($result,0,0); $key=DBget_field($result,0,1); @@ -1944,6 +1963,7 @@ $type=DBget_field($result,0,7); $snmp_community=DBget_field($result,0,8); $snmp_oid=DBget_field($result,0,9); + $value_type=DBget_field($result,0,10); } else { @@ -1957,6 +1977,7 @@ $type=0; $snmp_community="public"; $snmp_oid="interfaces.ifTable.ifEntry.ifInOctets.1"; + $value_type=0; } echo "<br>"; @@ -2045,6 +2066,18 @@ if($status==3) echo "SELECTED"; echo ">Not supported"; echo "</SELECT>"; + + show_table2_v_delimiter(); + echo "Type of information"; + show_table2_h_delimiter(); + echo "<SELECT NAME=\"value_type\" value=\"$value_type\" size=\"1\">"; + echo "<OPTION VALUE=\"0\""; + if($value_type==0) echo "SELECTED"; + echo ">Numeric"; + echo "<OPTION VALUE=\"1\""; + if($value_type==1) echo "SELECTED"; + echo ">Character"; + echo "</SELECT>"; show_table2_v_delimiter2(); echo "<input type=\"submit\" name=\"register\" value=\"add\">"; @@ -2245,7 +2278,7 @@ if(isset($triggerid)) { show_table2_v_delimiter(); - echo "Dependencies"; + echo "The trigger depends on"; show_table2_h_delimiter(); $sql="select t.triggerid,t.description from triggers t,trigger_depends d where t.triggerid=d.triggerid_up and d.triggerid_down=$triggerid"; $result1=DBselect($sql); diff --git a/frontends/php/items.php b/frontends/php/items.php index 944064eb..07e5232f 100644 --- a/frontends/php/items.php +++ b/frontends/php/items.php @@ -11,7 +11,7 @@ { if($register=="update") { - $result=update_item($itemid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid); + $result=update_item($itemid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type); show_messages($result,"Item updated","Cannot update item"); unset($itemid); } @@ -23,7 +23,7 @@ } if($register=="add") { - $result=add_item($description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid); + $result=add_item($description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type); show_messages($result,"Item added","Cannot add item"); unset($itemid); } diff --git a/frontends/php/latest.php b/frontends/php/latest.php index 88991710..175959a1 100644 --- a/frontends/php/latest.php +++ b/frontends/php/latest.php @@ -4,6 +4,7 @@ $page["file"] = "latest.php"; show_header($page["title"],0,0); ?> + <? show_table_header_begin(); echo "LATEST DATA"; @@ -156,7 +157,14 @@ { echo "<td><center>-</center></td>"; } - echo "<td><center><a href=\"history.php?action=showhistory&itemid=".$row["itemid"]."\">Show</a></center></td>"; + if($row["value_type"]==0) + { + echo "<td><center><a href=\"history.php?action=showhistory&itemid=".$row["itemid"]."\">Show</a></center></td>"; + } + else + { + echo "<td><center><a href=\"history.php?action=showvalues&period=3600&itemid=".$row["itemid"]."\">Show</a></center></td>"; + } if($row["value_type"]==0) { echo "<td><center><a href=\"trends.php?itemid=".$row["itemid"]."\">Show</a></center></td>"; diff --git a/include/cfg.c b/include/cfg.c index 2a9ec77a..194185cf 100644 --- a/include/cfg.c +++ b/include/cfg.c @@ -1,7 +1,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <syslog.h> #include "common.h" #include "cfg.h" @@ -34,12 +33,14 @@ int parse_cfg_file(char *cfg_file,struct cfg_line *cfg) int i,var; int *pointer; char **c; + int (*func)(); + file=fopen(cfg_file,"r"); if(NULL == file) { - syslog( LOG_CRIT, "Cannot open config file [%s] [%m]",cfg_file); + fprintf(stderr, "Cannot open config file [%s] [%m]\n",cfg_file); return FAIL; } @@ -57,7 +58,7 @@ int parse_cfg_file(char *cfg_file,struct cfg_line *cfg) if(NULL == value) { - syslog( LOG_CRIT, "Error in line [%s] Line %d", line, lineno); + fprintf(stderr, "Error in line [%s] Line %d\n", line, lineno); return FAIL; } value++; @@ -65,13 +66,22 @@ int parse_cfg_file(char *cfg_file,struct cfg_line *cfg) parameter[value-line-1]=0; -/* syslog( LOG_WARNING, "Parameter [%s] Value [%s]", parameter, value);*/ - i=0; while(cfg[i].parameter != 0) { if(strcmp(cfg[i].parameter, parameter) == 0) { + if(cfg[i].function != 0) + { + func=cfg[i].function; + if(func(value)!=SUCCEED) + { + fprintf(stderr, "Wrong value of [%s] in line %d.\n", cfg[i].parameter, lineno); + return FAIL; + } + } + else + { if(cfg[i].type == TYPE_INT) { var=atoi(value); @@ -79,7 +89,7 @@ int parse_cfg_file(char *cfg_file,struct cfg_line *cfg) { if( (var<cfg[i].min) || (var>cfg[i].max) ) { - syslog( LOG_CRIT, "Wrong value of [%s] in line %d. Should be between %d and %d.", cfg[i].parameter, lineno, cfg[i].min, cfg[i].max); + fprintf(stderr, "Wrong value of [%s] in line %d. Should be between %d and %d.\n", cfg[i].parameter, lineno, cfg[i].min, cfg[i].max); return FAIL; } @@ -87,7 +97,6 @@ int parse_cfg_file(char *cfg_file,struct cfg_line *cfg) /* Can this be done without "pointer" ? */ pointer=(int *)cfg[i].variable; *pointer=var; - syslog( LOG_WARNING, "Parameter [%s] [%d]", parameter, *pointer); } else { @@ -95,9 +104,39 @@ int parse_cfg_file(char *cfg_file,struct cfg_line *cfg) c=(char *)cfg[i].variable; *c=(char *)strdup(value); } + } } i++; } } + +/* Check for mandatory parameters */ + i=0; + while(cfg[i].parameter != 0) + { + if(cfg[i].mandatory ==1) + { + if(cfg[i].type == TYPE_INT) + { + pointer=(int *)cfg[i].variable; + if(*pointer==0) + { + fprintf(stderr,"Missing mandatory parameter [%s]\n", cfg[i].parameter); + return FAIL; + } + } + if(cfg[i].type == TYPE_STRING) + { + c=(char *)cfg[i].variable; + if(*c==NULL) + { + fprintf(stderr, "Missing mandatory parameter [%s]\n", cfg[i].parameter); + return FAIL; + } + } + } + i++; + } + return SUCCEED; } diff --git a/include/functions.c b/include/functions.c index 298e742b..e48b2d05 100644 --- a/include/functions.c +++ b/include/functions.c @@ -41,7 +41,7 @@ int evaluate_MIN(float *min,int itemid,int parameter) result = DBselect(sql); if((result==NULL)||(DBnum_rows(result)==0)) { - zabbix_log(LOG_LEVEL_NOTICE, "Result for MIN is empty" ); + zabbix_log(LOG_LEVEL_DEBUG, "Result for MIN is empty" ); DBfree_result(result); return FAIL; } @@ -49,7 +49,7 @@ int evaluate_MIN(float *min,int itemid,int parameter) field = DBget_field(result,0,0); if( field == NULL ) { - zabbix_log( LOG_LEVEL_NOTICE, "Result for MIN is empty" ); + zabbix_log( LOG_LEVEL_DEBUG, "Result for MIN is empty" ); DBfree_result(result); return FAIL; } @@ -79,7 +79,7 @@ int evaluate_MAX(float *max,int itemid,int parameter) result = DBselect(sql); if((result==NULL)||(DBnum_rows(result)==0)) { - zabbix_log(LOG_LEVEL_NOTICE, "Result for MAX is empty" ); + zabbix_log(LOG_LEVEL_DEBUG, "Result for MAX is empty" ); DBfree_result(result); return FAIL; } @@ -87,7 +87,7 @@ int evaluate_MAX(float *max,int itemid,int parameter) field = DBget_field(result,0,0); if( field == NULL ) { - zabbix_log( LOG_LEVEL_NOTICE, "Result for MAX is empty" ); + zabbix_log( LOG_LEVEL_DEBUG, "Result for MAX is empty" ); DBfree_result(result); return FAIL; } @@ -182,7 +182,7 @@ void update_functions(DB_ITEM *item) if((result==NULL)||(rows==0)) { - zabbix_log( LOG_LEVEL_NOTICE, "No functions to update."); + zabbix_log( LOG_LEVEL_DEBUG, "No functions to update."); DBfree_result(result); return; } @@ -514,7 +514,7 @@ void apply_actions(int triggerid,int good) /* * Recursive function! */ -void update_services(int triggerid) +void update_services(int triggerid, int istrue) { char sql[MAX_STRING_LEN+1]; int i,rows; @@ -536,7 +536,7 @@ void update_services(int triggerid) for(i=0;i<rows;i++) { - update_services(atoi(DBget_field(result,i,0))); + update_services(atoi(DBget_field(result,i,0)), istrue); } DBfree_result(result); @@ -572,7 +572,7 @@ void update_triggers( int suckers, int flag, int sucker_num, int lastclock ) if(rows == 0) { - zabbix_log( LOG_LEVEL_NOTICE, "No triggers to update" ); + zabbix_log( LOG_LEVEL_DEBUG, "No triggers to update" ); DBfree_result(result); return; } @@ -604,7 +604,7 @@ void update_triggers( int suckers, int flag, int sucker_num, int lastclock ) sprintf(sql,"update actions set nextcheck=0 where triggerid=%d and good=0",trigger.triggerid); DBexecute(sql); -/* update_services(trigger.triggerid); */ + update_services(trigger.triggerid, 1); } if((b==0)&&(trigger.istrue!=0)) @@ -622,7 +622,7 @@ void update_triggers( int suckers, int flag, int sucker_num, int lastclock ) sprintf(sql,"update actions set nextcheck=0 where triggerid=%d and good=1",trigger.triggerid); DBexecute(sql); -/* update_services(trigger.triggerid);*/ + update_services(trigger.triggerid, 0); } } DBfree_result(result); diff --git a/src/zabbix_agent/sysinfo.c b/src/zabbix_agent/sysinfo.c index 9d1b622a..2f0687f1 100644 --- a/src/zabbix_agent/sysinfo.c +++ b/src/zabbix_agent/sysinfo.c @@ -85,71 +85,73 @@ #include "sysinfo.h" COMMAND commands[AGENT_MAX_USER_COMMANDS]= +/* KEY FUNCTION (if float) FUNCTION (if string) PARAM*/ { - {"kern[maxfiles]" ,KERNEL_MAXFILES, 0}, - {"kern[maxproc]" ,KERNEL_MAXPROC, 0}, + {"kern[maxfiles]" ,KERNEL_MAXFILES, 0, 0}, + {"kern[maxproc]" ,KERNEL_MAXPROC, 0, 0}, - {"proc_cnt[*]" ,PROCCNT, "inetd"}, + {"proc_cnt[*]" ,PROCCNT, 0, "inetd"}, - {"memory[total]" ,TOTALMEM, 0}, - {"memory[shared]" ,SHAREDMEM, 0}, - {"memory[buffers]" ,BUFFERSMEM, 0}, - {"memory[cached]" ,CACHEDMEM, 0}, - {"memory[free]" ,FREEMEM, 0}, + {"memory[total]" ,TOTALMEM, 0, 0}, + {"memory[shared]" ,SHAREDMEM, 0, 0}, + {"memory[buffers]" ,BUFFERSMEM, 0, 0}, + {"memory[cached]" ,CACHEDMEM, 0, 0}, + {"memory[free]" ,FREEMEM, 0, 0}, - {"diskfree[*]" ,DF, "/"}, + {"diskfree[*]" ,DF, 0, "/"}, - {"inodefree[*]" ,INODE, "/"}, + {"inodefree[*]" ,INODE, 0, "/"}, - {"cksum[*]" ,CKSUM, "/etc/services"}, + {"cksum[*]" ,CKSUM, 0, "/etc/services"}, - {"filesize[*]" ,FILESIZE, "/etc/passwd"}, + {"filesize[*]" ,FILESIZE, 0, "/etc/passwd"}, - {"swap[free]" ,SWAPFREE, 0}, - {"swap[total]" ,SWAPTOTAL, 0}, + {"swap[free]" ,SWAPFREE, 0, 0}, + {"swap[total]" ,SWAPTOTAL, 0, 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"}, + {"swap[in]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b37-40"}, + {"swap[out]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b41-44"}, - {"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[interrupts]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b57-61"}, + {"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"}, ***************************************/ - {"io[disk_io]" ,DISK_IO, 0}, - {"io[disk_rio]" ,DISK_RIO, 0}, - {"io[disk_wio]" ,DISK_WIO, 0}, - {"io[disk_rblk]" ,DISK_RBLK, 0}, - {"io[disk_wblk]" ,DISK_WBLK, 0}, + {"io[disk_io]" ,DISK_IO, 0, 0}, + {"io[disk_rio]" ,DISK_RIO, 0, 0}, + {"io[disk_wio]" ,DISK_WIO, 0, 0}, + {"io[disk_rblk]" ,DISK_RBLK, 0, 0}, + {"io[disk_wblk]" ,DISK_WBLK, 0, 0}, - {"system[procload]" ,PROCLOAD, 0}, - {"system[procload5]" ,PROCLOAD5, 0}, - {"system[procload15]" ,PROCLOAD15, 0}, - {"system[proccount]" ,PROCCOUNT, 0}, + {"system[procload]" ,PROCLOAD, 0, 0}, + {"system[procload5]" ,PROCLOAD5, 0, 0}, + {"system[procload15]" ,PROCLOAD15, 0, 0}, + {"system[proccount]" ,PROCCOUNT, 0, 0}, #ifdef HAVE_PROC_LOADAVG - {"system[procrunning]" ,EXECUTE, "cat /proc/loadavg|cut -f1 -d'/'|cut -f4 -d' '"}, + {"system[procrunning]" ,EXECUTE, 0, "cat /proc/loadavg|cut -f1 -d'/'|cut -f4 -d' '"}, #endif - {"system[uname]" ,EXECUTE, "uname -a"}, - {"system[uptime]" ,UPTIME, 0}, - {"system[users]" ,EXECUTE, "who|wc -l"}, - - {"ping" ,PING, 0}, -/* {"tcp_count" ,EXECUTE, "netstat -tn|grep EST|wc -l"}, */ - - {"net[listen_23]" ,TCP_LISTEN, "0017"}, - {"net[listen_80]" ,TCP_LISTEN, "0050"}, - - {"check_port[*]" ,CHECK_PORT, "80"}, - - {"check_service[ssh]" ,CHECK_SERVICE_SSH, 0}, - {"check_service[smtp]" ,CHECK_SERVICE_SMTP, 0}, - {"check_service[ftp]" ,CHECK_SERVICE_FTP, 0}, - {"check_service[pop]" ,CHECK_SERVICE_POP, 0}, - {"check_service[nntp]" ,CHECK_SERVICE_NNTP, 0}, - {"check_service[imap]" ,CHECK_SERVICE_IMAP, 0}, - {0 ,0} + {"system[hostname]" ,0, EXECUTE_STR, "hostname"}, + {"system[uname]" ,0, EXECUTE_STR, "uname -a"}, + {"system[uptime]" ,UPTIME, 0, 0}, + {"system[users]" ,EXECUTE, 0,"who|wc -l"}, + + {"ping" ,PING, 0, 0}, +/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */ + + {"net[listen_23]" ,TCP_LISTEN, 0, "0017"}, + {"net[listen_80]" ,TCP_LISTEN, 0, "0050"}, + + {"check_port[*]" ,CHECK_PORT, 0, "80"}, + + {"check_service[ssh]" ,CHECK_SERVICE_SSH, 0, 0}, + {"check_service[smtp]" ,CHECK_SERVICE_SMTP, 0, 0}, + {"check_service[ftp]" ,CHECK_SERVICE_FTP, 0, 0}, + {"check_service[pop]" ,CHECK_SERVICE_POP, 0, 0}, + {"check_service[nntp]" ,CHECK_SERVICE_NNTP, 0, 0}, + {"check_service[imap]" ,CHECK_SERVICE_IMAP, 0, 0}, + {0} }; void add_user_parameter(char *key,char *command) @@ -178,48 +180,42 @@ void add_user_parameter(char *key,char *command) void test_parameters(void) { int i; - float result; - float (*function)(); - char *parameter = NULL; - char *key = NULL; + + char *c; i=0; - while(0 != commands[i].function) + while(0 != commands[i].key) { - key=commands[i].key; - function=commands[i].function; - parameter=commands[i].parameter; - - result = function(parameter); - if( result == FAIL ) - { - printf("\tUNSUPPORTED Key: %s\n",key); - } - else - { - printf("SUPPORTED Key: %s [%f]\n",key,result); - } + c=process(commands[i].key); + printf("Key: [%s]\tResult: [%s]\n",commands[i].key,c); fflush(stdout); - + free(c); i++; } } -float process(char *command) +/* The messy function must be rewritten! */ +char *process(char *command) { char *p; - float result; + double result=0; int i; char *n,*l,*r; float (*function)(); + char *(*function_str)(); char *parameter = NULL; - char key[1024]; + char key[MAX_STRING_LEN+1]; char param[1024]; char cmd[1024]; + char *res,*res2; + int ret_str=0; for( p=command+strlen(command)-1; p>command && ( *p=='\r' || *p =='\n' || *p == ' ' ); --p ); - p[1]=0; - + if( (*p=='\r') || (*p=='\n') ||(*p==' ')) + { + p[1]=0; + } + for(i=0;;i++) { if( commands[i].key == 0) @@ -251,6 +247,11 @@ float process(char *command) if( strcmp(key, cmd) == 0) { function=commands[i].function; + if(function==0) + { + function_str=commands[i].function_str; + ret_str=1; + } parameter=param; break; } @@ -260,26 +261,65 @@ float process(char *command) if( strcmp(key,command) == 0) { function=commands[i].function; + if(function==0) + { + function_str=commands[i].function_str; + ret_str=1; + } parameter=commands[i].parameter; break; } } } - - if( function !=0 ) + + if(ret_str == 0) { - result = function(parameter); - if( result == FAIL ) + if(function != 0) + { + result = function(parameter); + if( result == FAIL ) + { + result = NOTSUPPORTED; + } + } + else { result = NOTSUPPORTED; } } else { + res2=function_str(parameter); + if(res2==NULL) + { + result = NOTSUPPORTED; + } + } + + res=(char *)malloc(MAX_STRING_LEN+1); + if(res == NULL) + { +/* Not exactly ... */ result=NOTSUPPORTED; } - return result; + if(ret_str==0) + { + sprintf(res,"%f",result); + } + else + { + if(result==NOTSUPPORTED) + { + sprintf(res,"%f",result); + } + else + { + sprintf(res,"%s",res2); + } + } + + return res; } /* Code for cksum is based on code from cksum.c */ @@ -348,7 +388,7 @@ static u_long crctab[] = { * on failure. Errno is set on failure. */ -float CKSUM(const char * filename) +float CKSUM(const char * filename) { register u_char *p; register int nr; @@ -388,6 +428,7 @@ float CKSUM(const char * filename) } cval = ~crc; + return (float)cval; } @@ -490,9 +531,10 @@ float PROCCNT(const char * procname) DIR *dir; struct dirent *entries; struct stat buf; - char filename[512]; - char line[512]; - char name1[256],name2[256]; + char filename[MAX_STRING_LEN+1]; + char line[MAX_STRING_LEN+1]; + char name1[MAX_STRING_LEN+1]; + char name2[MAX_STRING_LEN+1]; FILE *f; @@ -501,9 +543,9 @@ float PROCCNT(const char * procname) dir=opendir("/proc"); while((entries=readdir(dir))!=NULL) { - strcpy(filename,"/proc/"); - strcat(filename,entries->d_name); - strcat(filename,"/status"); + strncpy(filename,"/proc/",MAX_STRING_LEN); + strncat(filename,entries->d_name,MAX_STRING_LEN); + strncat(filename,"/status",MAX_STRING_LEN); if(stat(filename,&buf)==0) { @@ -513,7 +555,7 @@ float PROCCNT(const char * procname) { continue; } - fgets(line,512,f); + fgets(line,MAX_STRING_LEN,f); fclose(f); if(sscanf(line,"%s\t%s\n",name1,name2)==2) @@ -633,12 +675,12 @@ float TCP_LISTEN(const char *porthex) { #ifdef HAVE_PROC FILE *f; - char c[1024]; + char c[MAX_STRING_LEN+1]; - char pattern[1024]="0050 00000000:0000 0A"; + char pattern[MAX_STRING_LEN+1]="0050 00000000:0000 0A"; - strcpy(pattern,porthex); - strcat(pattern," 00000000:0000 0A"); + strncpy(pattern,porthex,MAX_STRING_LEN); + strncat(pattern," 00000000:0000 0A", MAX_STRING_LEN); f=fopen("/proc/net/tcp","r"); if(NULL == f) @@ -646,7 +688,7 @@ float TCP_LISTEN(const char *porthex) return FAIL; } - while (NULL!=fgets(c,1024,f)) + while (NULL!=fgets(c,MAX_STRING_LEN,f)) { if(NULL != strstr(c,pattern)) { @@ -667,7 +709,7 @@ float getPROC(char *file,int lineno,int fieldno) { FILE *f; char *t; - char c[1024]; + char c[MAX_STRING_LEN+1]; float result; int i; @@ -678,7 +720,7 @@ float getPROC(char *file,int lineno,int fieldno) } for(i=1;i<=lineno;i++) { - fgets(c,1024,f); + fgets(c,MAX_STRING_LEN,f); } t=(char *)strtok(c," "); for(i=2;i<=fieldno;i++) @@ -1179,11 +1221,63 @@ float DISK_WBLK(void) #endif } +char *EXECUTE_STR(char *command) +{ + FILE *f; + char *c; + + c=(char *)malloc(MAX_STRING_LEN+1); + if(c == NULL) + { + return NULL; + } + + f=popen( command,"r"); + if(f==0) + { + switch (errno) + { +// case EINTR: +// return TIMEOUT_ERROR; + default: + printf("E1\n"); + return NULL; + } + } + + if(NULL == fgets(c,MAX_STRING_LEN,f)) + { + pclose(f); + switch (errno) + { +// case EINTR: +// return TIMEOUT_ERROR; + default: + printf("E1\n"); + return NULL; + } + } + + if(pclose(f) != 0) + { + switch (errno) + { +// case EINTR: +// return TIMEOUT_ERROR; + default: + printf("E1\n"); + return NULL; + } + } + + return c; +} + float EXECUTE(char *command) { FILE *f; float result; - char c[1024]; + char c[MAX_STRING_LEN+1]; f=popen( command,"r"); if(f==0) @@ -1197,7 +1291,7 @@ float EXECUTE(char *command) } } - if(NULL == fgets(c,1024,f)) + if(NULL == fgets(c,MAX_STRING_LEN,f)) { pclose(f); switch (errno) diff --git a/src/zabbix_agent/sysinfo.h b/src/zabbix_agent/sysinfo.h index d7e37f3b..7764ba1a 100644 --- a/src/zabbix_agent/sysinfo.h +++ b/src/zabbix_agent/sysinfo.h @@ -1,7 +1,7 @@ #ifndef MON_SYSINFO_H #define MON_SYSINFO_H -float process(char *command); +char *process(char *command); void add_user_parameter(char *key,char *command); void test_parameters(void); @@ -9,7 +9,7 @@ float getPROC(char *file,int lineno,int fieldno); float BUFFERSMEM(void); float CACHEDMEM(void); -float CKSUM(const char * filename); +float CKSUM(const char * filename); float FILESIZE(const char * filename); float DF(const char * mountPoint); float DISK_IO(void); @@ -35,6 +35,7 @@ float TCP_LISTEN(const char *porthex); float UPTIME(void); float EXECUTE(char *command); +char *EXECUTE_STR(char *command); float CHECK_SERVICE_SSH(void); float CHECK_SERVICE_SMTP(void); @@ -50,6 +51,7 @@ COMMAND { char *key; void *function; + void *function_str; char *parameter; }; diff --git a/src/zabbix_agent/zabbix_agent.c b/src/zabbix_agent/zabbix_agent.c index 51586cbf..66a16246 100644 --- a/src/zabbix_agent/zabbix_agent.c +++ b/src/zabbix_agent/zabbix_agent.c @@ -1,4 +1,4 @@ -/* #define TEST_PARAMETERS */ +/*#define TEST_PARAMETERS*/ #include "config.h" @@ -42,15 +42,30 @@ void signal_handler( int sig ) exit( FAIL ); } +int add_parameter(char *value) +{ + char *value2; + + value2=strstr(value,","); + if(NULL == value2) + { + return FAIL; + } + value2[0]=0; + value2++; + add_user_parameter(value, value2); + return SUCCEED; +} + void init_config(void) { struct cfg_line cfg[]= { /* PARAMETER ,VAR ,FUNC, TYPE(0i,1s),MANDATORY,MIN,MAX */ - {"Server",&CONFIG_HOSTS_ALLOWED,0,TYPE_STRING,PARM_OPT,0,0}, + {"Server",&CONFIG_HOSTS_ALLOWED,0,TYPE_STRING,PARM_MAND,0,0}, {"Timeout",&CONFIG_TIMEOUT,0,TYPE_INT,PARM_OPT,1,30}, - + {"UserParameter",0,&add_parameter,0,0,0,0}, {0} }; @@ -175,7 +190,7 @@ int check_security(void) return FAIL; } -float process_input() +char *process_input() { char s[1024]; @@ -186,6 +201,8 @@ float process_input() int main() { + char *res; + #ifdef TEST_PARAMETERS process_config_file(); test_parameters(); @@ -197,7 +214,7 @@ int main() signal( SIGTERM, signal_handler ); signal( SIGALRM, signal_handler ); - process_config_file(); + init_config(); alarm(CONFIG_TIMEOUT); @@ -206,7 +223,9 @@ int main() exit(FAIL); } - printf("%f\n",process_input()); + res=process_input(); + + printf("%s\n",res); fflush(stdout); diff --git a/src/zabbix_agent/zabbix_agentd.c b/src/zabbix_agent/zabbix_agentd.c index 10db5997..b6fd8403 100644 --- a/src/zabbix_agent/zabbix_agentd.c +++ b/src/zabbix_agent/zabbix_agentd.c @@ -87,7 +87,7 @@ void signal_handler( int sig ) uninit(); exit( FAIL ); } -/* parent==1 is mandatory ! EXECUTE sends SIGCHLD as well ... */ +/* parent==1 is mandatory ! EXECUTE sends SIGCHLD as well (?) ... */ else if( (SIGCHLD == sig) && (parent == 1) ) { zabbix_log( LOG_LEVEL_WARNING, "One child process died. Exiting ..."); @@ -406,7 +406,7 @@ void process_child(int sockfd) ssize_t nread; char line[1024]; char result[1024]; - double res; + char *res; static struct sigaction phan; @@ -440,7 +440,11 @@ void process_child(int sockfd) res=process(line); - sprintf(result,"%f",res); + sprintf(result,"%s",res); + if(res!=NULL) + { + free(res); + } zabbix_log( LOG_LEVEL_DEBUG, "Sending back:%s", result); write(sockfd,result,strlen(result)); @@ -547,6 +551,7 @@ int main() static struct sigaction phan; + process_config_file(); daemon_init(); phan.sa_handler = &signal_handler; @@ -557,7 +562,6 @@ int main() sigaction(SIGTERM, &phan, NULL); sigaction(SIGPIPE, &phan, NULL); - process_config_file(); if(CONFIG_LOG_FILE == NULL) { diff --git a/src/zabbix_sucker/zabbix_sucker.c b/src/zabbix_sucker/zabbix_sucker.c index 6edfcc67..eabb52bd 100644 --- a/src/zabbix_sucker/zabbix_sucker.c +++ b/src/zabbix_sucker/zabbix_sucker.c @@ -471,7 +471,7 @@ int get_value_zabbix(double *result,char **result_str,DB_ITEM *item) zabbix_log(LOG_LEVEL_DEBUG, "Got string:%10s", c ); *result=strtod(c,&e); - if( (*result==0) && (c==e) ) + if( (*result==0) && (c==e) && (item->value_type==0) ) { zabbix_log( LOG_LEVEL_WARNING, "Got empty string from [%s]. Parameter [%s]",item->host, item->key); zabbix_log( LOG_LEVEL_WARNING, "Assuming that agent dropped connection because of access permissions"); @@ -863,6 +863,8 @@ int main(int argc, char **argv) struct sigaction phan; + init_config(); + daemon_init(); phan.sa_handler = &signal_handler; /* set up sig handler using sigaction() */ @@ -873,10 +875,6 @@ int main(int argc, char **argv) sigaction(SIGTERM, &phan, NULL); sigaction(SIGCHLD, &phan, NULL); -/* process_config_file();*/ -/* process_config_file to be removed */ - init_config(); - if(CONFIG_LOG_FILE == NULL) { zabbix_open_log(LOG_TYPE_SYSLOG,CONFIG_LOG_LEVEL,NULL); @@ -913,6 +911,7 @@ int main(int argc, char **argv) if(sucker_num == 0) { +/* First instance of zabbix_suckerd does housekeeping procedures */ main_housekeeping_loop(); } else diff --git a/src/zabbix_trapper/zabbix_trapperd.c b/src/zabbix_trapper/zabbix_trapperd.c index dd2bbd31..f7169fe0 100644 --- a/src/zabbix_trapper/zabbix_trapperd.c +++ b/src/zabbix_trapper/zabbix_trapperd.c @@ -541,10 +541,10 @@ int main() static struct sigaction phan; + init_config(); daemon_init(); /* process_config_file(); */ - init_config(); if(CONFIG_LOG_FILE == NULL) { diff --git a/upgrades/dbpatches/1.0beta2_to_1.0beta3/mysql/patch.sql b/upgrades/dbpatches/1.0beta2_to_1.0beta3/mysql/patch.sql index 75f60653..4e2437be 100644 --- a/upgrades/dbpatches/1.0beta2_to_1.0beta3/mysql/patch.sql +++ b/upgrades/dbpatches/1.0beta2_to_1.0beta3/mysql/patch.sql @@ -1,4 +1,5 @@ alter table items add value_type int(4) DEFAULT '0' NOT NULL; +alter table items_template add value_type int(4) DEFAULT '0' NOT NULL; CREATE TABLE history_str ( itemid int(4) DEFAULT '0' NOT NULL, @@ -6,3 +7,8 @@ CREATE TABLE history_str ( value varchar(255) DEFAULT '' NOT NULL, PRIMARY KEY (itemid,clock) ); + +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (65,'Host name','system[hostname]', 1800, 1); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (66,'Host information','system[uname]', 1800, 1); diff --git a/upgrades/dbpatches/1.0beta2_to_1.0beta3/postgresql/patch.sql b/upgrades/dbpatches/1.0beta2_to_1.0beta3/postgresql/patch.sql index b77de8d8..9aff2bf8 100644 --- a/upgrades/dbpatches/1.0beta2_to_1.0beta3/postgresql/patch.sql +++ b/upgrades/dbpatches/1.0beta2_to_1.0beta3/postgresql/patch.sql @@ -1,4 +1,5 @@ alter table items add value_type int4 DEFAULT '0' NOT NULL; +alter table items_template add value_type int4 DEFAULT '0' NOT NULL; CREATE TABLE history_str ( itemid int4 DEFAULT '0' NOT NULL, @@ -8,3 +9,7 @@ CREATE TABLE history_str ( FOREIGN KEY (itemid) REFERENCES items ); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (65,'Host name','system[hostname]', 1800, 1); +insert into items_template (itemtemplateid,description,key_,delay,value_type) + values (66,'Host information','system[uname]', 1800, 1); |
