diff options
56 files changed, 6693 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 00000000..c5c7d91b --- /dev/null +++ b/AUTHORS @@ -0,0 +1,5 @@ +Core developers +=============== + + * Alexei Vladishev <alex@gobbo.caves.lv> + Initial idea. diff --git a/COPYING b/COPYING new file mode 100644 index 00000000..02be4c60 --- /dev/null +++ b/COPYING @@ -0,0 +1,344 @@ + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) 19yy <name of author> + + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. + + + @@ -0,0 +1,10 @@ + 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. + + --alex@gobbo.caves.lv diff --git a/INSTALL b/INSTALL new file mode 100644 index 00000000..d5cef9e7 --- /dev/null +++ b/INSTALL @@ -0,0 +1,4 @@ +Zabbix Installation notes +============================ + +Please, see doc/manual.txt for installation instructions @@ -0,0 +1 @@ +Check http://sourceforge.net/news/?group_id=23494 diff --git a/create/mysql/schema.sql b/create/mysql/schema.sql new file mode 100644 index 00000000..63b1cf2f --- /dev/null +++ b/create/mysql/schema.sql @@ -0,0 +1,293 @@ +# +# Table structure for table 'config' +# + +CREATE TABLE config ( + smtp_server varchar(255) DEFAULT '' NOT NULL, + smtp_helo varchar(255) DEFAULT '' NOT NULL, + smtp_email varchar(255) DEFAULT '' NOT NULL +); + +insert into config (smtp_server,smtp_helo,smtp_email) values ("localhost","localhost","zabbix@localhost"); + +# +# Table structure for table 'alerts' +# + +CREATE TABLE alerts ( + alertid int(4) NOT NULL auto_increment, + clock int(4) DEFAULT '0' NOT NULL, + type varchar(10) DEFAULT '' NOT NULL, + sendto varchar(100) DEFAULT '' NOT NULL, + subject varchar(255) DEFAULT '' NOT NULL, + message varchar(255) DEFAULT '' NOT NULL, + PRIMARY KEY (alertid), + KEY clock (clock) +); + +# +# Table structure for table 'actions' +# + +CREATE TABLE actions ( + actionid int(4) NOT NULL auto_increment, + triggerid int(4) DEFAULT '0' NOT NULL, + userid int(4) DEFAULT '0' NOT NULL, + good int(4) DEFAULT '0' NOT NULL, + delay int(4) DEFAULT '0' NOT NULL, + subject varchar(255) DEFAULT '' NOT NULL, + message varchar(255) DEFAULT '' NOT NULL, + nextcheck int(4) DEFAULT '0' NOT NULL, + PRIMARY KEY (actionid) +); + +# +# Table structure for table 'alarms' +# + +CREATE TABLE alarms ( + alarmid int(4) NOT NULL auto_increment, + triggerid int(4) DEFAULT '0' NOT NULL, + clock int(4) DEFAULT '0' NOT NULL, + istrue int(4) DEFAULT '0' NOT NULL, + PRIMARY KEY (alarmid) +); + +# +# Table structure for table 'functions' +# + +CREATE TABLE functions ( + functionid int(4) NOT NULL auto_increment, + itemid int(4) DEFAULT '0' NOT NULL, + triggerid int(4) DEFAULT '0' NOT NULL, + lastvalue double(16,4) DEFAULT '0.0000' NOT NULL, + function varchar(10) DEFAULT '' NOT NULL, + parameter int(4) DEFAULT '0' NOT NULL, + PRIMARY KEY (functionid), + KEY itemid (itemid), + KEY triggerid (itemid), + KEY itemidfunctionparameter (itemid,function,parameter) +); + +# +# Table structure for table 'history' +# + +CREATE TABLE history ( + itemid int(4) DEFAULT '0' NOT NULL, + clock int(4) DEFAULT '0' NOT NULL, + value double(16,4) DEFAULT '0.0000' NOT NULL, + PRIMARY KEY (itemid,clock) +); + +# +# Table structure for table 'hosts' +# + +CREATE TABLE hosts ( + hostid int(4) NOT NULL auto_increment, + platformid int(4) NOT NULL, + host varchar(64) DEFAULT '' NOT NULL, + port int(4) DEFAULT '0' NOT NULL, + status int(4) DEFAULT '0' NOT NULL, + PRIMARY KEY (hostid), + KEY (platformid), + KEY (status) +); + +# +# Table structure for table 'platforms' +# + +CREATE TABLE platforms ( + platformid int(4) NOT NULL, + platform varchar(32) DEFAULT '' NOT NULL, + PRIMARY KEY (platformid) +); + +insert into platforms (platformid,platform) values (1,"Linux (Intel) v2.2"); +insert into platforms (platformid,platform) values (2,"HP-UX 10.20"); +insert into platforms (platformid,platform) values (3,"HP-UX 11.00"); +insert into platforms (platformid,platform) values (4,"AIX 4.3"); + +# +# Table structure for table 'items_template' +# + +CREATE TABLE items_template ( + itemtemplateid int(4) NOT NULL, + platformid int(4) NOT NULL, + description varchar(255) DEFAULT '' NOT NULL, + key_ varchar(64) DEFAULT '' NOT NULL, + delay int(4) DEFAULT '0' NOT NULL, + PRIMARY KEY (itemtemplateid), + UNIQUE (platformid, key_), + KEY (platformid) +); + +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (1,1,"Free memory","freemem", 30); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (2,1,"Free disk space on /","root_free", 30); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (3,1,"Free disk space on /tmp","tmp_free", 30); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (4,1,"Free disk space on /usr","usr_free", 30); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (5,1,"Free number of inodes on /","root_inode", 30); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (6,1,"Free number of inodes on /opt","opt_inode", 30); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (7,1,"Free number of inodes on /tmp","tmp_inode", 30); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (8,1,"Free number of inodes on /usr","usr_inode", 30); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (9,1,"Number of processes","proccount", 30); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (10,1,"Processor load","procload", 10); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (11,1,"Processor load5","procload5", 30); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (12,1,"Processor load15","procload15", 60); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (13,1,"Number of running processes","procrunning", 30); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (14,1,"Free swap space","swapfree", 30); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (16,1,"Size of /var/log/syslog","syslog_size", 30); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (17,1,"Number of users connected","users", 30); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (18,1,"Number of established TCP connections","tcp_count", 30); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (19,1,"Md5sum of /etc/inetd.conf","md5sum_inetd", 600); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (20,1,"Md5sum of /vmlinuz","md5sum_kernel", 600); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (21,1,"Md5sum of /etc/passwd","md5sum_passwd", 600); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (22,1,"Ping of server","ping", 30); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (23,1,"Free disk space on /home","home_free", 30); +insert into items_template (itemtemplateid,platformid,description,key_,delay) + values (24,1,"Free number of inodes on /home","home_inode", 30); + +# +# Table structure for table 'triggers_template' +# + +CREATE TABLE triggers_template ( + triggertemplateid int(4) NOT NULL, + itemtemplateid int(4) NOT NULL, + description varchar(255) DEFAULT '' NOT NULL, + expression varchar(255) DEFAULT '' NOT NULL, + PRIMARY KEY (triggertemplateid), + KEY (itemtemplateid) +); + +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (1,1,"Lack of free memory","{:.last(0)}<1000000"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (2,2,"Low free disk space on /","{:.last(0)}<1000000000"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (3,3,"Low free disk space on /tmp","{:.last(0)}<1000000000"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (4,4,"Low free disk space on /usr","{:.last(0)}<1000000000"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (5,5,"Low number of free inodes on /","{:.last(0)}<1000000000"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (6,6,"Low number of free inodes on /opt","{:.last(0)}<1000000000"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (7,7,"Low number of free inodes on /tmp","{:.last(0)}<1000000000"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (8,8,"Low number of free inodes on /usr","{:.last(0)}<1000000000"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (9,9,"Too many processes running","{:.last(0)}>500"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (10,10,"Processor load is too high","{:.last(0)}>5"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (13,13,"Too many processes running","{:.last(0)}>10"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (14,14,"Lack of free swap space","{:.last(0)}<100000000"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (17,17,"Too may users connected","{:.last(0)}>50"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (18,18,"Too may established TCP connections","{:.last(0)}>500"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (19,19,"/etc/inetd.conf has been changed","{:.diff(0)}>0"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (20,20,"/vmlinuz has been changed","{:.diff(0)}>0"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (21,21,"/passwd has been changed","{:.diff(0)}>0"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (22,22,"No ping from server","{:.nodata(60)}>0"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (23,23,"Low free disk space on /home","{:.last(0)}<1000000000"); +insert into triggers_template (triggertemplateid,itemtemplateid,description,expression) + values (24,24,"Low number of free inodes on /home","{:.last(0)}<1000000000"); + +# +# Table structure for table 'items' +# + +CREATE TABLE items ( + itemid int(4) NOT NULL auto_increment, + hostid int(4) NOT NULL, + description varchar(255) DEFAULT '' NOT NULL, + key_ varchar(64) DEFAULT '' NOT NULL, + delay int(4) DEFAULT '0' NOT NULL, + history int(4) DEFAULT '0' NOT NULL, + lastdelete int(4) DEFAULT '0' NOT NULL, + nextcheck int(4) DEFAULT '0' NOT NULL, + lastvalue double(16,4) DEFAULT NULL, + lastclock int(4) DEFAULT NULL, + prevvalue double(16,4) DEFAULT NULL, + status int(4) DEFAULT '0' NOT NULL, + PRIMARY KEY (itemid), + UNIQUE shortname (hostid,key_), + KEY (hostid) +); + +# +# Table structure for table 'media' +# + +CREATE TABLE media ( + mediaid int(4) NOT NULL auto_increment, + userid int(4) DEFAULT '0' NOT NULL, + type varchar(10) DEFAULT '' NOT NULL, + sendto varchar(100) DEFAULT '' NOT NULL, + active int(4) DEFAULT '0' NOT NULL, + PRIMARY KEY (mediaid) +); + +# +# Table structure for table 'triggers' +# + +CREATE TABLE triggers ( + triggerid int(4) NOT NULL auto_increment, + expression varchar(255) DEFAULT '' NOT NULL, + description varchar(255) DEFAULT '' NOT NULL, + istrue int(4) DEFAULT '0' NOT NULL, + lastcheck int(4) DEFAULT '0' NOT NULL, + priority int(2) DEFAULT '0' NOT NULL, + lastchange int(4) DEFAULT '0' NOT NULL, + comments blob, + PRIMARY KEY (triggerid) +); + +# +# Table structure for table 'users' +# + +CREATE TABLE users ( + userid int(4) NOT NULL auto_increment, + alias varchar(100) DEFAULT '' NOT NULL, + name varchar(100) DEFAULT '' NOT NULL, + surname varchar(100) DEFAULT '' NOT NULL, + PRIMARY KEY (userid), + UNIQUE (alias) +); + diff --git a/doc/dbstructure b/doc/dbstructure new file mode 100644 index 00000000..54263901 --- /dev/null +++ b/doc/dbstructure @@ -0,0 +1,185 @@ +Description of database structure +================================= + +The table contains list of actions to be applied if trigger +change its state. + +Table ACTIONS +============= + +actionid int ; Unique action ID +triggerid int ; Trigger ID +userid int ; User ID +good int ; +delay int ; How ofter sent the message (in sec) +subject varchar ; Subject of the message +message varchar ; The message itself +nextcheck int ; Time when we should send message next time + +Table ALARMS +============ + +This table contains history of changes of trigger states. +When a trigger changes its state, new record is added to the table. + +STRUCTURE +--------- + + triggerid int ; unique ID + clock int ; Timestamp when trigger changed its status + istrue int ; if '1' the trigger became true, '0' otherwise + + +Table FUNCTIONS +=============== + +The table contains list of simple functions used in trigger expressions. + +STRUCTURE +--------- + +functionid int ; Unique function ID +itemid int ; Item ID +triggerid int ; Trigger ID +lastvalue double ; Last values +function varchar ; Function name: LAST, MIN, MAX, PREV, NODATA +parameter int ; Parameter to function. Ignored if function does not need any parameter + +Table HISTORY +============= + +This table contains history of values of items. + +STRUCTURE +--------- + + itemid int ; Item ID + clock int ; Timestamp + value double ; Value of the item at specific time + + + +Table ITEMS +=========== + +This table contains list of monitored items. + +STRUCTURE +--------- + + itemid int ; Unique item ID + hostid id ; Host ID + description varchar ; Description of the item + key_ varchar ; Key to be sent to host + delay int ; How often we retrieve this item (in sec) + history int ; Store only "history" seconds in history table + lastdelete int ; Time of last deletion from "history" table + nextcheck int ; Time when next value should be retrieved from host + lastvalue double ; Last value retrieved from host + lastclock int ; Time when last value was retrieved + prevvalue double ; Previous last value + status int ; Status of item. 0 - active, 1 - disabled, 2 - traper, + ; 3 - not supported by agent + + +Table MEDIA +=========== + +This table contains list of available medias for given user. + +STRUCTURE +--------- + + mediaid int ; Unique media ID + userid int ; User ID + type varchar ; Type of media: EMAIL, EITEMS, EMEDIA + sendto varchar ; Address to send email + active int ; Status of media. 0 - active, 1 - disbaled + + +Table TRIGGERS +============== + +The table contains list of triggers. + +STRUCTURE +--------- + + triggerid int ; Unique trigger ID + expression varchar ; Expression for trigger + description varchar ; Description of trigger + istrue int ; 1 if expression is false, 0 otherwise + lastcheck int ; Time when trigger expression was recalculated + priority int ; + lastchange int ; Time when istrue was changed + comments blob ; Comments + + +Table USERS +=========== + +The table contains list of Zabbix's users. + +STRUCTURE +--------- + + userid int ; Unique user ID + name varchar ; Name of user + surname varchar ; Surname + alias varchar ; User's alias + passwd varchar ; User's password + + +Table HOSTS +=========== + +The table contains list of monitored Hosts + +STRUCTURE +--------- + + hostid int ; Unique host ID + platformid int ; Platform ID + host varchar ; Host name of IP address + status int ; Host status. 0 - monitored, 1 - not monitored + + +Table PLATFORMS +=============== + +The table contains list of platforms + +STRUCTURE +--------- + + platformid int ; Unique platform ID + platform varchar ; Name of platform + + +Table ITEMS_TEMPLATE +==================== + +The table contains list of supported items for each platform + +STRUCTURE +--------- + + itemtemplateid int ; Unique ID of item template + platformid int ; Platform ID + description varchar ; Item description + key_ int ; Key to sent to host + delay int ; How often we sent the key (in sec) + + +Table TRIGGERS_TEMPLATE +==================== + +The table contains sample list of triggers for each template item + +STRUCTURE +--------- + + triggertemplateid int ; Unique ID of trigger template + itemtemplateid int ; ID of item template the trigger belongs to + description varchar ; Trigger description + expression varchar ; Expression for trigger diff --git a/doc/manual.txt b/doc/manual.txt new file mode 100644 index 00000000..3e4179b8 --- /dev/null +++ b/doc/manual.txt @@ -0,0 +1,286 @@ +1. Chapter 1 (Introduction) + +1.1 About the manual +1.2 What is Zabbix ? +1.3 What front end are available for Zabbix ? +1.4 What databases can be used with Zabbix ? +1.5 What does Zabbix offer ? +1.6 What does Zabbix consist of ? + +2. Chapter 2 (Installation) + +2.1 What platforms are supported by Zabbix ? +2.2 Before you start +2.3 Installation procedure + +3. Chapter 3 (Adminitration) +3.1 Zabbix configuration +3.2 Expressions for triggers + +- Chapter 1 (Introduction) + +1.1 About the manual + +This manual 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. + +1.2 What is Zabbix ? + +Zabbix was created by Alexei Vladishev. It is software for monitoring +of network and servers. It has flexible notification mechanism. All +monitored parameters (such as process load, free disk space, etc) +can be viewed in either graphical or text way. + +1.3 What frontends are available for Zabbix ? + +Currently, Zabbix has PHP-based WEB interface. + +1.4 What databases can be used with Zabbix ? + +MySQL is the only database supported by Zabbix. Support for other +databases (PostgreSQL,Oracle, etc) is coming soon. + +1.5 What does Zabbix offer ? + +The following are amongst the features that Zabbix offer: + + - Zabbix agent for Linux + - Zabbix's server side for Linux + - WEB-based interface + - E-mail notification in case of predefined events + - Support for both polling and traping mechanism + +1.6 What does Zabbix consist of ? + +Zabbix consists of seven main components: + +- database + +Zabbix uses database to store everything from configuration parameters +to values received from agents. + +- end user interface + +- "zabbix_sucker" + +The process periodically connects to agents to get updated information +on monitored parameters. + +- "zabbix_agent" + +The process lives on monitored server. zabbix_sucker connects to the zabbix_agent +to get latest values of monitored parameters. + +- "zabbix_alarmer" + +The process is used to calculate expressions used for triggers and send +alarms to users. + +- "zabbix_sender" + +The process is used to send values to Zabbix. + +- "zabbix_traper" + +The process receives values sent by zabbix_sender. + +2. Chapter 2 (Installation) + +2.1 What platforms are supported by Zabbix ? + +Zabbix server side supports the following platforms: + + - Linux 2.xx + +Agents are available for the following platforms: + + - Linux 2.xx + +2.2 Before you start + +Building Zabbix requires GNU make. It will not work with other make programs. + +Zabbix requires both physical (suprise!) and disk memory. 64 Mb of physical +memory and 50 Mb of free disk memory is good start point. +However, amount of required memory strongly depends on configuration +parameters. If you're planning to keep long history of monitored parameters, +you should think of even a couple of gigabytes to store the history in +the database. + +2.3 Installation procedure + + - Create the Zabbix superuser account. + +This is the user the server will run on. For production use you should create +a separate, unprivileged account ("zabbix" is commonly used). + +Running Zabbix as "root","bin", or any other account with special rights is a +security risk. Do not do it ! + + - Create the Zabbix database. + +For MySQL: + +mysql -u<username> -p<password> +> create database zabbix; +>quit; + +cd create/mysql +cat schema.sql |mysql zabbix -u<username> -p<password> + + - Configure include/db.h + +#define DB_NAME "" +#define DB_USER "" +#define DB_PASSWD "" + +Change these values. + + - Configure the source code for you system. + +cd src/zabbix_sucker +./configure +make + +cd src/zabbix_alarmer +./configure +make + +cd src/zabbix_agent +./configure +make + +cd src/zabbix_traper +./configure +make + +cd src/zabbix_sender +./configure +make + + - Copy binaries to /opt/zabbix/bin or any other directory. + + - Configure /etc/services + +Add the following lines to /etc/services: + +zabbix_agent 10000/tcp +zabbix_trap 10001/tcp + + - Configure /etc/inetd.conf + +Add the following lines 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_traper + + - Restart inetd + +killall -HUP inetd + + - Configure WEB interface + +As zabbix: + +mkdir /home/zabbix/html +cp frontends/php/* /home/zabbix/html/ + +Change these values in config.inc: + + $DB_SERVER =""; + $DB_DATABASE ="zabbix"; + $DB_USER =""; + $DB_PWD ="" + +3.1 Zabbix configuration + + - Use WEB browser to configure Zabbix (http://localhost/~zabbix) + - Click on "CONFIG" + +Set up SMTP parameters. + + - Click on "USERS" + +Add yourself to list of users. + + - Set up available Medias for the user (Click on "Media") + + - Add host for monitoring + +Be sure that you've installed agent on the host. Otherwise, set status +to "Not monitored". + + - Configure ITEMS + + - Configure TRIGGERS + +Defined actions for triggers you are interested in. + +- Create /etc/zabbix/zabbix_agent.conf + +Put IP address of Zabbix server here. + + - Run zabbix_sucker and zabbix_alarmer + +/opt/zabbix/bin/zabbix_alarmer +/opt/zabbix/bin/zabbix_sucker + +3.2 Expressions for triggers + +The following operators supported for triggers: + +> - more than +< - less than +| - logical OR +& - logical AND + +The following functions supported: + +last - last value, parameter is ignored +min - MIN value for period of time, parameter - time in sec +max - MAX value for period of time, parameter - time in sec +diff - 1 - if last and previous values are different, 0 - otherwise +prev - previous value, parameter is ignored +nodata - 1, if no values were received for "parameter" seconds + +Simplest useful expression might look as: + +{<server>:<key>.<function>(<parameter>)}<operator><const> + +Example 1: + +{sourceforge.net:procload.last(0)}>5 + +It means: + +sourceforge.net - server name +procload - key name + +sourceforge.net:procload gives short name of monitored parameter. + +last - function name + +Basically the expression means, processor load of sourceforge.net is more than +5. The trigger becomes true, when processor load exceeds 5. + +Example 2: + +More complex example: + +({sourceforge.net:procload.last(0)>5}) | ({sourceforge.net:procload.min(600)}>2) + +The expression becomes true when either current processor load is more +than 5 or it was more than 2 during last 10 minutes. + +Example 3: + +Use of diff function. + +({sourceforge.net:passwd_md5sum.diff(0)})>0 + +The expression becomes true when previous value of MD5 sum of /etc/passwd +differs from last one. + +Similiar expressions could be useful to monitor changes in important files, such as +/etc/passwd, /etc/inetd.conf, /kernel, etc. diff --git a/frontends/php/actions.html b/frontends/php/actions.html new file mode 100644 index 00000000..155f8bc7 --- /dev/null +++ b/frontends/php/actions.html @@ -0,0 +1,171 @@ +<? + include "config.inc"; + $title = "Actions"; + show_header($title,0); +?> + +<? + if($register=="add") + { + add_action( $triggerid, $userid, $good, $delay, $subject, $message ); + } + if($register=="update") + { + update_action( $actionid, $userid, $good, $delay, $subject, $message ); + } + if($register=="delete") + { + delete_action($actionid); + } +?> + +<? + if(!isset($description)) + { + $sql="select description, expression from triggers where triggerid=$triggerid"; + $result=mysql_query($sql,$mysql); + $row=mysql_fetch_row($result); + $description=$row[0]; + $expression=$row[1]; + } + +?> + +<? + $expression=explode_exp($expression,1); + show_table_header("$description<BR>$expression"); +?> + +<hr> + +<? + $sql="select a.actionid,a.triggerid,u.alias,a.good,a.delay,a.subject,a.message from actions a,users u where a.userid=u.userid and a.triggerid=$triggerid order by u.alias, a.good desc"; + $result=mysql_query($sql,$mysql); + + echo "<CENTER>"; + echo "<TABLE BORDER=0 WIDTH=100% BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; + echo "<TR>"; + echo "<TD><b>Send to</b></TD>"; + echo "<TD><b>When trigger</b></TD>"; + echo "<TD><b>Delay</b></TD>"; + echo "<TD><b>Subject</b></TD>"; + echo "<TD><b>Message</b></TD>"; + echo "<TD><b>Actions</b></TD>"; + echo "</TR>"; + while($row=mysql_fetch_row($result)) + { + $actid=$row[0]; + $good="OFF"; + if($row[3]) + { + $good="ON"; + } + $to=$row[2]; + $delay=$row[4]; + $subject=$row[5]; + $msg=$row[6]; + + if($actionid==$actid) + { + echo "<TR BGCOLOR=#FFDDDD>"; + $col=$col+1; + $sactid=$actid; + $sgood=$good; + $sto=$to; + $sdelay=$delay; + $ssubject=$subject; + $smsg=$msg; + } + else + { + if($col==1) + { + echo "<TR BGCOLOR=#EEEEEE>"; + $col=0; + } else + { + echo "<TR BGCOLOR=#DDDDDD>"; + $col=1; + } + } + + echo "<TD>$to</TD>"; + echo "<TD>$good</TD>"; + echo "<TD>$delay</TD>"; + echo "<TD>$subject</TD>"; + echo "<TD>$msg</TD>"; + echo "<TD>"; + echo " <A HREF=\"actions.html?register=edit&actionid=$actid&triggerid=$triggerid\">Edit</A>"; + echo ", <A HREF=\"actions.html?register=delete&actionid=$actid&triggerid=$triggerid\">Delete</A>"; + echo "</TD></TR>"; + } + echo "</TABLE>"; +?> +</font> +</tr> +</table></center> + +<? + echo "<br>"; + show_table2_header_begin(); + echo "New action"; + + show_table2_v_delimiter(); + echo "<form method=\"post\" action=\"actions.html\">"; + echo "<input name=\"triggerid\" type=\"hidden\" value=$triggerid>"; + echo "<input name=\"actionid\" type=\"hidden\" value=$sactid>"; + echo "Send to"; + show_table2_h_delimiter(); + echo "<SELECT NAME=\"userid\" SIZE=\"1\">"; + + $sql="select userid,alias from users order by alias"; + $result=mysql_query($sql,$mysql); + while($row=mysql_fetch_row($result)) + { + $id=$row[0]; + $name=$row[1]; + if($name==$sto) + { + echo "<option value=\"$id\" SELECTED>$name"; + } + else + { + echo "<option value=\"$id\">$name"; + } + } + echo "</select>"; + + show_table2_v_delimiter(); + echo "When trigger becomes"; + show_table2_h_delimiter(); + echo "<select name=\"good\" size=1>"; + echo "<OPTION VALUE=\"1\""; if($sgood=="ON") echo "SELECTED"; echo ">ON"; + echo "<OPTION VALUE=\"0\""; if($sgood=="OFF") echo "SELECTED"; echo ">OFF"; + echo "</SELECT>"; + + show_table2_v_delimiter(); + echo "Delay"; + show_table2_h_delimiter(); + echo "<input name=\"delay\" value=\"300\" size=5>"; + + show_table2_v_delimiter(); + echo "Subject"; + show_table2_h_delimiter(); + echo "<input name=\"subject\" size=50>"; + + show_table2_v_delimiter(); + echo "Message"; + show_table2_h_delimiter(); + echo "<input name=\"message\" size=50>"; + + show_table2_v_delimiter2(); + echo "<input type=\"submit\" name=\"register\" value=\"add\">"; + if(isset($actionid)) + { + echo "<input type=\"submit\" name=\"register\" value=\"update\">"; + } + + show_table2_header_end(); + + show_footer(); +?> diff --git a/frontends/php/alarms.html b/frontends/php/alarms.html new file mode 100644 index 00000000..5a9020ba --- /dev/null +++ b/frontends/php/alarms.html @@ -0,0 +1,170 @@ +<? + include "config.inc"; + $title = "Alarms"; + show_header($title,0); +?> + +<? + show_table_header_begin(); + echo "ALARMS"; + + show_table_v_delimiter(); + + if(!isset($triggerid)) + { + echo "<CENTER><B>No triggerID!!!!</B><BR>Please Contact Server Adminstrator</CENTER>"; + show_footer(); + exit; + } + else + { + if((!$Expression)||(!$Description)||(!$Priority)) + { + $result=mysql_query("select expression,description,priority from triggers where triggerid=$triggerid",$mysql); + $row=mysql_fetch_row($result); + + if(!isset($Expression)) $Expression=$row[0]; + if(!isset($Description)) $Description=$row[1]; + if(!isset($Priority)) $Priority=$row[2]; + } + } +?> + +<? + if($limit=="NO") + { + echo "[<A HREF=\"alarms.html?triggerid=$triggerid&limit=30\">"; + echo "Show only last 100</A>]"; + $limit=" "; + } + else + { + echo "[<A HREF=\"alarms.html?triggerid=$triggerid&limit=NO\">"; + echo "Show all</A>]"; + $limit=" limit 100"; + } + + show_table_header_end(); + echo "<br>"; +?> + + +<? + $Expression=explode_exp($Expression,1); + show_table_header("$Description<BR><font size=-1>$Expression</font>"); +?> + +<FONT COLOR="#000000"> +<? + $sql="select clock,istrue from alarms where triggerid=$triggerid order by clock desc $limit"; + $result=mysql_query($sql,$mysql); + + echo "<CENTER>"; + echo "<TABLE WIDTH=100% BORDER=0 BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; + echo "<TR>"; + echo "<TD><FONT SIZE=+1>Time</FONT></TD>"; + echo "<TD><FONT SIZE=+1>Status</FONT></TD>"; + echo "<TD><FONT SIZE=+1>Length</FONT></TD>"; + echo "<TD><FONT SIZE=+1>Sum</FONT></TD>"; + echo "<TD><FONT SIZE=+1>%</FONT></TD>"; + echo "</TR>"; + $truesum=0; + $falsesum=0; + $dissum=0; + $clock=mktime(); + while($row=mysql_fetch_row($result)) + { + $lclock=$clock; + $clock=$row[0]; + $leng=$lclock-$clock; + $status=$row[1]; + if($status==0) { echo "<TR BGCOLOR=#EEFFEE>"; } + elseif($status==2) { echo "<TR BGCOLOR=#DDDDDD>"; } + elseif($status==3) { echo "<TR BGCOLOR=#EEEEEE>"; } + else { echo "<TR BGCOLOR=#FFDDDD>"; } + + echo "<TD>",date("Y.M.d H:i:s",$clock),"</TD>"; + if($status==1) + { + $istrue="TRUE"; + $truesum=$truesum+$leng; + $sum=$truesum; + } + elseif($status==0) + { + $istrue="FALSE"; + $falsesum=$falsesum+$leng; + $sum=$falsesum; + } + elseif($status==2) + { + $istrue="DISABLED"; + $dissum=$dissum+$leng; + $sum=$dissum; + } + elseif($status==3) + { + $istrue="MODIFIED"; + $dissum=$dissum+$leng; + $sum=$dissum; + } + + $proc=(100*$sum)/($falsesum+$truesum+$dissum); + $proc=round($proc*100)/100; + $proc="$proc%"; + + echo "<TD><B>",$istrue,"</B></TD>"; + if($leng>60*60*24) + { + $leng= round(($leng/(60*60*24))*10)/10; + $leng="$leng days"; + } + elseif ($leng>60*60) + { + $leng= round(($leng/(60*60))*10)/10; + $leng="$leng hours"; + } + elseif ($leng>60) + { + $leng= round(($leng/(60))*10)/10; + $leng="$leng mins"; + } + else + { + $leng="$leng secs"; + } + + if($sum>60*60*24) + { + $sum= round(($sum/(60*60*24))*10)/10; + $sum="$sum days"; + } + elseif ($sum>60*60) + { + $sum= round(($sum/(60*60))*10)/10; + $sum="$sum hours"; + } + elseif ($sum>60) + { + $sum= round(($sum/(60))*10)/10; + $sum="$sum mins"; + } + else + { + $sum="$sum secs"; + } + + echo "<TD>$leng</TD>"; + echo "<TD>$sum</TD>"; + echo "<TD>$proc</TD>"; + echo "</TR>"; + } + echo "</TABLE><BR>"; +?> +</FONT> +</TR> +</TABLE></CENTER> + +<? + show_footer(); +?> diff --git a/frontends/php/alerts.html b/frontends/php/alerts.html new file mode 100644 index 00000000..85ae9907 --- /dev/null +++ b/frontends/php/alerts.html @@ -0,0 +1,84 @@ +<? + include "config.inc"; + $title = "Alerts"; + show_header($title,0); +?> + +<? + show_table_header_begin(); + echo "ALERTS"; + + show_table_v_delimiter(); +?> + +<? + if(isset($limit)) + { + echo "[<A HREF=\"alerts.html?limit=200\">"; + echo "Show last 200</A>]"; + $limit=" limit 50"; + } + else + { + echo "[<A HREF=\"alerts.html?limit=200\">"; + echo "Show last 200</A>]"; + $limit=" limit 200"; + } + + show_table_header_end(); + echo "<br>"; +?> + + +<FONT COLOR="#000000"> +<? + $sql="select alertid,clock,type,sendto,subject,message from alerts order by clock desc $limit"; + $result=mysql_query($sql,$mysql); + + echo "<CENTER>"; + echo "<TABLE WIDTH=100% BORDER=0 BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; + echo "<TR>"; + echo "<TD WIDTH=\"10%\"><FONT SIZE=+1>Time</FONT></TD>"; + echo "<TD WIDTH=\"5%\"><FONT SIZE=+1>Type</FONT></TD>"; + echo "<TD><FONT SIZE=+1>Send to</FONT></TD>"; + echo "<TD><FONT SIZE=+1>Subject</FONT></TD>"; + echo "<TD><FONT SIZE=+1>Message</FONT></TD>"; + echo "</TR>"; + while($row=mysql_fetch_row($result)) + { + if($col==1) + { + echo "<tr bgcolor=#DDDDDD>"; + $col=0; + } + else + { + echo "<tr bgcolor=#EEEEEE>"; + $col=1; + } + $clock=$row[1]; + $type=$row[2]; + if($type=="EMAIL") + { + $type="E-mail"; + } + $sendto=$row[3]; + $subject=$row[4]; + $message=$row[5]; + + echo "<TD>".date("Y.M.d H:i:s",$clock)."</TD>"; + echo "<TD>$type</TD>"; + echo "<TD>$sendto</TD>"; + echo "<TD>$subject</TD>"; + echo "<TD>$message</TD>"; + echo "</TR>"; + } + echo "</TABLE><BR>"; +?> +</FONT> +</TR> +</TABLE></CENTER> + +<? + show_footer(); +?> diff --git a/frontends/php/chart.html b/frontends/php/chart.html new file mode 100644 index 00000000..03756ae5 --- /dev/null +++ b/frontends/php/chart.html @@ -0,0 +1,111 @@ +<? + include "config.inc"; + +# PARAMETERS: + +# itemid +# period +# from + + $sizeX=900; + $sizeY=200; + + $shiftX=10; + $shiftY=10; + + $nodata=1; + + +// Header( "Content-type: text/html"); + Header( "Content-type: image/png"); + Header( "Expires: Mon, 17 Aug 1998 12:51:50 GMT"); + + $im = imagecreate($sizeX+$shiftX+61,$sizeY+2*$shiftY+10); + + $red=ImageColorAllocate($im,255,0,0); + $green=ImageColorAllocate($im,0,255,0); + $darkgreen=ImageColorAllocate($im,0,150,0); + $blue=ImageColorAllocate($im,0,0,255); + $yellow=ImageColorAllocate($im,255,255,0); + $cyan=ImageColorAllocate($im,0,255,255); + $black=ImageColorAllocate($im,0,0,0); + + $x=imagesx($im); + $y=imagesy($im); + + ImageFilledRectangle($im,0,0,$sizeX+$shiftX+61,$sizeY+2*$shiftY+10,$black); + + for($i=0;$i<=$sizeY;$i+=50) + { + ImageDashedLine($im,$shiftX,$i+$shiftY,$sizeX+$shiftX,$i+$shiftY,$darkgreen); + } + for($i=0;$i<=$sizeX;$i+=50) + { + ImageDashedLine($im,$i+$shiftX,$shiftY,$i+$shiftX,$sizeY+$shiftY,$darkgreen); + } + + $from_time = time(NULL)-$period-3600*$from; + $to_time = time(NULL)-3600*$from; + $result=mysql_query("select clock,value from history where itemid=$itemid and clock>$from_time and clock<$to_time order by clock",$mysql); + $len=0; + $maxX=-1000000000; + $maxY=-1000000000; + $minX=1000000000; + $minY=1000000000; + $x=array(); + $y=array(); + while($row=mysql_fetch_row($result)) + { + $nodata=0; + $x[$len]=$row[0]; + $y[$len]=$row[1]; +// echo $row[0]," - ",$y[$len],"<Br>"; + if($x[$len]>$maxX) { $maxX=$x[$len]; } + if($x[$len]<$minX) { $minX=$x[$len]; } + if($y[$len]>$maxY) { $maxY=$y[$len]; } + if($y[$len]<$minY) { $minY=$y[$len]; } + $len++; + } +// echo "MIN/MAX:",$minX," - ",$maxX," - ",$minY," - ",$maxY,"<Br>"; + + if(($minX!=$maxX)&&($minY!=$maxY)) + { + for($i=0;$i<$len-1;$i++) + { + $x1=$sizeX*($x[$i]-$minX)/($maxX-$minX); + $y1=$sizeY*($y[$i]-$minY)/($maxY-$minY); + $x2=$sizeX*($x[$i+1]-$minX)/($maxX-$minX); + $y2=$sizeY*($y[$i+1]-$minY)/($maxY-$minY); + + $y1=$sizeY-$y1; + $y2=$sizeY-$y2; + +// echo $x1," - ",$x2," - ",$y1," - ",$y2,"<Br>"; + ImageLine($im,$x1+$shiftX,$y1+$shiftY,$x2+$shiftX,$y2+$shiftY,$green); + } + } + else + { + ImageLine($im,$shiftX,$shiftY+$sizeY/2,$sizeX+$shiftX,$shiftY+$sizeY/2,$green); + } + + if($nodata == 0) + { + for($i=0;$i<=$sizeY;$i+=50) + { + ImageString($im, 1, $sizeX+5+$shiftX, $sizeY-$i-4+$shiftY, $i*($maxY-$minY)/$sizeY+$minY , $red); + } + + date("dS of F Y h:i:s A",$row[0]); + + ImageString($im, 1,10, $sizeY+$shiftY+5, date("dS of F Y h:i:s A",$minX) , $red); + ImageString($im, 1,$sizeX+$shiftX-168,$sizeY+$shiftY+5, date("dS of F Y h:i:s A",$maxX) , $red); + } + else + { + ImageString($im, 2,$sizeX/2 -50, $sizeY+$shiftY+3, "NO DATA FOR THIS PERIOD" , $red); + } + + ImagePng($im); + ImageDestroy($im); +?> diff --git a/frontends/php/config.html b/frontends/php/config.html new file mode 100644 index 00000000..d614fb48 --- /dev/null +++ b/frontends/php/config.html @@ -0,0 +1,55 @@ +<? + include "config.inc"; + $title = "Configuration of Zabbix"; + show_header($title,0); +?> + +<? + show_table_header("CONFIGURATION OF ZABBIX"); + echo "<br>"; +?> + +<? + if($register=="update") + { + update_config($smtp_server,$smtp_helo,$smtp_email); + } +?> + +<? + $result=mysql_query("select smtp_server,smtp_helo,smtp_email from config",$mysql); + $row=mysql_fetch_row($result); + $smtp_server=$row[0]; + $smtp_helo=$row[1]; + $smtp_email=$row[2]; +?> + +<? + show_table2_header_begin(); + echo "Configuration"; + + show_table2_v_delimiter(); + echo "<form method=\"post\" action=\"config.html\">"; + echo "SMTP server"; + show_table2_h_delimiter(); + echo "<input name=\"smtp_server\" value=\"$smtp_server\"size=40>"; + + show_table2_v_delimiter(); + echo "Value from SMTP HELO authentification"; + show_table2_h_delimiter(); + echo "<input name=\"smtp_helo\" value=\"$smtp_helo\"size=40>"; + + show_table2_v_delimiter(); + echo "ZABBIX email address to send alarms from"; + show_table2_h_delimiter(); + echo "<input name=\"smtp_email\" value=\"$smtp_email\"size=40>"; + + show_table2_v_delimiter2(); + echo "<input type=\"submit\" name=\"register\" value=\"update\">"; + + show_table2_header_end(); +?> + +<? + show_footer(); +?> diff --git a/frontends/php/config.inc b/frontends/php/config.inc new file mode 100644 index 00000000..dbf0fc4d --- /dev/null +++ b/frontends/php/config.inc @@ -0,0 +1,1165 @@ +<? + $DB_SERVER ="localhost"; + $DB_DATABASE ="zabbix"; + $DB_USER ="<user>"; + $DB_PWD ="<password>"; + + $mysql=mysql_pconnect($DB_SERVER,$DB_USER,$DB_PASSWORD); + mysql_select_db($DB_DATABASE); + + function cr() + { + echo "\n"; + } + + # Header for HTML pages + + function show_header($title,$refresh) + { + +?> + <!doctype html public "-//W3C//DTD HTML 3.2//EN"> + <html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="Author" content="Alexei Vladishev"> +<? + if($refresh!=0) + { + echo "<meta http-equiv=\"refresh\" content=\"$refresh\">"; + } +?> + <title><? echo $title; ?></title> + </head> + <body bgcolor="#778899" text="#000000" link="#000000" vlink="#000000" topmargin=4 leftmargin=0 rightmargin=0 marginheight=4> + + <table border=0 cellspacing=0 cellpadding=0 width="100%" bgcolor=000000> + <tr> + <td valign="top"> + <table width="100%" border=0 cellspacing=1 cellpadding=3> + <tr> + <td colspan=1 bgcolor=FFFFFF align=center valign="top" width="15%"> + <font face="Arial,Helvetica" size=2> + <a href="latest.html">LATEST VALUES</a> + </font> + </td> + <td colspan=1 bgcolor=FFFFFF align=center valign="top" width="10%"> + <font face="Arial,Helvetica" size=2> + <a href="tr_status.html?notitle=true&onlytrue=true&noactions=true&compact=true">STATUS OF TRIGGERS</a> + </font> + </td> + <td colspan=1 bgcolor=FFFFFF align=center valign="top" width="10%"> + <font face="Arial,Helvetica" size=2> + <a href="queue.html">QUEUE</a> + </font> + </td> + <td colspan=1 bgcolor=FFFFFF align=center valign="top" width="10%"> + <font face="Arial,Helvetica" size=2> + <a href="latestalarms.html">ALARMS</a> + </font> + </td> + <td colspan=1 bgcolor=FFFFFF align=center valign="top" width="15%"> + <font face="Arial,Helvetica" size=2> + <a href="alerts.html">ALERTS</a> + </font> + </td> + </tr> + <tr> + <td colspan=1 bgcolor=FFFFFF align=center valign="top" width="15%"> + <font face="Arial,Helvetica" size=2> + <a href="config.html">CONFIG</a> + </font> + </td> + <td colspan=1 bgcolor=FFFFFF align=center valign="top" width="10%"> + <font face="Arial,Helvetica" size=2> + <a href="users.html">USERS</a> + </font> + </td> + <td colspan=1 bgcolor=FFFFFF align=center valign="top" width="10%"> + <font face="Arial,Helvetica" size=2> + <a href="hosts.html">HOSTS</a> + </font> + </td> + <td colspan=1 bgcolor=FFFFFF align=center valign="top" width="10%"> + <font face="Arial,Helvetica" size=2> + <a href="items.html">ITEMS</a> + </font> + </td> + <td colspan=1 bgcolor=FFFFFF align=center valign="top" width="15%"> + <font face="Arial,Helvetica" size=2> + <a href="triggers.html">TRIGGERS</a> + </font> + </td> + </tr> + </table> + </td> + </tr> + </table> + + <br> +<? + } + + # Show values in plain text + + function show_plaintext($itemid, $from, $till) + { + global $mysql; + + $result=mysql_query("select clock,value from history where itemid=$itemid and clock>$from and clock<$till order by clock",$mysql); + + echo "<PRE>"; + while($row=mysql_fetch_row($result)) + { + $clock=$row[0]; + $value=$row[1]; + echo date("Y-m-d H:i:s",$clock); + echo "\t$clock\t$value\n"; + } + } + + + # Translate {10}>10 to something like localhost:procload.last(0)>10 + + function explode_exp ($expression, $html) + { + global $mysql; + +# echo "EXPRESSION:",$expression,"<Br>"; + + $functionid=''; + $exp=''; + for($i=0;$i<strlen($expression);$i++) + { + if($expression[$i] == '{') + { + $functionid=''; + $state='FUNCTIONID'; + continue; + } + if($expression[$i] == '}') + { + $state=''; + $sql="select h.host,i.key_,f.function,f.parameter,i.itemid from items i,functions f,hosts h where functionid=$functionid and i.itemid=f.itemid and h.hostid=i.hostid"; + $res1=mysql_query($sql,$mysql); + $row1=mysql_fetch_row($res1); + if($html == 0) + { + $exp=$exp."{".$row1[0].":".$row1[1].".".$row1[2]."(".$row1[3].")}"; + } + else + { + $exp=$exp."{<A HREF=\"history.html?action=showhistory&itemid=$row1[4]\">".$row1[0].":".$row1[1]."</A>.<B>".$row1[2]."(</B>".$row1[3]."<B>)</B>}"; + } + continue; + } + if($state == "FUNCTIONID") + { + $functionid=$functionid.$expression[$i]; + continue; + } + $exp=$exp.$expression[$i]; + } +# echo "EXP:",$exp,"<Br>"; + return $exp; + } + + # Translate localhost:procload.last(0)>10 to {12}>10 + + function implode_exp ($expression, $triggerid) + { + global $mysql; + + $exp=''; + for($i=0;$i<strlen($expression);$i++) + { + if($expression[$i] == '{') + { + if($state=="") + { + $host=''; + $key=''; + $function=''; + $parameter=''; + $state='HOST'; + continue; + } + } + if( ($expression[$i] == '}')&&($state=="") ) + { +# echo "HOST:$host<BR>"; +# echo "KEY:$key<BR>"; +# echo "FUNCTION:$function<BR>"; +# echo "PARAMETER:$parameter<BR>"; + $state=''; + + $sql="select i.itemid from items i,hosts h where i.key_='$key' and h.host='$host' and h.hostid=i.hostid"; +# echo $sql,"<Br>"; + $res=mysql_query($sql,$mysql); + $row=mysql_fetch_row($res); + + $itemid=$row[0]; +# echo "ITEMID:$itemid<BR>"; + +# $sql="select functionid from functions where function='$function' and parameter=$parameter"; +# echo $sql,"<Br>"; +# $res=mysql_query($sql,$mysql); +# $row=mysql_fetch_row($res); + +# if($row) +# { +# $functionid=$row[0]; +# } +# else +# { + $sql="insert into functions (functionid,itemid,triggerid,function,parameter) values (NULL,$itemid,$triggerid,'$function',$parameter)"; +# echo $sql,"<Br>"; + $res=mysql_query($sql,$mysql); + $functionid=mysql_insert_id($mysql); +# } +# echo "FUNCTIONID:$functionid<BR>"; + + $exp=$exp.'{'.$functionid.'}'; + + continue; + } + if($expression[$i] == '(') + { + if($state == "FUNCTION") + { + $state='PARAMETER'; + continue; + } + } + if($expression[$i] == ')') + { + if($state == "PARAMETER") + { + $state=''; + continue; + } + } + if($expression[$i] == ':') + { + $state="KEY"; + continue; + } + if($expression[$i] == '.') + { + if($state == "KEY") + { + $state="FUNCTION"; + continue; + } + } + if($state == "HOST") + { + $host=$host.$expression[$i]; + continue; + } + if($state == "KEY") + { + $key=$key.$expression[$i]; + continue; + } + if($state == "FUNCTION") + { + $function=$function.$expression[$i]; + continue; + } + if($state == "PARAMETER") + { + $parameter=$parameter.$expression[$i]; + continue; + } + $exp=$exp.$expression[$i]; + } + return $exp; + } + + # Update Trigger status + + function update_trigger_status($triggerid,$status) + { + global $mysql; + + $sql="update triggers set istrue=$status where triggerid=$triggerid"; + $result=mysql_query($sql,$mysql); + } + + # Update Item status + + function update_item_status($itemid,$status) + { + global $mysql; + + $sql="update items set status=$status where itemid=$itemid"; + $result=mysql_query($sql,$mysql); + } + + # Update Host status + + function update_host_status($hostid,$status) + { + global $mysql; + + $sql="update hosts set status=$status where hostid=$hostid"; + $result=mysql_query($sql,$mysql); + } + + # Update Item definition + + function update_item($itemid,$description,$key,$hostid,$delay,$history,$status) + { + global $mysql; + + $sql="update items set description='$description',key_='$key',hostid=$hostid,delay=$delay,history=$history,lastdelete=0,nextcheck=0,status=$status where itemid=$itemid"; + $result=mysql_query($sql,$mysql); + } + + # Add Action + + function add_action( $triggerid, $userid, $good, $delay, $subject, $message ) + { + global $mysql; + + $sql="insert into actions (actionid,triggerid,userid,good,delay,nextcheck,subject,message) values (NULL,$triggerid,$userid,$good,$delay,0,'$subject','$message')"; + $result=mysql_query($sql,$mysql); + } + + # Update Action + + function update_action( $actionid, $userid, $good, $delay, $subject, $message ) + { + global $mysql; + + $sql="update actions set userid=$userid,good=$good,delay=$delay,nextcheck=0,subject='$subject',message='$message' where actionid=$actionid"; + $result=mysql_query($sql,$mysql); + } + + # Delete Action by userid + + function delete_actions_by_userid( $userid ) + { + global $mysql; + + $sql="delete from actions where userid=$userid"; + $result=mysql_query($sql,$mysql); + } + + # Delete Action + + function delete_action( $actionid ) + { + global $mysql; + + $sql="delete from actions where actionid=$actionid"; + $result=mysql_query($sql,$mysql); + } + + # Delete from History + + function delete_history_by_itemid( $itemid ) + { + global $mysql; + + + $sql="delete from history where itemid=$itemid"; + $result=mysql_query($sql,$mysql); + } + + # Add Item definition + + function add_item($description,$key,$hostid,$delay,$history,$status) + { + global $mysql; + + $sql="insert into items (itemid,description,key_,hostid,delay,history,lastdelete,nextcheck,status) values (NULL,'$description','$key',$hostid,$delay,$history,0,0,$status)"; + $result=mysql_query($sql,$mysql); + return mysql_insert_id($mysql); + } + + # Delete Function definition + + function delete_function_by_triggerid($triggerid) + { + global $mysql; + + $sql="delete from functions where triggerid=$triggerid"; + $result=mysql_query($sql,$mysql); + } + + # Delete Function and Trigger definitions by itemid + + function delete_triggers_functions_by_itemid($itemid) + { + global $mysql; + + $sql="select triggerid from functions where itemid=$itemid"; + $result=mysql_query($sql,$mysql); + while($row=mysql_fetch_row($result)) + { + delete_function_by_triggerid($row[0]); + } + + $sql="delete from functions where itemid=$itemid"; + $result=mysql_query($sql,$mysql); + } + + # Delete Item definition + + function delete_item($itemid) + { + global $mysql; + + $sql="delete from items where itemid=$itemid"; + $result=mysql_query($sql,$mysql); + + delete_triggers_functions_by_itemid($itemid); + delete_history_by_itemid($itemid); + } + + # Add alarm + + function add_alarm($triggerid,$istrue) + { + global $mysql; + + $now=mktime(); + $sql="insert into alarms(triggerid,clock,istrue) values($triggerid,$now,$istrue)"; + $result=mysql_query($sql,$mysql); + } + + # Add Trigger definition + + function add_trigger($expression,$description,$priority,$istrue,$comments) + { + global $mysql; + + $sql="insert into triggers (triggerid,description,priority,istrue,comments) values (NULL,'$description',$priority,$istrue,'$comments')"; +# echo $sql,"<Br>"; + $result=mysql_query($sql,$mysql); + + $triggerid=mysql_insert_id($mysql); + + $expression=implode_exp($expression,$triggerid); + $sql="update triggers set expression='$expression' where triggerid=$triggerid"; +# echo $sql,"<Br>"; + $result=mysql_query($sql,$mysql); + } + + # Delete Trigger definition + + function delete_trigger($triggerid) + { + global $mysql; + + $sql="delete from triggers where triggerid=$triggerid"; + $result=mysql_query($sql,$mysql); + + delete_function_by_triggerid($triggerid); + } + + # Update Trigger definition + + function update_trigger($triggerid,$expression,$description,$priority,$istrue,$comments) + { + global $mysql; + + delete_trigger($triggerid); + + $triggerid=add_trigger($expression,$description,$priority,$istrue,$comments); + } + + # Add User definition + + function add_user($name,$surname,$alias) + { + global $mysql; + + $sql="insert into users (userid,name,surname,alias) values (NULL,'$name','$surname','$alias')"; + $result=mysql_query($sql,$mysql); + + return $result; + } + + # Add Items and Triggers from template + + function add_from_templates($hostid,$platformid,$host) + { + global $mysql; + + $result=mysql_query("select itemtemplateid,description,key_,delay from items_template where platformid=$platformid",$mysql); + while($row=mysql_fetch_row($result)) + { + $itemtemplateid=$row[0]; + $description=$row[1]; + $key=$row[2]; + $delay=$row[3]; + + $itemid=add_item($description,$key,$hostid,$delay,24*3600,0); + + $result2=mysql_query("select triggertemplateid,description,expression from triggers_template where itemtemplateid=$itemtemplateid",$mysql); + while($row2=mysql_fetch_row($result2)) + { + $itemtemplateid=$row2[0]; + $description=$row2[1]; + $expression=$row2[2]; + + for($i=0;$i<strlen($expression);$i++) + { + if($expression[$i] == ':') + { + $expression=substr($expression,0,$i)."$host:$key".substr($expression,$i); + + break; + } + } + + add_trigger($expression,$description,0,2,""); + } + } + } + + # Add Host definition + + function add_host($platformid,$host,$port,$status) + { + global $mysql; + + $sql="insert into hosts (hostid,platformid,host,port,status) values (NULL,$platformid,'$host',$port,$status)"; + $result=mysql_query($sql,$mysql); + $hostid=mysql_insert_id($mysql); + + add_from_templates($hostid,$platformid,$host); + + } + + # Add Media definition + + function add_media( $userid, $type, $sendto) + { + global $mysql; + + $sql="insert into media (userid,mediaid,type,sendto,active) values ($userid,NULL,'$type','$sendto',0)"; + $result=mysql_query($sql,$mysql); + } + + # Delete Media definition + + function delete_media($mediaid) + { + global $mysql; + + $sql="delete from media where mediaid=$mediaid"; + $result=mysql_query($sql,$mysql); + } + + # Delete Media definition by userid + + function delete_media_by_userid($userid) + { + global $mysql; + + $sql="delete from media where userid=$userid"; + $result=mysql_query($sql,$mysql); + } + + # Update configuration + + function update_config($smtp_server,$smtp_helo,$smtp_email) + { + global $mysql; + + $sql="update config set smtp_server=\"$smtp_server\",smtp_helo=\"$smtp_helo\",smtp_email=\"$smtp_email\""; + $result=mysql_query($sql,$mysql); + } + + + # Activate Media + + function activate_media($mediaid) + { + global $mysql; + + $sql="update media set active=0 where mediaid=$mediaid"; + $result=mysql_query($sql,$mysql); + } + + # Disactivate Media + + function disactivate_media($mediaid) + { + global $mysql; + + $sql="update media set active=1 where mediaid=$mediaid"; + $result=mysql_query($sql,$mysql); + } + + # Delete Host + + function delete_host($hostid) + { + global $mysql; + + $sql="select itemid from items where hostid=$hostid"; + $result=mysql_query($sql,$mysql); + while($row=mysql_fetch_row($result)) + { + delete_item($row[0]); + } + + $sql="delete from hosts where hostid=$hostid"; + $result=mysql_query($sql,$mysql); + } + + # Delete User definition + + function delete_user($userid) + { + global $mysql; + + delete_media_by_userid($userid); + delete_actions_by_userid($userid); + + $sql="delete from users where userid=$userid"; + $result=mysql_query($sql,$mysql); + } + + function show_table_h_delimiter() + { + echo "</font>"; + cr(); + echo "</td>"; + cr(); + echo "<td colspan=1 bgcolor=FFFFFF align=center valign=\"top\">"; + cr(); + echo " <font face=\"Arial,Helvetica\" size=2>"; + cr(); + } + + function show_table2_h_delimiter() + { + echo "</font>"; + cr(); + echo "</td>"; + cr(); + echo "<td colspan=1 bgcolor=CCCCCC align=left valign=\"top\">"; + cr(); + echo " <font face=\"Arial,Helvetica\" size=-1>"; + cr(); + } + + function show_table_v_delimiter() + { + echo "</font>"; + cr(); + echo "</td>"; + cr(); + echo "</tr>"; + cr(); + echo "<tr>"; + cr(); + echo "<td colspan=1 bgcolor=FFFFFF align=center valign=\"top\">"; + cr(); + echo "<font face=\"Arial,Helvetica\" size=2>"; + cr(); + } + + function show_table2_v_delimiter() + { + echo "</font>"; + cr(); + echo "</td>"; + cr(); + echo "</tr>"; + cr(); + echo "<tr>"; + cr(); + echo "<td colspan=1 bgcolor=CCCCCC align=left valign=\"top\">"; + cr(); + echo "<font face=\"Arial,Helvetica\" size=-1>"; + cr(); + } + + function show_table2_v_delimiter2() + { + echo "</font>"; + cr(); + echo "</td>"; + cr(); + echo "</tr>"; + cr(); + echo "<tr>"; + cr(); + echo "<td colspan=2 bgcolor=\"99AABB\" align=right valign=\"top\">"; + cr(); + echo "<font face=\"Arial,Helvetica\" size=-1>"; + cr(); + } + + + + function show_table2_header_begin() + { + echo "<center>"; + cr(); + echo "<table border=0 cellspacing=0 cellpadding=0 width=\"50%\" bgcolor=000000>"; + cr(); + echo "<tr>"; + cr(); + echo "<td valign=\"top\">"; + cr(); + echo "<table width=\"100%\" border=0 cellspacing=1 cellpadding=3>"; + cr(); + echo "<tr>"; + cr(); + echo "<td colspan=2 bgcolor=99AABB align=center valign=\"top\">"; + cr(); + echo " <font face=\"Arial,Helvetica\" size=+1>"; + cr(); + } + + function show_table_header_begin() + { + echo "<table border=0 cellspacing=0 cellpadding=0 width=\"100%\" bgcolor=000000>"; + cr(); + echo "<tr>"; + cr(); + echo "<td valign=\"top\">"; + cr(); + echo "<table width=\"100%\" border=0 cellspacing=1 cellpadding=3>"; + cr(); + echo "<tr>"; + cr(); + echo "<td colspan=1 bgcolor=99AABB align=center valign=\"top\">"; + cr(); + echo " <font face=\"Arial,Helvetica\" size=+1>"; + cr(); + } + + function show_table2_header_end() + { + echo " </font>"; + cr(); + echo "</td>"; + cr(); + echo "</tr>"; + cr(); + echo "</table>"; + cr(); + echo "</td>"; + cr(); + echo "</tr>"; + cr(); + echo "</table>"; + cr(); + echo "</center>"; + cr(); + } + + function show_table_header_end() + { + echo " </font>"; + cr(); + echo "</td>"; + cr(); + echo "</tr>"; + cr(); + echo "</table>"; + cr(); + echo "</td>"; + cr(); + echo "</tr>"; + cr(); + echo "</table>"; + cr(); + } + + function show_table_header($title) + { + show_table_header_begin(); + cr(); + echo $title; + cr(); + show_table_header_end(); + cr(); + } + + # Show History Graph + + function show_history($itemid,$from,$period) + { + if (!isset($from)) + { + $from=0; + $till="NOW"; + } + else + { + $till=time(NULL)-$from*3600; + $till=date("d M - H:i:s",$till); + } + + echo "<center>"; + + if (!isset($period)) + { + $period=3600; + show_table_header("TILL $till (LAST HOUR)"); + } + else + { + $tmp=$period/3600; + show_table_header("TILL $till ($tmp HOURs)"); + } + echo("<hr>"); + echo "<IMG SRC=\"chart.html?itemid=$itemid&period=$period&from=$from\">"; + echo("<hr>"); + + + // Start of <<< WEEK >>> + $tmp=$from+12*14; + echo("[<A HREF=\"history.html?action=showhistory&itemid=$itemid&from=$tmp&period=$period\">"); + echo("Week back</A>] "); + + // Start of <<< 12h >>> + $tmp=$from+12; + echo("[<A HREF=\"history.html?action=showhistory&itemid=$itemid&from=$tmp&period=$period\">"); + echo("12h back</A>] "); + // End of <<< 12h >>> + + // HOUR BACK + $tmp=$from+1; + echo("[<A HREF=\"history.html?action=showhistory&itemid=$itemid&from=$tmp&period=$period\">"); + echo("1h back</A>] "); + + // Start of --- + $tmp=$period+3600; + echo("[<A HREF=\"history.html?action=showhistory&itemid=$itemid&from=$from&period=$tmp\">"); + echo("+1h</A>] "); + + if ($period>3600) + { + $tmp=$period-3600; + echo("[<A HREF=\"history.html?action=showhistory&itemid=$itemid&from=$from&period=$tmp\">"); + echo("-1h</A>] "); + } + else + { + echo("[-1h]"); + } + // End of ------ + + if ($from>0) // HOUR FORWARD + { + $tmp=$from-1; + echo("[<A HREF=\"history.html?action=showhistory&itemid=$itemid&from=$tmp&period=$period\">"); + echo("1h forward</A>] "); + } + else + { + echo("[1h forward]"); + } + + + if ($From>0) // 12h FORWARD + { + $tmp=$from-12; + echo("[<A HREF=\"history.html?action=showhistory&itemid=$itemid&from=$tmp&period=$period\">"); + echo("12h forward</A>] "); + } + else + { + echo("[12h forward]"); + } + + if ($From>0) // WEEK Forward + { + $tmp=$from-12*14; + echo("[<A HREF=\"history.html?action=showhistory&itemid=$itemid&from=$tmp&period=$period\">"); + echo("Week forward</A>] "); + } + else + { + echo("[Week forward]"); + } + + echo("</body></html>\n"); + } + + # Show history + function show_freehist($itemid,$period) + { + + echo "<br>"; + show_table2_header_begin(); + echo "Choose period"; + + show_table2_v_delimiter(); + echo "<form method=\"post\" action=\"history.html\">"; + echo "<input name=\"itemid\" type=\"hidden\" value=$itemid size=8>"; + echo "Period in seconds"; + show_table2_h_delimiter(); + echo "<input name=\"period\" value=\"7200\" size=8>"; + + show_table2_v_delimiter(); + echo "From (in hours)"; + show_table2_h_delimiter(); + echo "<input name=\"from\" value=\"24\" size=8>"; + + show_table2_v_delimiter2(); + echo "Press "; + echo "<input type=\"submit\" name=\"action\" value=\"showvalues\"> to see graph"; + + show_table2_header_end(); + + show_footer(); + } + + # Show in plain text + function show_plaintxt($itemid,$period) + { + show_table2_header_begin(); + echo "Data in plain text format"; + + show_table2_v_delimiter(); + echo "<form method=\"get\" action=\"history.html\">"; + echo "<input name=\"itemid\" type=\"Hidden\" value=$itemid size=8>"; + echo "<input name=\"itemid\" type=\"Hidden\" value=$itemid size=8>"; + echo "From: (yyyy/mm/dd - HH:MM)"; + show_table2_h_delimiter(); + echo "<input name=\"fromyear\" value=\"",date("Y"),"\" size=5>/"; + echo "<input name=\"frommonth\" value=\"",date("m"),"\" size=3>/"; + echo "<input name=\"fromday\" value=\"",date("d"),"\" size=3> - "; + echo "<input name=\"fromhour\" value=\"0\" size=3>:"; + echo "<input name=\"frommin\" value=\"00\" size=3>"; + + show_table2_v_delimiter(); + echo "Till: (yyyy/mm/dd - HH:MM)"; + show_table2_h_delimiter(); + echo "<input name=\"tillyear\" value=\"",date("Y"),"\" size=5>/"; + echo "<input name=\"tillmonth\" value=\"",date("m"),"\" size=3>/"; + echo "<input name=\"tillday\" value=\"",date("d"),"\" size=3> - "; + echo "<input name=\"tillhour\" value=\"23\" size=3>:"; + echo "<input name=\"tillmin\" value=\"59\" size=3>"; + + show_table2_v_delimiter2(); + echo "Press to see data in "; + echo "<input type=\"submit\" name=\"action\" value=\"plaintext\">"; + + show_table2_header_end(); + + show_footer(); + } + + # Insert form for Item information + function insert_item_form($itemid) + { + global $mysql; + + if(isset($itemid)) + { + mysql_select_db("monitor"); + $result=mysql_query("select i.description, i.key_, h.host, h.port, i.delay, i.history, i.status from items i,hosts h where i.itemid=$itemid and h.hostid=i.hostid",$mysql); + $row=mysql_fetch_row($result); + + $description=$row[0]; + $key=$row[1]; + $host=$row[2]; + $port=$row[3]; + $delay=$row[4]; + $history=$row[5]; + $status=$row[6]; + } + if( !isset($port) ) + { + $port=10000; + } + if( !isset($delay) ) + { + $delay=30; + } + if( !isset($history) ) + { + $history=30*24*3600; + } + if( !isset($status) ) + { + $status=0; + } + + echo "<br>"; + + show_table2_header_begin(); + echo "Item configuration"; + + show_table2_v_delimiter(); + echo "<form method=\"post\" action=\"items.html\">"; + echo "<input name=\"itemid\" type=hidden value=$itemid size=8>"; + echo "Description"; + show_table2_h_delimiter(); + echo "<input name=\"description\" value=\"$description\"size=40>"; + + show_table2_v_delimiter(); + echo "Host"; + show_table2_h_delimiter(); + echo "<select name=\"hostid\" value=\"3\">"; + $result=mysql_query("select hostid,host from hosts order by host",$mysql); + while($row=mysql_fetch_row($result)) + { + $hostid_=$row[0]; + $host_=$row[1]; + if($host==$host_) + { + echo "<option value=\"$hostid_\" selected>$host_"; + } + else + { + echo "<option value=\"$hostid_\">$host_"; + } + } + echo "</select>"; + + show_table2_v_delimiter(); + echo "Key"; + show_table2_h_delimiter(); + echo "<input name=\"key\" value=\"$key\"size=40>"; + + show_table2_v_delimiter(); + echo "Delay"; + show_table2_h_delimiter(); + echo "<input name=\"delay\" value=\"$delay\"size=5>"; + + show_table2_v_delimiter(); + echo "History"; + show_table2_h_delimiter(); + echo "<input name=\"history\" value=\"$history\"size=8>"; + + show_table2_v_delimiter(); + echo "Status"; + show_table2_h_delimiter(); + echo "<SELECT NAME=\"status\" value=\"$status\" size=\"1\">"; + echo "<OPTION VALUE=\"0\""; + if($status==0) echo "SELECTED"; + echo ">Monitored"; + echo "<OPTION VALUE=\"1\""; + if($status==1) echo "SELECTED"; + echo ">Disabled"; + echo "<OPTION VALUE=\"2\""; + if($status==2) echo "SELECTED"; + echo ">Trapper"; + echo "<OPTION VALUE=\"3\""; + if($status==3) echo "SELECTED"; + echo ">Not supported"; + echo "</SELECT>"; + + show_table2_v_delimiter2(); + echo "<input type=\"submit\" name=\"register\" value=\"add\">"; + if(isset($itemid)) + { + echo "<input type=\"submit\" name=\"register\" value=\"update\">"; + echo "<input type=\"submit\" name=\"register\" value=\"delete\">"; + } + + show_table2_header_end(); +?> +<? +?> +</TR> +</TABLE> + +</CENTER> +</FORM> + +</BODY> +</HTML> +<? + } + + # Insert form for Trigger + function insert_trigger_form($triggerid) + { + global $mysql; + + if(isset($triggerid)) + { + $result=mysql_query("select expression,description,priority,istrue,comments from triggers where triggerid=$triggerid",$mysql); + $row=mysql_fetch_row($result); + + if(!isset($expression)) $expression=$row[0]; + $expression=explode_exp($expression,0); + + if(!$description) $description=$row[1]; + if(!$priority) $priority=$row[2]; + if(!$istrue) $istrue=$row[3]; + if(!$comments) $comments=$row[6]; + } + + echo "<br>"; + + show_table2_header_begin(); + echo "Trigger configuration"; + + show_table2_v_delimiter(); + echo "<form method=\"post\" action=\"triggers.html\">"; + echo "<input name=\"triggerid\" type=hidden value=$triggerid size=8>"; + echo "Description"; + show_table2_h_delimiter(); + echo "<input name=\"description\" value=\"$description\"size=70>"; + + show_table2_v_delimiter(); + echo "Expression"; + show_table2_h_delimiter(); + echo "<input name=\"expression\" value=\"$expression\"size=70>"; + + show_table2_v_delimiter(); + echo "Priority"; + show_table2_h_delimiter(); + echo "<SELECT NAME=\"priority\" size=\"1\">"; + echo "<OPTION VALUE=\"0\" "; if($priority==0) echo "SELECTED"; echo ">Not classified"; + echo "<OPTION VALUE=\"1\" "; if($priority==1) echo "SELECTED"; echo ">Just for information"; + echo "<OPTION VALUE=\"2\" "; if($priority==2) echo "SELECTED"; echo ">Warning"; + echo "<OPTION VALUE=\"3\" "; if($priority==3) echo "SELECTED"; echo ">Average"; + echo "<OPTION VALUE=\"4\" "; if($priority==4) echo "SELECTED"; echo ">High"; + echo "<OPTION VALUE=\"5\" "; if($priority==5) echo "SELECTED"; echo ">Disaster"; + echo "</SELECT>"; + + show_table2_v_delimiter(); + echo "Comments"; + show_table2_h_delimiter(); + echo "<TEXTAREA NAME=\"comments\" COLS=54 ROWS=\"5\" WRAP=\"SOFT\">$comments</TEXTAREA>"; + + show_table2_v_delimiter(); + echo "Disabled"; + show_table2_h_delimiter(); + echo "<INPUT TYPE=\"CHECKBOX\" "; + if($istrue==2) { echo "CHECKED"; } + echo "NAME=\"disabled\" VALUE=\"true\">"; + + show_table2_v_delimiter2(); + echo "<input type=\"submit\" name=\"register\" value=\"add\">"; + if(isset($triggerid)) + { + echo "<input type=\"submit\" name=\"register\" value=\"update\">"; + echo "<input type=\"submit\" name=\"register\" value=\"delete\">"; + } + show_table2_header_end(); + } + + + function show_footer() + { + echo "<table border=0 cellpadding=1 cellspacing=5 width=\"100%\" align=center>"; + echo "<tr>"; + echo "<td bgcolor=\"#000000\">"; + echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\" width=\"100%\" bgcolor=\"#666666\">"; + echo "<tr><td align=center>"; + echo "<font face=\"Arial,Helvetica\" size=1>"; + echo "<a href=\"http://zabbix.sourceforge.net\">ZABBIX</a> Copyright 2000,2001 by <a href=\"mailto:alex@gobbo.caves.lv\">Alexei Vladishev</a>"; + echo "</font>"; + echo "</td></tr>"; + echo "</table>"; + echo "</table>"; + } +?> diff --git a/frontends/php/history.html b/frontends/php/history.html new file mode 100644 index 00000000..3259bee1 --- /dev/null +++ b/frontends/php/history.html @@ -0,0 +1,165 @@ +<? + include "config.inc"; + + if(!isset($itemid)) + { + echo "Missing <B>itemid</B> Parameter - See System Administror"; + exit; + } + + $result=mysql_query("select h.host,i.description,i.nextcheck-unix_timestamp(now()),h.hostid from items i,hosts h where i.itemid=$itemid and h.hostid=i.hostid"); + while($row=mysql_fetch_row($result)) + { + $host=$row[0]; + $description=$row[1]; + $beforenextcheck=$row[2]+10; + $hostid=$row[3]; + } + + if($action=="showhistory") + { + show_header("$host:$description",$beforenextcheck); + } + if($action=="showvalues") + { + show_header("$host:$description",0); + } + if($action=="showfreehist") + { + show_header("$host:$description",0); + } + if($action=="showplaintxt") + { + show_header("$host:$description",0); + } +?> + +<? + if($action=="plaintext") + { + $from=mktime($fromhour,$frommin,0,$frommonth,$fromday,$fromyear); + $till=mktime($tillhour,$tillmin,0,$tillmonth,$tillday,$tillyear); + show_plaintext($itemid, $from, $till); + exit; + } + +?> + +<? + show_table_header_begin(); + echo "<A HREF='latest.html?hostid=$hostid'>$host</A> : $description"; + show_table_v_delimiter(); + echo("<DIV ALIGN=CENTER>"); + if($action =="showhistory") + { + echo("<b>[<A HREF=\"history.html?action=showhistory&itemid=$itemid\">Last hour graph</A>]</b> "); + } + else + { + echo("<A HREF=\"history.html?action=showhistory&itemid=$itemid\">Last hour graph</A> "); + } + if($action =="showvalues") + { + echo("<b>[<A HREF=\"history.html?action=showvalues&itemid=$itemid&period=3600\">Values of last hour</A>]</b> "); + } + else + { + echo("<A HREF=\"history.html?action=showvalues&itemid=$itemid&period=3600\">Values of last hour</A> "); + } + if($action =="showfreehist") + { + echo("<b>[<A HREF=\"history.html?action=showfreehist&itemid=$itemid\">Values of specified period</A>]</b> "); + } + else + { + echo("<A HREF=\"history.html?action=showfreehist&itemid=$itemid\">Values of specified period</A> "); + } + if($action =="showplaintxt") + { + echo("<b>[<A HREF=\"history.html?action=showplaintxt&itemid=$itemid\">Values in plaint text format</A>]</b> "); + } + else + { + echo("<A HREF=\"history.html?action=showplaintxt&itemid=$itemid\">Values in plaint text format</A> "); + } + echo("</DIV>\n"); + show_table_header_end(); + echo("<br>"); + + if($action=="showfreehist") + { + if(!isset($period)) + { + show_freehist($itemid,$period); + } + exit; + + } + + if($action=="showplaintxt") + { + if(!isset($period)) + { + show_plaintxt($itemid,$period); + } + exit; + + } + + if($action=="showvalues") + { + if(!isset($from)) + { + $from=0; + } + if(!isset($period)) + { + $period=3600; + } + $time=time(NULL)-$period-$from*3600; + $till=time(NULL)-$from*3600; + $hours=$period/3600; + + show_table_header("Showing history of $period seconds($hours h)<BR>[from: ".date("d M - H:i:s",$time)."] [till: ".date("d M - H:i:s",$till)."]"); + + echo "<TABLE BORDER=0 COLS=2 ALIGN=CENTER WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; + echo "<TR>"; + echo "<TD><B>Clock</B></TD>"; + echo "<TD><B>Value</B></TD>"; + echo "</TR>"; + + + $result=mysql_query("select clock,value from history where itemid=$itemid and clock>$time and clock<$till order by clock desc"); + while($row=mysql_fetch_row($result)) + { + if($col==1) + { + echo "<TR BGCOLOR=#DDDDDD>"; + $col=0; + } else + { + echo "<TR BGCOLOR=#EEEEEE>"; + $col=1; + } + $clock=$row[0]; + $value=$row[1]; + $clock=date("d M - H:i:s",$clock); + echo "<TD>$clock</TD>"; + echo "<TD>$value</TD>"; + echo "</TR>"; + } + echo "</TABLE><CENTER><BR>"; + + echo("</CENTER></BODY></HTML>\n"); + + show_footer(); + exit; + } + + if($action=="showhistory") + { + show_history($itemid,$from,$period); + show_footer(); + exit; + } +?> diff --git a/frontends/php/hosts.html b/frontends/php/hosts.html new file mode 100644 index 00000000..287cdb00 --- /dev/null +++ b/frontends/php/hosts.html @@ -0,0 +1,118 @@ +<? + include "config.inc"; + $title = "Hosts"; + show_header($title,0); +?> + +<? + show_table_header("CONFIGURATION OF HOSTS"); + echo "<br>"; +?> + +<? + if($register=="add") + { + add_host($platformid,$host,$port,$status); + } + if($register=="changestatus") + { + update_host_status($hostid,$status); + } + if($register=="delete") + { + delete_host($hostid); + } +?> + +<? + show_table_header("HOSTS"); + echo "<TABLE BORDER=0 COLS=4 WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; + echo "<TR><TD WIDTH=\"10%\"><B>Platform</B></TD>"; + echo "<TD WIDTH=\"10%\" NOSAVE><B>Host</B></TD>"; + echo "<TD WIDTH=\"10%\" NOSAVE><B>Port</B></TD>"; + echo "<TD WIDTH=\"10%\" NOSAVE><B>Status</B></TD>"; + echo "<TD WIDTH=\"10%\" NOSAVE><B>Actions</B></TD>"; + echo "</TR>"; + + $result=mysql_query("select h.hostid,p.platform,h.host,h.port,h.status from hosts h,platforms p where p.platformid=h.platformid order by p.platform,h.host",$mysql); + echo "<CENTER>"; + while($row=mysql_fetch_row($result)) + { + if($col==1) + { + echo "<TR BGCOLOR=#EEEEEE>"; + $col=0; + } else + { + echo "<TR BGCOLOR=#DDDDDD>"; + $col=1; + } + + $hostid=$row[0]; + $platform=$row[1]; + $host=$row[2]; + $port=$row[3]; + $status=$row[4]; + echo "<TD>$platform</TD>"; + echo "<TD><a href=\"items.html?hostid=$hostid\">$host</a></TD>"; + echo "<TD>$port</TD>"; + echo "<TD>"; + if($status == 0) + echo "<a href=\"hosts.html?hostid=$hostid®ister=changestatus&status=1\">Monitored</a>"; + else if($status == 1) + echo "<a href=\"hosts.html?hostid=$hostid®ister=changestatus&status=0\">Not monitored</a>"; + else + echo "Unknown"; + echo "</TD>"; + echo "<TD><A HREF=\"hosts.html?register=delete&hostid=$hostid\">Delete</A></TD>"; + echo "</TR>"; + } + echo "</TABLE>"; +?> + +<? + echo "<br>"; + show_table2_header_begin(); + echo "New host"; + + show_table2_v_delimiter(); + echo "<form method=\"post\" action=\"hosts.html\">"; + echo "Platform"; + show_table2_h_delimiter(); + echo "<select name=\"platformid\">"; + $result=mysql_query("select platformid,platform from platforms order by platform",$mysql); + while($row=mysql_fetch_row($result)) + { + $platformid=$row[0]; + $platform=$row[1]; + echo "<option value=\"$platformid\">$platform"; + } + echo "</select>"; + + show_table2_v_delimiter(); + echo "Host"; + show_table2_h_delimiter(); + echo "<input name=\"host\" size=20>"; + + show_table2_v_delimiter(); + echo "Port"; + show_table2_h_delimiter(); + echo "<input name=\"port\" size=5 value=\"10000\">"; + + show_table2_v_delimiter(); + echo "Status"; + show_table2_h_delimiter(); + echo "<select name=\"status\" size=\"1\">"; + echo "<option value=\"0\" \"selected\">Monitored"; + echo "<option value=\"1\">Not monitored"; + echo "</select>"; + + show_table2_v_delimiter2(); + echo "<input type=\"submit\" name=\"register\" value=\"add\">"; + + show_table2_header_end(); +?> + +<? + show_footer(); +?> diff --git a/frontends/php/index.html b/frontends/php/index.html new file mode 100644 index 00000000..9ffb1c35 --- /dev/null +++ b/frontends/php/index.html @@ -0,0 +1,9 @@ +<? + include "config.inc"; + $title="Monitoring"; + show_header($title,0); +?> + +<? + show_footer(); +?> diff --git a/frontends/php/items.html b/frontends/php/items.html new file mode 100644 index 00000000..395c9ccf --- /dev/null +++ b/frontends/php/items.html @@ -0,0 +1,181 @@ +<? + include "config.inc"; + $title = "Configuration of items"; + show_header($title,0); +?> + +<? + + if($register=="update") + { + update_item($itemid,$description,$key,$hostid,$delay,$history,$status); + } + if($register=="changestatus") + { + update_item_status($itemid,$status); + } + if($register=="add") + { + add_item($description,$key,$hostid,$delay,$history,$status); + } + if($register=="delete") + { + delete_item($itemid); + } +?> + +<? + show_table_header_begin(); + echo "CONFIGURATION OF ITEMS"; + show_table_v_delimiter(); +?> + +<? + $result=mysql_query("select hostid,host from hosts order by host",$mysql); + if(isset($hostid)) + { + echo "<A HREF=\"items.html\">all</A> "; + } + else + { + echo "<b>[<A HREF=\"items.html\">all</A>]</b> "; + } + while($row=mysql_fetch_row($result)) + { + $hid=$row[0]; + $host=$row[1]; + if($hostid == $hid) + { + echo "<b>["; + } + echo "<A HREF=\"items.html?hostid=$hid\">$host</A>"; + if($hostid == $hid) + { + echo "]</b>"; + } + echo " "; + } + show_table_header_end(); + echo "<br>"; + + $lasthost=""; + if(isset($hostid)) + { + $whereonly="where h.hostid=i.hostid and h.hostid=$hostid"; + } + else + { + $whereonly="where h.hostid=i.hostid"; + } + $result=mysql_query("select h.host,i.key_,i.itemid,i.description,h.port,i.delay,i.history,i.lastvalue,i.lastclock,i.status,i.lastdelete,i.nextcheck,h.hostid from hosts h,items i $whereonly order by h.host,i.key_,i.description",$mysql); + echo "<CENTER>"; + while($row=mysql_fetch_row($result)) + { + $host=$row[0]; + $itemid_=$row[2]; + $hostid_=$row[12]; +// echo "\n<br><hr><b>=$host= =$lasthost=</b>\n"; + if($lasthost!=$host) + { + if($lasthost!="") + { + echo "</TABLE><BR>"; + } + show_table_header("<A HREF='items.html?hostid=$hostid_'>$host</A>"); + echo "<TABLE BORDER=0 COLS=13 WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; + cr(); + echo "<TR>"; + cr(); + echo "<TD WIDTH=\"10%\" NOSAVE><B>Host</B></TD>"; + cr(); + echo "<TD WIDTH=\"10%\" NOSAVE><B>Key</B></TD>"; + cr(); + echo "<TD WIDTH=\"10%\" ><B>Description</B></TD>"; + cr(); + echo "<TD WIDTH=\"5%\" NOSAVE><B>Delay</B></TD>"; + cr(); + echo "<TD WIDTH=\"5%\" NOSAVE><B>History</B></TD>"; + cr(); + echo "<TD><B>Shortname</B></TD>"; + cr(); + echo "<TD WIDTH=\"5%\" NOSAVE><B>Status</B></TD>"; + cr(); + echo "<TD WIDTH=\"5%\" NOSAVE><B>Lastdelete</B></TD>"; + cr(); + echo "<TD WIDTH=\"5%\" NOSAVE><B>Nextcheck</B></TD>"; + cr(); + echo "<TD WIDTH=\"5%\" NOSAVE><B>Actions</B></TD>"; + cr(); + echo "</TR>"; + cr(); + } + $lasthost=$host; + if($col==1) + { + echo "<TR BGCOLOR=#DDDDDD>"; + cr(); + $col=0; + } else + { + echo "<TR BGCOLOR=#EEEEEE>"; + $col=1; + } + $host=$row[0]; + $port=$row[4]; + $delay=$row[5]; + $history=$row[6]; + $shortname=$row[0].':'.$row[1]; + $key=$row[1]; + $description=$row[3]; + $lastvalue=$row[7]; + $lastclock=date("y/m/d H:i:s",$row[9]); + $itemid_=$row[2]; + $status=$row[9]; + $lastdelete=date("y/m/d H:i:s",$row[10]); + $nextcheck=date("y/m/d H:i:s",$row[11]); + echo "<TD>$host</TD>"; + echo "<TD>$key</TD>"; + echo "<TD>$description</TD>"; + $description=rawurlencode($description); + echo "<TD>$delay</TD>"; + echo "<TD>$history</TD>"; + echo "<TD>$shortname</TD>"; + + echo "<td align=center>"; + if($status==0) echo "<a href=\"items.html?itemid=$itemid_®ister=changestatus&status=1\">Active</a>"; + elseif($status==1) echo "<a href=\"items.html?itemid=$itemid_®ister=changestatus&status=0\">Not active</a>"; + elseif($status==2) echo "Traper"; + elseif($status==3) echo "Not supported"; + elseif($status==10) echo "Autodisabled"; + else echo "<TD ALIGN=CENTER><B>$status</B> Unknown</TD>"; + echo "</td>"; + + echo "<TD>$lastdelete</TD>"; + echo "<TD>$nextcheck</TD>"; + + if(isset($hostid_)) + { + echo "<TD><A HREF=\"items.html#form?hostid=$hostid_&itemid=$itemid_\">Change</A></TD>"; + } + else + { + echo "<TD><A HREF=\"items.html#form?itemid=$itemid_\">Change</A></TD>"; + } + echo "</TR>"; + } + echo "</TABLE>"; +?> + +<? + $result=mysql_query("select count(*) from hosts",$mysql); + $row=mysql_fetch_row($result); + if($row[0]>0) + { + echo "<a name=\"form\"></a>"; + insert_item_form($itemid); + } +?> + +<? + show_footer(); +?> diff --git a/frontends/php/latest.html b/frontends/php/latest.html new file mode 100644 index 00000000..54c0f175 --- /dev/null +++ b/frontends/php/latest.html @@ -0,0 +1,154 @@ +<? + include "config.inc"; + $title = "Latest values"; + show_header($title,0); +?> + +<? + show_table_header_begin(); + echo "LATEST DATA"; + + show_table_v_delimiter(); + + echo "<font size=2>"; + + $lasthost=""; + $result=mysql_query("select h.hostid,h.host from hosts h,items i where h.status=0 and h.hostid=i.hostid group by h.hostid,h.host order by h.host",$mysql); + + if(isset($hostid)) + { + echo "<a href='latest.html'>all</a> "; + } + else + { + echo "<b>[<a href='latest.html'>all</a>]</b> "; + } + while($row=mysql_fetch_row($result)) + { + $hostid_=$row[0]; + $host=$row[1]; + if($hostid == $hostid_) + { + echo "<b>["; + } + echo "<a href='latest.html?hostid=$hostid_'>$host</a>"; + if($hostid == $hostid_) + { + echo "]</b>"; + } + echo " "; + } + + echo "</font>"; + show_table_header_end(); + echo "<br>"; + + if(isset($hostid)) + { + $where="where h.hostid=i.hostid and h.status=0 and h.hostid=$hostid"; + } + else + { + $where="where h.hostid=i.hostid and h.status=0"; + } + + $result=mysql_query("select h.host,i.itemid,i.description,i.lastvalue,i.prevvalue,i.lastclock,i.status,h.hostid from items i,hosts h $where order by h.host,i.description",$mysql); + while($row=mysql_fetch_row($result)) + { + $host=$row[0]; + $itemid=$row[1]; + $hostid=$row[7]; + if($lasthost!=$host) + { + if($lasthost!="") + { + echo "</table>"; + } + show_table_header("<a href=\"latest.html?hostid=$hostid\">$host</a>"); + + echo "<TABLE BORDER=0 COLS=4 WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; + cr(); + echo "<TR>"; + cr(); + echo "<TD><B>Description</B></TD>"; + cr(); + echo "<TD WIDTH=\"10%\" NOSAVE><B>Last check</B></TD>"; + cr(); + echo "<TD WIDTH=\"10%\" NOSAVE><B>Last value</B></TD>"; + cr(); + echo "<TD WIDTH=\"5%\" NOSAVE><B>Change</B></TD>"; + cr(); + echo "<TD WIDTH=\"10%\" NOSAVE><center><B>History</B></center></TD>"; + cr(); + echo "</TR>"; + cr(); + } + $lasthost=$host; + if($col==1) + { + echo "<tr bgcolor=#DDDDDD>"; + $col=0; + } else + { + echo "<tr bgcolor=#EEEEEE>"; + $col=1; + } + $prevvalue=$row[4]; + $description=$row[2]; + $lastvalue=$row[3]; + $lastclock=$row[5]; + if($lastclock==NULL) + { + $lastclock="<center>-</center>"; + } + else + { + $lastclock=date("H:i:s",$lastclock); + } + $itemid=$row[1]; + $status=$row[6]; + $dif=$lastvalue-$prevvalue; + echo "<td>$description</td>"; + echo "<td>"; + if($status==2) + { + echo "<font color=\"#FF6666\">"; + } + elseif($status!=0) + { + echo "<font color=\"#666666\">"; + } + + echo "$lastclock</td>\n"; + if($lastvalue!=NULL) + { + if(round($lastvalue)==$lastvalue) + { + echo "<td>"; printf("%.0f",$lastvalue); echo "</td>"; + } + else + { + echo "<td>"; printf("%.2f",$lastvalue); echo "</td>"; + } + } + else + { + echo "<td><center>-</center></td>"; + } + if( $dif != 0 ) + { + echo "<td>$dif</td>"; + } + else + { + echo "<td><center>-</center></td>"; + } + echo "<td><center><a href=\"history.html?action=showhistory&itemid=$itemid\">Show</a></center></td>"; + echo "</tr>"; + } + echo "</table>"; +?> + +<? + show_footer(); +?> diff --git a/frontends/php/latestalarms.html b/frontends/php/latestalarms.html new file mode 100644 index 00000000..5598e66d --- /dev/null +++ b/frontends/php/latestalarms.html @@ -0,0 +1,89 @@ +<? + include "config.inc"; + $title = "Latest alarms"; + show_header($title,10); +?> + +<? + show_table_header_begin(); + echo "HISTORY OF ALARMS"; + + show_table_v_delimiter(); +?> + +<? + if(isset($limit)) + { + echo "[<A HREF=\"latestalarms.html\">"; + echo "Show last 50</A>]"; + } + else + { + echo "[<A HREF=\"latestalarms.html?limit=200\">"; + echo "Show last 200</A>]"; + } + + show_table_header_end(); + echo "<br>"; + + show_table_header("ALARMS"); +?> + +<FONT COLOR="#000000"> +<? + if(isset($limit)) + { + $sql="select t.description,a.clock,a.istrue,t.triggerid from alarms a,triggers t where t.triggerid=a.triggerid order by clock desc limit $limit"; + } + else + { + $sql="select t.description,a.clock,a.istrue,t.triggerid from alarms a,triggers t where t.triggerid=a.triggerid order by clock desc limit $limit 50"; + } + $result=mysql_query($sql,$mysql); + + echo "<CENTER>"; + echo "<TABLE WIDTH=100% BORDER=0 BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; + echo "<TR>"; + echo "<TD width=\"20%\"><b>Time</b></TD>"; + echo "<TD><b>Description</b></TD>"; + echo "<TD width=\"10%\"><b>Status</b></TD>"; + echo "</TR>"; + while($row=mysql_fetch_row($result)) + { + $description=$row[0]; + $clock=$row[1]; + $istrue=$row[2]; + $triggerid_=$row[3]; + + if($col==1) + { + echo "<tr bgcolor=#DDDDDD>"; + $col=0; + } + else + { + echo "<tr bgcolor=#EEEEEE>"; + $col=1; + } + + echo "<TD>",date("Y.M.d H:i:s",$clock),"</TD>"; + echo "<TD><a href=\"alarms.html?triggerid=$triggerid_\">$description</a></TD>"; + if($istrue==0) + { + echo "<TD><font color=\"00AA00\">OFF</font></TD>"; + } + else + { + echo "<TD><font color=\"AA0000\">ON</font></TD>"; + } + echo "</TR>"; + } + echo "</TABLE><BR>"; +?> +</FONT> +</TR> +</TABLE></CENTER> + +<? + show_footer(); +?> diff --git a/frontends/php/media.html b/frontends/php/media.html new file mode 100644 index 00000000..96c51ea1 --- /dev/null +++ b/frontends/php/media.html @@ -0,0 +1,124 @@ +<? + include "config.inc"; + $title = "Media"; + show_header($title,0); +?> + +<? + show_table_header("MEDIA"); +?> + +<HR> + +<? + if($register=="enable") + { + activate_media( $mediaid ); + } + elseif($register=="disable") + { + disactivate_media( $mediaid ); + } + elseif($register!=$asdfasd) + { +# include "check_auth.inc"; + } + + + if($register=="add") + { + add_media( $userid, $type, $sendto); + } + if($register=="delete") + { + delete_media( $mediaid ); + } +?> + + +<FONT COLOR="#000000"> +<? + $sql="select mediaid,type,sendto,active from media where userid=$userid order by type,sendto"; + $result=mysql_query($sql,$mysql); + + echo "<CENTER>"; + echo "<TABLE BORDER=0 WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; + echo "<TR>"; + echo "<TD><FONT SIZE=+1>Type</FONT></TD>"; + echo "<TD><FONT SIZE=+1>Send to</FONT></TD>"; + echo "<TD><FONT SIZE=+1>Status</FONT></TD>"; + echo "<TD><FONT SIZE=+1>Actions</FONT></TD>"; + echo "</TR>"; + + while($row=mysql_fetch_row($result)) + { + if($col==1) + { + echo "<TR BGCOLOR=#DDDDDD>"; + $col=0; + } else + { + echo "<TR BGCOLOR=#EEEEEE>"; + $col=1; + } + $mediaid=$row[0]; + $type_=$row[1]; + echo "<TD>"; + if($type_=="EMAIL") + { + echo "E-mail"; + } + else + { + echo $type_; + } + echo "</TD>"; + echo "<TD>",$row[2],"</TD>"; + echo "<TD>"; + if($row[3]==0) + { + echo "<a href=\"media.html?register=disable&mediaid=$mediaid&userid=$userid\">Enabled</A>"; + } + else + { + echo "<a href=\"media.html?register=enable&mediaid=$mediaid&userid=$userid\">Disabled</A>"; + } + echo "</TD>"; + echo "<TD>"; + echo "<A HREF=\"media.html?register=delete&mediaid=$mediaid&userid=$userid\">Delete</A>"; + echo "</TD>"; + echo "</TR>"; + } + echo "</TABLE>"; +?> +</FONT> +</TR> +</TABLE></CENTER> + +<CENTER> +<? + echo "<br>"; + show_table2_header_begin(); + echo "New media"; + + show_table2_v_delimiter(); + echo "<form method=\"post\" action=\"media.html\">"; + echo "<input name=\"userid\" type=\"hidden\" value=$userid>"; + echo "Type"; + show_table2_h_delimiter(); + echo "<select name=\"type\" size=1>"; + echo "<OPTION VALUE=\"EMAIL\">E-mail"; + echo "</SELECT>"; + + show_table2_v_delimiter(); + echo "Send to"; + show_table2_h_delimiter(); + echo "<input name=\"sendto\" size=20>"; + + show_table2_v_delimiter2(); + echo "<input type=\"submit\" name=\"register\" value=\"add\">"; + + show_table2_header_end(); + + show_footer(); +?> diff --git a/frontends/php/queue.html b/frontends/php/queue.html new file mode 100644 index 00000000..baa374d8 --- /dev/null +++ b/frontends/php/queue.html @@ -0,0 +1,52 @@ +<? + include "config.inc"; + $title = "Information about monitoring server"; + show_header($title,10); +?> + +<? + show_table_header("QUEUE OF ITEMS TO BE UPDATED"); + + echo "<br>"; + + show_table_header("QUEUE"); +?> +<? + $result=mysql_query("select i.itemid, from_unixtime(i.nextcheck), i.description, h.host from items i,hosts h where i.status=0 and h.status=0 and i.hostid=h.hostid and i.nextcheck<UNIX_TIMESTAMP() order by i.nextcheck;",$mysql); + $i=0; + echo "<table border=0 width=100% bgcolor='#CCCCCC' cellspacing=1 cellpadding=3>"; + echo "\n"; + echo "<tr><td><b>Next time to check</b></td><td><b>Host</b></td><td><b>Description</b></td></tr>"; + echo "\n"; + while($row=mysql_fetch_row($result)) + { + $i++; + $itemid=$row[0]; + $time=$row[1]; + $description=$row[2]; + $host=$row[3]; + + if($col==1) + { + echo "<tr bgcolor=#EEEEEE>"; + $col=0; + } else + { + echo "<tr bgcolor=#DDDDDD>"; + $col=1; + } + echo "\n"; + echo "<td>$time</td><td>$host</td><td>$description</td>"; + echo "\n"; + echo "</tr>"; + echo "\n"; + } + echo "</table>"; +?> +<? + show_table_header("Total:$i"); +?> + +<? + show_footer(); +?> diff --git a/frontends/php/tr_status.html b/frontends/php/tr_status.html new file mode 100644 index 00000000..69120809 --- /dev/null +++ b/frontends/php/tr_status.html @@ -0,0 +1,199 @@ +<? + include "config.inc"; + $title = "Status of triggers"; + show_header($title,10); +?> + +<? + show_table_header_begin(); + echo "STATUS OF TRIGGERS"; + + show_table_v_delimiter(); +?> + +<A NAME="top"></A> +<? + if($noactions!='true') + { + $noactions='false'; + } +?> + +<? + if($onlytrue!='true') + { + echo "[<A HREF=\"tr_status.html?onlytrue=true&noactions=$noactions&compact=$compact\">Show only true</a>] "; + $onlytrue='false'; + } + else + { + echo "[<A HREF=\"tr_status.html?noactions=$noactions&compact=$compact\">Show all triggers</A>] "; + } + if($noactions!='true') + { + echo "[<A HREF=\"tr_status.html?onlytrue=$onlytrue&noactions=true&compact=$compact\">Hide Actions</A>] "; + } + else + { + echo "[<A HREF=\"tr_status.html?onlytrue=$onlytrue&noactions=false&compact=$compact\">Show Actions</A>] "; + } + if($compact!='true') + { + echo "[<A HREF=\"tr_status.html?onlytrue=$onlytrue&noactions=$noactions&compact=true\">Hide Details</A>] "; + } + else + { + echo "[<A HREF=\"tr_status.html?onlytrue=$onlytrue&noactions=$noactions&compact=false\">Show Details</A>] "; + } + echo "[<A HREF=\"tr_status.html?noactions=false&onlytrue=false&showselected=true\">Select</A>] "; + + + if($showselected=='true') + { + echo "<form method=\"get\" action=\"tr_status.html\">"; + echo "Where <b>Description</b> like <input name=\"only\" type=\"text\" value=\"$only\">"; + echo "<INPUT NAME=\"noactions\" TYPE=\"HIDDEN\" value=\"$noactions\"> "; + echo "<INPUT NAME=\"showselected\" TYPE=\"HIDDEN\" value=\"true\"> "; +// echo "<INPUT TYPE=\"IMAGE\" SRC=\"img/enter.gif\"VALUE=\"Show\" BORDER=0 ALT=\"Show\""; + echo "<input type=\"submit\" name=\"register\" value=\"Show\">"; + echo "</form>"; + if($only==$asdfasdf) $only="abcdef"; + $onlywheredesc=" where description like \"%$only%\" "; + } + show_table_header_end(); + + echo "<br>"; + + show_table_header("TRIGGERS"); + + echo "\n<TABLE BORDER=0 COLS=5 WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; + echo "<TR ALIGN=CENTER>"; + echo "<TD ALIGN=LEFT><B>Description"; + if($compact!='true') {echo "<BR><FONT SIZE=-1>Expression</FONT></B>";} + echo "</TD>"; + echo "<TD WIDTH=\"3%\"><B>Status</B></TD>"; + echo "<TD WIDTH=\"3%\"><B>Priority</B></TD>"; + if($noactions=='true') + echo "<TD WIDTH=\"12%\">"; + else + echo "<TD WIDTH=\"3%\">"; + + echo "<B>Last change"; + if($compact!='true') { echo "<BR><FONT SIZE=-1>(Last check)</FONT></B>";} + echo "</TD>"; + + if($noactions!='true') + { + echo "<TD WIDTH=\"8%\" NOSAVE><B>Actions</B></TD>"; + } + echo "</TR>\n"; + + if($onlytrue=='true') + { + $result=mysql_query("select triggerid,istrue,description,lastcheck,expression,priority,lastchange,comments from triggers where istrue=1 order by priority desc, description",$mysql); + } + else + { + $result=mysql_query("select triggerid,istrue,description,lastcheck,expression,priority,lastchange,comments from triggers $onlywheredesc order by description,priority",$mysql); + } + $trigcount=0; + $i=0; + while($row=mysql_fetch_row($result)) + { + $trigcount++; + if($col==1) + { + echo "\n<TR BGCOLOR=#EEEEEE>"; + $col=0; + } else + { + echo "\n<TR BGCOLOR=#DDDDDD>"; + $col=1; + } + $expression=$row[4]; + $description=$row[2]; + $triggerid=$row[0]; + $istrue=$row[1]; + $lastcheck=$row[3]; + $priority=$row[5]; + $lastchange=$row[6]; + $comments=$row[7]; + + $lastchange=date("d M H:i:s",$lastchange); + + echo "<TD>"; + + if(($comments!="")&&($comments!=" ")) + { + echo "<A HREF=\"comments.html?triggerId=$triggerid\"><b>C</b></a> "; + } + echo "$description"; + + if($compact!='true') + { + $expression=explode_exp($expression,1); + echo "<BR><FONT COLOR=\"#000000\" SIZE=-2>$expression</FONT>"; + } + echo "</TD>"; + if($istrue==0) + { echo "<TD ALIGN=CENTER><FONT COLOR=\"00AA00\">FALSE</FONT></TD>";} + elseif($istrue==2) + { echo "<TD ALIGN=CENTER><FONT COLOR=\"777777\">DISABLED</FONT></TD>"; } + elseif($istrue==3) + { echo "<TD ALIGN=CENTER><FONT COLOR=\"777777\">MODIFIED</FONT></TD>"; } + else + { echo "<TD ALIGN=CENTER><FONT COLOR=\"AA0000\">TRUE</FONT></TD>"; } + + if($priority==0) echo "<TD ALIGN=CENTER>Not clasified</TD>"; + elseif($priority==1) echo "<TD ALIGN=CENTER>Just information</TD>"; + elseif($priority==2) echo "<TD ALIGN=CENTER>Warning</TD>"; + elseif($priority==3) echo "<TD ALIGN=CENTER BGCOLOR=#DDAAAA>Average</TD>"; + elseif($priority==4) echo "<TD ALIGN=CENTER BGCOLOR=#FF8888>High</TD>"; + elseif($priority==5) echo "<TD ALIGN=CENTER BGCOLOR=RED>Disaster !!!</TD>"; + else echo "<TD ALIGN=CENTER><B>$priority</B></TD>"; + + echo "<TD ALIGN=CENTER><A HREF=\"alarms.html?triggerid=$triggerid\">$lastchange</a>"; + if($compact!='true') + { + echo "<BR><FONT SIZE=-1 COLOR=BLACK>(",date("H:i:s",$lastcheck),")</FONT>"; + } + echo "</TD>"; + + if($noactions!='true') + { + echo "<TD>"; + echo "<A HREF=\"actions.html?triggerid=$triggerid\">Show actions</A> - "; + echo "<A HREF=\"alarms.html?triggerid=$triggerid\">History</A>"; + echo "</TD>"; + } + if($istrue==0) echo "</TR>\n"; + $i++; + } + echo "</TABLE>\n"; + + show_table_header("Total:$i"); + + $result=mysql_query(" select min(lastcheck) from triggers where istrue<2;",$mysql); + $row=mysql_fetch_row($result); + $lastcheck=$row[0]; + $diff=mktime()-$lastcheck; + + $result=mysql_query("select count(*) from items i,hosts h where i.status=0 and h.status=0 and h.hostid=i.hostid and i.nextcheck<UNIX_TIMESTAMP()-60;",$mysql); + $row=mysql_fetch_row($result); + $answ=$row[0]; + if ($answ>0) + { + echo "<br>"; + show_table_header("<font color=\"AA0000\">Is zabbix_sucker running ? Check QUEUE.</font>"); + } + + if(($lastcheck!=NULL)&&($diff>180)) ### Result for Trigger checking + { + echo "<br>"; + show_table_header("<font color=\"AA0000\">Is zabbix_alarmer running ?</font>"); + } +?> + +<? + show_footer(); +?> diff --git a/frontends/php/triggers.html b/frontends/php/triggers.html new file mode 100644 index 00000000..e4760d60 --- /dev/null +++ b/frontends/php/triggers.html @@ -0,0 +1,158 @@ +<? + include "config.inc"; + $title = "Configuration of triggers"; + show_header($title,0); +?> + +<? + if($register=="changestatus") + { + update_trigger_status($triggerid,$status); + } + if($register=="update") + { + $now=mktime(); + if($disabled=='true') { $istrue=2; } + else { $istrue=3; } + + update_trigger($triggerid,$expression,$description,$priority,$istrue,$comments); + } + if($register=="add") + { + + if($disabled=='true') { $istrue=2; } + else { $istrue=0; } + + add_trigger($expression,$description,$priority,$istrue,$comments); + } + if($register=="delete") + { + delete_trigger($triggerid); + } +?> + +<? + show_table_header_begin(); + echo "CONFIGURATION OF TRIGGERS"; + show_table_v_delimiter(); +?> + +<? + $result=mysql_query("select hostid,host from hosts order by host",$mysql); + if(isset($hostid)) + { + echo "<A HREF=\"triggers.html\">all</A> "; + } + else + { + echo "<b>[<A HREF=\"triggers.html\">all</A>]</b> "; + } + while($row=mysql_fetch_row($result)) + { + $hid=$row[0]; + $host=$row[1]; + if($hid == $hostid) + { + echo "<b>[<A HREF=\"triggers.html?hostid=$hid\">$host</A>]</b> "; + } + else + { + echo "<A HREF=\"triggers.html?hostid=$hid\">$host</A> "; + } + } + + show_table_header_end(); + echo "<br>"; +?> + +<? + + if(isset($hostid)) + { + $cond=" and h.hostid=$hostid "; + } + else + { + $cond=""; + } + + $result=mysql_query("select h.hostid,h.host,t.triggerid,t.expression,t.description,t.istrue from triggers t,hosts h,items i,functions f where f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid $cond order by h.host,t.description",$mysql); + $ss="."; + while($row=mysql_fetch_row($result)) + { + $hostid_=$row[0]; + $host=$row[1]; + if($lasthost!=$host) + { + if($lasthost!="") + { + echo "</TABLE><BR>"; + } + show_table_header("<A HREF='triggers.html?hostid=$hostid_'>$host</A>"); + echo "<TABLE BORDER=0 COLS=3 WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; + echo "<TR>"; + echo "<TD><B>Description</B></TD>"; + echo "<TD><B>Expression</B></TD>"; + echo "<TD WIDTH=\"5%\"><B>Status</B></TD>"; + echo "<TD WIDTH=\"15%\" NOSAVE><B>Actions</B></TD>"; + echo "</TR>\n"; + } + $lasthost=$host; + + if($col==1) + { + echo "<TR BGCOLOR=#DDDDDD>"; + $col=0; + } else + { + echo "<TR BGCOLOR=#EEEEEE>"; + $col=1; + } + $description=$row[4]; + $triggerid_=$row[2]; + $expression=$row[3]; + $istrue=$row[5]; + echo "<TD>$description</TD>"; + $description=rawurlencode($description); + + echo "<TD>".explode_exp($expression,1)."</TD>"; + echo "<TD>"; + if($istrue == 2) + { + echo "<a href=\"triggers.html?register=changestatus&triggerid=$triggerid_&status=0&hostid=$hostid_\">Disabled"; + } + else + { + echo "<a href=\"triggers.html?register=changestatus&triggerid=$triggerid_&status=2&hostid=$hostid_\">Enabled"; + } + $expression=rawurlencode($expression); + echo "</TD>"; + echo "<TD>"; + if(isset($hostid)) + { + echo "<A HREF=\"triggers.html#form?triggerid=$triggerid_&hostid=$hostid\">Change</A> "; + } + else + { + echo "<A HREF=\"triggers.html#form?triggerid=$triggerid_\">Change</A> "; + } + echo "-<A HREF=\"actions.html?triggerid=$triggerid_&description=$description\">ShowActions</A>"; + echo "</TD>"; + echo "</TR>\n"; + } + echo "</table>\n"; +?> + +<? + $result=mysql_query("select count(*) from hosts",$mysql); + $row=mysql_fetch_row($result); + if($row[0]>0) + { + echo "<a name=\"form\"></a>"; + insert_trigger_form($triggerid); + } +?> + +<? + show_footer(); +?> diff --git a/frontends/php/users.html b/frontends/php/users.html new file mode 100644 index 00000000..5fde27b2 --- /dev/null +++ b/frontends/php/users.html @@ -0,0 +1,90 @@ +<? + include "config.inc"; + $title = "Users"; + show_header($title,0); +?> + +<? + show_table_header("CONFIGURATION OF USERS"); + echo "<br>"; +?> + +<? + if($register=="add") + { + $result=add_user($name,$surname,$alias); + } + if($register=="delete") + { + delete_user($userid); + } +?> + +<? + show_table_header("USERS"); + echo "<TABLE BORDER=0 COLS=4 WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; + echo "<TR><TD WIDTH=\"10%\"><B>Alias</B></TD>"; + echo "<TD WIDTH=\"10%\" NOSAVE><B>Name</B></TD>"; + echo "<TD WIDTH=\"10%\" NOSAVE><B>Surname</B></TD>"; + echo "<TD WIDTH=\"10%\" NOSAVE><B>Actions</B></TD>"; + echo "</TR>"; + + $result=mysql_query("select userid,alias,name,surname from users order by alias",$mysql); + echo "<CENTER>"; + while($row=mysql_fetch_row($result)) + { + if($col==1) + { + echo "<TR BGCOLOR=#EEEEEE>"; + $col=0; + } else + { + echo "<TR BGCOLOR=#DDDDDD>"; + $col=1; + } + + $alias=$row[1]; + $name=$row[2]; + $surname=$row[3]; + $userid=$row[0]; + echo "<TD>$alias</TD>"; + echo "<TD>$name</TD>"; + echo "<TD>$surname</TD>"; + echo "<TD><A HREF=\"media.html?userid=$userid\">Media</A> - <A HREF=\"users.html?register=delete&userid=$userid\">Delete</A>"; + echo "</TD>"; + echo "</TR>"; + } + echo "</TABLE>"; +?> + +<? + echo "<br>"; + + show_table2_header_begin(); + echo "New user"; + + show_table2_v_delimiter(); + echo "<form method=\"post\" action=\"users.html\">"; + echo "Alias"; + show_table2_h_delimiter(); + echo "<input name=\"alias\" size=20>"; + + show_table2_v_delimiter(); + echo "Name"; + show_table2_h_delimiter(); + echo "<input name=\"name\" size=20>"; + + show_table2_v_delimiter(); + echo "Surname"; + show_table2_h_delimiter(); + echo "<input name=\"surname\" size=20>"; + + show_table2_v_delimiter2(); + echo "<input type=\"submit\" name=\"register\" value=\"add\">"; + + show_table2_header_end(); +?> + +<? + show_footer(); +?> diff --git a/include/common.h b/include/common.h new file mode 100644 index 00000000..9c2af7fc --- /dev/null +++ b/include/common.h @@ -0,0 +1,20 @@ +#ifndef MON_COMMON_H +#define MON_COMMON_H + +#define SUCCEED 0 +#define FAIL (-1) +#define NOTSUPPORTED (-2) + +#define MAXFD 64 + + +#define SUCKER_DELAY 5 +#define ALARMER_DELAY 5 + +#define SUCKER_TIMEOUT 5 +#define AGENT_TIMEOUT 3 + +#define SENDER_TIMEOUT 3 +#define TRAPER_TIMEOUT 5 + +#endif diff --git a/include/db.c b/include/db.c new file mode 100644 index 00000000..99aa8e02 --- /dev/null +++ b/include/db.c @@ -0,0 +1,67 @@ +#include <stdlib.h> +#include <stdio.h> + +#include "db.h" +#include "common.h" +#include "debug.h" + +MYSQL mysql; + +void DBconnect( void ) +{ + if( ! mysql_connect( &mysql, NULL, DB_USER, DB_PASSWD ) ) + { + dbg_write( dbg_fatal, "Failed to connect to database: Error: %s\n",mysql_error(&mysql) ); + exit( FAIL ); + } + if( mysql_select_db( &mysql, DB_NAME ) != 0 ) + { + dbg_write( dbg_fatal, "Failed to select database: Error: %s\n",mysql_error(&mysql) ); + exit( FAIL ); + } +} + +void DBexecute( char *query ) +{ + dbg_write( dbg_proginfo, "Executing query:%s\n",query); + + if( mysql_query(&mysql,query) != 0 ) + { + dbg_write( dbg_fatal, "Query failed:%s", mysql_error(&mysql) ); + exit( FAIL ); + } +} + +DB_RESULT *DBget_result( void ) +{ + return mysql_store_result(&mysql); +} + +DB_ROW DBfetch_row(DB_RESULT *result) +{ + return mysql_fetch_row(result); +} + +int DBnum_rows(DB_RESULT *result) +{ + return mysql_num_rows(result); +} + +int DBget_function_result(float *Result,char *FunctionID) +{ + DB_RESULT *result; + DB_ROW row; + + char c[128]; + + sprintf( c, "select lastvalue from functions where functionid=%s", FunctionID ); + DBexecute(c); + + result = DBget_result(); + + row = DBfetch_row(result); + *Result=atof(row[0]); + DBfree_result(result); + + return SUCCEED; +} diff --git a/include/db.h b/include/db.h new file mode 100644 index 00000000..7321c65d --- /dev/null +++ b/include/db.h @@ -0,0 +1,81 @@ +#ifndef MON_DB_H +#define MON_DB_H + +#include "mysql.h" + +#define DB_NAME "zabbix" +#define DB_USER "root" +#define DB_PASSWD "" + +#define ITEM struct item_type +#define TRIGGER struct trigger_type +#define FUNCTION struct function_type +#define ACTION struct action_type +#define MEDIA struct media_type + +#define DB_RESULT MYSQL_RES +#define DB_ROW MYSQL_ROW +#define DBfree_result mysql_free_result + +ITEM +{ + int ItemId; + char *Description; + char *Key; + char *Host; + char *ShortName; + int Port; + int Delay; + int History; + time_t LastDelete; + time_t LastCheck; +}; + +FUNCTION +{ + int FunctionId; + int ItemId; + int TriggerId; + double LastValue; + char *Function; + int Parameter; +}; + +MEDIA +{ + int MediaId; + char *Type; + char *SendTo; + int Active; +}; + +ACTION +{ + int ActionId; + int TriggerId; + int UserId; + int Good; + int Delay; + int LastCheck; + char *Subject; + char *Message; +}; + +TRIGGER +{ + int TriggerId; + char *Expression; + char *Description; + int IsTrue; +}; + +void DBconnect( void ); + +void DBexecute( char *query ); + +DB_RESULT *DBget_result( ); +DB_ROW DBfetch_row(DB_RESULT *result); +int DBnum_rows(DB_RESULT *result); +int DBget_function_result(float *Result,char *FunctionID); + +#endif diff --git a/include/debug.c b/include/debug.c new file mode 100644 index 00000000..f2695bcc --- /dev/null +++ b/include/debug.c @@ -0,0 +1,59 @@ +#include <stdio.h> +#include <stdlib.h> + +#include <stdarg.h> + +#include "debug.h" + +FILE *dbg_fd; + +int dbg_level; + +void dbg_init( int level, char *filename ) +{ + dbg_fd = fopen( filename,"a" ); + + if( NULL == dbg_fd ) + { + fprintf( stderr, "Unable to open debug file.\n" ); + exit( 1 ); + } + + dbg_level=level; +} + +void dbg_flush(void) +{ + fflush(dbg_fd); +} + +void dbg_write( int level, const char *fmt, ... ) +{ + va_list param; + + if( level <= dbg_level) + { + if( level == dbg_fatal ) + { + fprintf( dbg_fd, "FATAL: " ); + } + else if( level == dbg_syserr ) + { + fprintf( dbg_fd, "ERROR: " ); + } + else if( level == dbg_syswarn ) + { + fprintf( dbg_fd, "WARNING: " ); + } + else + { + fprintf( dbg_fd, "INFO: " ); + } + + va_start( param, fmt ); + vfprintf( dbg_fd, fmt, param ); + fprintf( dbg_fd, "\n" ); + fflush( dbg_fd ); + va_end( param ); + } +} diff --git a/include/debug.h b/include/debug.h new file mode 100644 index 00000000..37f99b6c --- /dev/null +++ b/include/debug.h @@ -0,0 +1,16 @@ +#ifndef MON_DEBUG_H +#define MON_DEBUG_H + +enum +{ + dbg_fatal = 0, + dbg_syserr, + dbg_syswarn, + dbg_proginfo +}; + +void dbg_init( int level, char *filename ); +void dbg_flush( void ); +void dbg_write(int level, const char *fmt, ...); + +#endif diff --git a/include/expression.c b/include/expression.c new file mode 100644 index 00000000..16446ad8 --- /dev/null +++ b/include/expression.c @@ -0,0 +1,348 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> + +#include "common.h" +#include "debug.h" +#include "db.h" + +int IsFloat(char *c) +{ + int i; + + dbg_write( dbg_proginfo, "Starting IsFloat:%s", c ); + for(i=0;i<=strlen(c);i++) + { + if((c[i]=='(')||(c[i]==')')||(c[i]=='{')||(c[i]=='<')||(c[i]=='>')||(c[i]=='=')) + { + return FAIL; + } + } + return SUCCEED; +} + +void DeleteSpaces(char *c) +{ + int i,j; + + dbg_write( dbg_proginfo, "Before deleting spaces:%s", c ); + + j=0; + for(i=0;i<strlen(c);i++) + { + if( c[i] != ' ') + { + c[j]=c[i]; + j++; + } + } + c[j]=0; + + dbg_write( dbg_proginfo, "After deleting spaces:%s", c ); + +} + +int FindChar(char *str,char c) +{ + int i; + + for(i=0;i<strlen(str);i++) + { + if(str[i]==c) return i; + } + return FAIL; +} + +int EvaluateSimple (float *Result,char *exp) +{ + float value1,value2; + char first[1024],second[1024]; + int i,j,l; + + dbg_write( dbg_proginfo, "Evaluating simple expression [%s]", exp ); + + if( IsFloat(exp) == SUCCEED ) + { + *Result=atof(exp); + return SUCCEED; + } + + if( FindChar(exp,'|') != FAIL ) + { + dbg_write( dbg_proginfo, "| is found" ); + l=FindChar(exp,'|'); + strcpy( first, exp ); + first[l]=0; + j=0; + for(i=l+1;i<strlen(exp);i++) + { + second[j]=exp[i]; + j++; + } + second[j]=0; + if( EvaluateSimple(&value1,first) == FAIL ) + { + dbg_write( dbg_syserr, "Cannot evaluate expression [%s]", first ); + return FAIL; + } + if( value1 == 1) + { + *Result=value1; + return SUCCEED; + } + if( EvaluateSimple(&value2,second) == FAIL ) + { + dbg_write( dbg_syserr, "Cannot evaluate expression [%s]", second ); + return FAIL; + } + if( value2 == 1) + { + *Result=value2; + return SUCCEED; + } + *Result=0; + return SUCCEED; + } + else if( FindChar(exp,'&') != FAIL ) + { + dbg_write( dbg_proginfo, "& is found" ); + l=FindChar(exp,'&'); + strcpy( first, exp ); + first[l]=0; + j=0; + for(i=l+1;i<strlen(exp);i++) + { + second[j]=exp[i]; + j++; + } + second[j]=0; + if( EvaluateSimple(&value1,first) == FAIL ) + { + dbg_write( dbg_syserr, "Cannot evaluate expression [%s]", first ); + return FAIL; + } + if( EvaluateSimple(&value2,second) == FAIL ) + { + dbg_write( dbg_syserr, "Cannot evaluate expression [%s]", second ); + return FAIL; + } + if( (value1 == 1) && (value2 == 1) ) + { + *Result=1; + } + else + { + *Result=0; + } + return SUCCEED; + } + else if( FindChar(exp,'>') != FAIL ) + { + dbg_write( dbg_proginfo, "> is found" ); + l=FindChar(exp,'>'); + strcpy(first, exp); + first[l]=0; + j=0; + for(i=l+1;i<strlen(exp);i++) + { + second[j]=exp[i]; + j++; + } + second[j]=0; + if( EvaluateSimple(&value1,first) == FAIL ) + { + dbg_write( dbg_syserr, "Cannot evaluate expression [%s]", first ); + return FAIL; + } + if( EvaluateSimple(&value2,second) == FAIL ) + { + dbg_write( dbg_syserr, "Cannot evaluate expression [%s]", second ); + return FAIL; + } + if( value1 > value2 ) + { + *Result=1; + } + else + { + *Result=0; + } + return SUCCEED; + } + else if( FindChar(exp,'<') != FAIL ) + { + dbg_write( dbg_proginfo, "< is found" ); + l=FindChar(exp,'<'); + strcpy(first, exp); + first[l]=0; + j=0; + for(i=l+1;i<strlen(exp);i++) + { + second[j]=exp[i]; + j++; + } + second[j]=0; + if( EvaluateSimple(&value1,first) == FAIL ) + { + dbg_write( dbg_syserr, "Cannot evaluate expression [%s]", first ); + return FAIL; + } + if( EvaluateSimple(&value2,second) == FAIL ) + { + dbg_write( dbg_syserr, "Cannot evaluate expression [%s]", second ); + return FAIL; + } + if( value1 < value2 ) + { + *Result=1; + } + else + { + *Result=0; + } + return SUCCEED; + } + else + { + dbg_write( dbg_syserr, "Format error or unsupported operator. Exp: [%s]", exp ); + return FAIL; + } + return SUCCEED; +} + +int Evaluate(int *Result,char *exp) +{ + float value; + char res[1024]; + char simple[1024]; + int i,l,r; + + strcpy( res,exp ); + + while( FindChar( exp, ')' ) != FAIL ) + { + l=-1; + r=FindChar(exp,')'); + for(i=r;i>=0;i--) + { + if( exp[i] == '(' ) + { + l=i; + break; + } + } + if( r == -1 ) + { + dbg_write( dbg_syserr, "Cannot find left bracket [(]. Expression:%s", exp ); + return FAIL; + } + for(i=l+1;i<r;i++) + { + simple[i-l-1]=exp[i]; + } + simple[r-l-1]=0; + + if( EvaluateSimple( &value, simple ) != SUCCEED ) + { + dbg_write( dbg_syserr, "Unable to evaluate simple expression [%s]", simple ); + return FAIL; + } + + dbg_write( dbg_proginfo, "Expression1:%s", exp ); + + exp[l]='%'; + exp[l+1]='f'; + exp[l+2]=' '; + + dbg_write( dbg_proginfo, "Expression2:%s", exp ); + + for(i=l+3;i<=r;i++) exp[i]=' '; + + dbg_write( dbg_proginfo, "Expression3:%s", exp ); + + sprintf(res,exp,value); + strcpy(exp,res); + DeleteSpaces(res); + dbg_write( dbg_proginfo, "Expression4:%s", res ); + } + if( EvaluateSimple( &value, res ) != SUCCEED ) + { + dbg_write( dbg_syserr, "Unable to evaluate simple expression [%s]", simple ); + return FAIL; + } + dbg_write( dbg_proginfo, "Evaluate end:[%f]", value ); + *Result=value; + return SUCCEED; +} + +int SubstituteFunctions(char *exp) +{ + float value; + char functionid[1024]; + char res[1024]; + int i,l,r; + + dbg_write( dbg_proginfo, "BEGIN SubstituteFunctions" ); + + while( FindChar(exp,'{') != FAIL ) + { + l=FindChar(exp,'{'); + r=FindChar(exp,'}'); + if( r == FAIL ) + { + dbg_write( dbg_syserr, "Cannot find right bracket. Expression:%s", exp ); + return FAIL; + } + if( r < l ) + { + dbg_write( dbg_syserr, "Right bracket is before left one. Expression:%s", exp ); + return FAIL; + } + + for(i=l+1;i<r;i++) + { + functionid[i-l-1]=exp[i]; + } + functionid[r-l-1]=0; + + if( DBget_function_result( &value, functionid ) != SUCCEED ) + { + dbg_write( dbg_syserr, "Unable to get value by functionid [%s]", functionid ); + return FAIL; + } + + dbg_write( dbg_proginfo, "Expression1:%s", exp ); + + exp[l]='%'; + exp[l+1]='f'; + exp[l+2]=' '; + + dbg_write( dbg_proginfo, "Expression2:%s", exp ); + + for(i=l+3;i<=r;i++) exp[i]=' '; + + dbg_write( dbg_proginfo, "Expression3:%s", exp ); + + sprintf(res,exp,value); + strcpy(exp,res); + DeleteSpaces(exp); + dbg_write( dbg_proginfo, "Expression4:%s", exp ); + } + dbg_write( dbg_proginfo, "Expression:%s", exp ); + dbg_write( dbg_proginfo, "END1 SubstituteFunctions" ); + return SUCCEED; +} + +int EvaluateExpression (int *Result,char *expression) +{ + DeleteSpaces(expression); + if( SubstituteFunctions(expression) == SUCCEED) + { + if( Evaluate(Result, expression) == SUCCEED) + { + return SUCCEED; + } + } + return FAIL; +} diff --git a/include/expression.h b/include/expression.h new file mode 100644 index 00000000..33aaf977 --- /dev/null +++ b/include/expression.h @@ -0,0 +1,8 @@ +#ifndef MON_EXPRESSION_H +#define MON_EXPRESSION_H + +int FindChar(char *str,char c); +int SubstituteFunctions(char *exp); +int EvaluateExpression (int *Result,char *expression); + +#endif diff --git a/include/functions.c b/include/functions.c new file mode 100644 index 00000000..5428d585 --- /dev/null +++ b/include/functions.c @@ -0,0 +1,284 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <netinet/in.h> +#include <netdb.h> + +#include <signal.h> + +#include <time.h> + +#include "common.h" +#include "db.h" +#include "debug.h" + +int evaluate_LAST(float *Result,int ItemId,int Parameter) +{ + DB_RESULT *result; + DB_ROW row; + + char c[1024]; + + sprintf(c,"select lastvalue from items where itemid=%d and lastvalue is not null", ItemId ); + DBexecute(c); + + result = DBget_result(); + if(result==NULL) + { + DBfree_result(result); + return FAIL; + } + if(DBnum_rows(result)==0) + { + DBfree_result(result); + return FAIL; + } + row = DBfetch_row(result); + if( row[0] == NULL ) + { + DBfree_result(result); + return FAIL; + } + *Result=atof(row[0]); + + DBfree_result(result); + + return SUCCEED; +} + +int evaluate_MIN(float *Result,int ItemId,int Parameter) +{ + DB_RESULT *result; + DB_ROW row; + + char c[1024]; + + sprintf(c,"select min(value) from history where clock>unix_timestamp()-%d and itemid=%d",Parameter,ItemId); + DBexecute(c); + + result = DBget_result(); + if(result==NULL) + { + dbg_write( dbg_proginfo, "Result for MIN is empty" ); + DBfree_result(result); + return FAIL; + } + if(DBnum_rows(result)==0) + { + dbg_write( dbg_proginfo, "Result for MIN is empty" ); + DBfree_result(result); + return FAIL; + } + row = DBfetch_row(result); + if( row[0] == NULL ) + { + dbg_write( dbg_proginfo, "Result for MIN is empty" ); + DBfree_result(result); + return FAIL; + } + *Result=atof(row[0]); + + DBfree_result(result); + + return SUCCEED; +} + +int evaluate_MAX(float *Result,int ItemId,int Parameter) +{ + DB_RESULT *result; + DB_ROW row; + + char c[1024]; + + sprintf(c,"select max(value) from history where clock>unix_timestamp()-%d and itemid=%d",Parameter,ItemId); + DBexecute(c); + + result = DBget_result(); + if(result==NULL) + { + DBfree_result(result); + return FAIL; + } + if(DBnum_rows(result)==0) + { + DBfree_result(result); + return FAIL; + } + row = DBfetch_row(result); + if( row[0] == NULL ) + { + DBfree_result(result); + return FAIL; + } + *Result=atof(row[0]); + + DBfree_result(result); + + return SUCCEED; +} + +int evaluate_PREV(float *Result,int ItemId,int Parameter) +{ + DB_RESULT *result; + DB_ROW row; + + char c[1024]; + + sprintf(c,"select prevvalue from items where itemid=%d and prevvalue is not null", ItemId ); + DBexecute(c); + + result = DBget_result(); + if(result==NULL) + { + DBfree_result(result); + return FAIL; + } + if(DBnum_rows(result)==0) + { + DBfree_result(result); + return FAIL; + } + row = DBfetch_row(result); + if( row[0] == NULL ) + { + DBfree_result(result); + return FAIL; + } + *Result=atof(row[0]); + + DBfree_result(result); + + return SUCCEED; +} + +int evaluate_DIFF(float *Result,int ItemId,int Parameter) +{ + float prev,last; + float diff; + + if(evaluate_PREV(&prev,ItemId,Parameter) == FAIL) + { + return FAIL; + } + + if(evaluate_LAST(&last,ItemId,Parameter) == FAIL) + { + return FAIL; + } + + diff=last-prev; + + if((diff<0.000001)&&(diff>-0.000001)) + { + *Result=0; + } + else + { + *Result=1; + } + + return SUCCEED; +} + +int evaluate_NODATA(float *Result,int ItemId,int Parameter) +{ + DB_RESULT *result; + DB_ROW row; + + char c[1024]; + + sprintf(c,"select value from history where itemid=%d and clock>unix_timestamp()-%d limit 1",ItemId,Parameter); + DBexecute(c); + + result = DBget_result(); + if(result==NULL) + { + DBfree_result(result); + return FAIL; + } + if(DBnum_rows(result)==0) + { + DBfree_result(result); + return FAIL; + } + row = DBfetch_row(result); + *Result=0; + if(row == NULL) + { + *Result=1; + } + + DBfree_result(result); + + return SUCCEED; +} + +int updateFunctions( int ItemId ) +{ + FUNCTION Function; + DB_RESULT *result; + DB_ROW row; + char c[1024]; + float value; + int ret=SUCCEED; + + sprintf(c,"select function,parameter from functions where itemid=%d group by 1,2 order by 1,2",ItemId ); + DBexecute(c); + + result = DBget_result(); + if(result==NULL) + { + dbg_write( dbg_syswarn, "No functions to update."); + DBfree_result(result); + return SUCCEED; + } + + while ( (row = DBfetch_row(result)) != NULL ) + { + Function.Function=row[0]; + Function.Parameter=atoi(row[1]); + dbg_write( dbg_proginfo, "ItemId:%d Evaluating %s(%d)\n",ItemId,Function.Function,Function.Parameter); + if(strcmp(Function.Function,"last")==0) + { + ret = evaluate_LAST(&value,ItemId,Function.Parameter); + } + else if(strcmp(Function.Function,"prev")==0) + { + ret = evaluate_PREV(&value,ItemId,Function.Parameter); + } + else if(strcmp(Function.Function,"nodata")==0) + { + ret = evaluate_NODATA(&value,ItemId,Function.Parameter); + } + else if(strcmp(Function.Function,"min")==0) + { + ret = evaluate_MIN(&value,ItemId,Function.Parameter); + } + else if(strcmp(Function.Function,"max")==0) + { + ret = evaluate_MAX(&value,ItemId,Function.Parameter); + } + else if(strcmp(Function.Function,"diff")==0) + { + ret = evaluate_DIFF(&value,ItemId,Function.Parameter); + } + else + { + dbg_write( dbg_syswarn, "Unknown function:%s\n",Function.Function); + DBfree_result(result); + return FAIL; + } + dbg_write( dbg_proginfo, "Result:%f\n",value); + if (ret == SUCCEED) + { + sprintf(c,"update functions set lastvalue=%f where itemid=%d and function='%s' and parameter=%d", value, ItemId, Function.Function, Function.Parameter ); +// printf("%s\n",c); + DBexecute(c); + } + } + + DBfree_result(result); + return ret; +} diff --git a/include/functions.h b/include/functions.h new file mode 100644 index 00000000..3b7112c3 --- /dev/null +++ b/include/functions.h @@ -0,0 +1,12 @@ +#ifndef MON_FUNCTIONS_H +#define MON_FUNCTIONS_H + +int evaluate_LAST(float *Result,int ItemId,int Parameter); +int evaluate_MIN(float *Result,int ItemId,int Parameter); +int evaluate_MAX(float *Result,int ItemId,int Parameter); +int evaluate_PREV(float *Result,int ItemId,int Parameter); +int evaluate_DIFF(float *Result,int ItemId,int Parameter); +int evaluate_NODATA(float *Result,int ItemId,int Parameter); +int updateFunctions( int ItemId ); + +#endif diff --git a/include/sysinfo.h b/include/sysinfo.h new file mode 100644 index 00000000..e677e9e4 --- /dev/null +++ b/include/sysinfo.h @@ -0,0 +1,14 @@ +#ifndef MON_SYSINFO_H +#define MON_SYSINFO_H + +float INODE(const char * mountPoint); +float DF(const char * mountPoint); +float getPROC(char *file,int lineno,int fieldno); +float FREEMEM(void); +float PROCLOAD(void); +float PROCLOAD5(void); +float PROCLOAD15(void); +float SWAPFREE(void); +float EXECUTE(char *command); + +#endif diff --git a/misc/conf/zabbix_agent.conf b/misc/conf/zabbix_agent.conf new file mode 100644 index 00000000..7b9ad531 --- /dev/null +++ b/misc/conf/zabbix_agent.conf @@ -0,0 +1 @@ +127.0.0.1 diff --git a/misc/pinger/hosts b/misc/pinger/hosts new file mode 100644 index 00000000..2fbb50c4 --- /dev/null +++ b/misc/pinger/hosts @@ -0,0 +1 @@ +localhost diff --git a/misc/pinger/pinger.pl b/misc/pinger/pinger.pl new file mode 100755 index 00000000..7e7188e9 --- /dev/null +++ b/misc/pinger/pinger.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl + +$dead_hosts = `cat /home/monitor/hosts | fping -u`; + +foreach $host (split(/\n/,$dead_hosts)) +{ + $cmd="/home/monitor/monitor/src/mon_sender/mon_sender arsenal 10001 $host:alive 0"; + print $cmd,"\n"; + system( $cmd ); +} + +$alive_hosts = `cat /home/monitor/hosts | fping -a`; + +foreach $host (split(/\n/,$alive_hosts)) +{ + $cmd="/home/monitor/monitor/src/mon_sender/mon_sender arsenal 10001 $host:alive 1"; + print $cmd,"\n"; + system( $cmd ); +} + + diff --git a/src/zabbix_agent/Makefile.in b/src/zabbix_agent/Makefile.in new file mode 100644 index 00000000..852960cc --- /dev/null +++ b/src/zabbix_agent/Makefile.in @@ -0,0 +1,10 @@ +# Build rules + +all: + + @CC@ @LIBS@ @CFLAGS@ -I../../include zabbix_agent.c sysinfo.c -o zabbix_agent -Wall + strip zabbix_agent + +clean: + rm -fv *.o + diff --git a/src/zabbix_agent/configure.in b/src/zabbix_agent/configure.in new file mode 100644 index 00000000..213cb9f8 --- /dev/null +++ b/src/zabbix_agent/configure.in @@ -0,0 +1,35 @@ +dnl Process this file with autoconf to produce a configure script. +AC_INIT(zabbix_agent.c) + +dnl Checks for programs. +AC_PROG_CC + +dnl Checks for libraries. +dnl Replace `main' with a function in -lmysqlclient: + +dnl Checks for header files. +AC_HEADER_STDC + +AC_CHECK_HEADERS(stdio.h) +AC_CHECK_HEADERS(stdlib.h) +AC_CHECK_HEADERS(string.h) +AC_CHECK_HEADERS(signal.h) +AC_CHECK_HEADERS(errno.h) +AC_CHECK_HEADERS(unistd.h) +AC_CHECK_HEADERS(mntent.h) +AC_CHECK_HEADERS(fcntl.h) +AC_CHECK_HEADERS(sys/stat.h) +AC_CHECK_HEADERS(sys/socket.h) +AC_CHECK_HEADERS(sys/types.h) +AC_CHECK_HEADERS(netinet/in.h) +AC_CHECK_HEADERS(arpa/inet.h) + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_TYPE_PID_T + +dnl Checks for library functions. +AC_TYPE_SIGNAL +AC_CHECK_FUNCS(socket strtod) + +AC_CONFIG_HEADER(config.h) +AC_OUTPUT(Makefile) diff --git a/src/zabbix_agent/sysinfo.c b/src/zabbix_agent/sysinfo.c new file mode 100644 index 00000000..71ffd792 --- /dev/null +++ b/src/zabbix_agent/sysinfo.c @@ -0,0 +1,159 @@ +#include <stdio.h> +#include <mntent.h> +#include <sys/stat.h> +#include <sys/vfs.h> +#include <string.h> + +#include "../include/common.h" +#include "sysinfo.h" + +float FILESIZE(const char * filename) +{ + struct stat buf; + + if(stat(filename,&buf) == 0) + { + return buf.st_size; + } + + return FAIL; +} + +float INODE(const char * mountPoint) +{ + struct statfs s; + long blocks_used; + long blocks_percent_used; + + if ( statfs(mountPoint, &s) != 0 ) + { + return FAIL; + } + + if ( s.f_blocks > 0 ) { + blocks_used = s.f_blocks - s.f_bfree; + blocks_percent_used = (long) + (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); + +// printf( +// "%7.0f %7.0f %7.0f %5ld%% %s\n" +// ,s.f_blocks * (s.f_bsize / 1024.0) +// ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0) +// ,s.f_bavail * (s.f_bsize / 1024.0) +// ,blocks_percent_used +// ,mountPoint); + return s.f_ffree; + + } + + return FAIL; +} + +float DF(const char * mountPoint) +{ + struct statfs s; + long blocks_used; + long blocks_percent_used; + + if ( statfs(mountPoint, &s) != 0 ) + { + return FAIL; + } + + if ( s.f_blocks > 0 ) { + blocks_used = s.f_blocks - s.f_bfree; + blocks_percent_used = (long) + (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); + +// printf( +// "%7.0f %7.0f %7.0f %5ld%% %s\n" +// ,s.f_blocks * (s.f_bsize / 1024.0) +// ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0) +// ,s.f_bavail * (s.f_bsize / 1024.0) +// ,blocks_percent_used +// ,mountPoint); + return s.f_bavail * (s.f_bsize / 1024.0); + + } + + return FAIL; +} + +float getPROC(char *file,int lineno,int fieldno) +{ + FILE *f; + char *t; + char c[1024]; + float result; + int i; + + f=fopen(file,"r"); + if( f==NULL) + { + return FAIL; + } + for(i=1;i<=lineno;i++) + { + fgets(c,1024,f); + } + t=(char *)strtok(c," "); + for(i=2;i<=fieldno;i++) + { + t=(char *)strtok(NULL," "); + printf("%s\n",t); + } + fclose(f); + + sscanf(t, "%f", &result ); + + return result; +} + +float FREEMEM(void) +{ + return getPROC("/proc/meminfo",5,2); +} + +float PING(void) +{ + return 1; +} + +float PROCLOAD(void) +{ + return getPROC("/proc/loadavg",1,1); +} + +float PROCLOAD5(void) +{ + return getPROC("/proc/loadavg",1,2); +} + +float PROCLOAD15(void) +{ + return getPROC("/proc/loadavg",1,3); +} + +float SWAPFREE(void) +{ + return getPROC("/proc/meminfo",10,2); +} + +float EXECUTE(char *command) +{ + FILE *f; + float result; + char c[1024]; + + f=popen( command,"r"); + if(f==0) + { + return FAIL; + } + fgets(c,1024,f); + pclose(f); + + sscanf(c, "%f", &result ); + + return result; +} diff --git a/src/zabbix_agent/sysinfo.h b/src/zabbix_agent/sysinfo.h new file mode 100644 index 00000000..b779e33a --- /dev/null +++ b/src/zabbix_agent/sysinfo.h @@ -0,0 +1,16 @@ +#ifndef MON_SYSINFO_H +#define MON_SYSINFO_H + +float INODE(const char * mountPoint); +float FILESIZE(const char * filename); +float DF(const char * mountPoint); +float getPROC(char *file,int lineno,int fieldno); +float FREEMEM(void); +float PING(void); +float PROCLOAD(void); +float PROCLOAD5(void); +float PROCLOAD15(void); +float SWAPFREE(void); +float EXECUTE(char *command); + +#endif diff --git a/src/zabbix_agent/zabbix_agent.c b/src/zabbix_agent/zabbix_agent.c new file mode 100644 index 00000000..a65a9243 --- /dev/null +++ b/src/zabbix_agent/zabbix_agent.c @@ -0,0 +1,166 @@ +#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" + +COMMAND commands[]= + { + {"freemem" ,FREEMEM, 0}, + {"root_free" ,DF, "/"}, + {"opt_free" ,DF, "/opt"}, + {"tmp_free" ,DF, "/tmp"}, + {"usr_free" ,DF, "/usr"}, + {"home_free" ,DF, "/home"}, + {"root_inode" ,INODE, "/"}, + {"opt_inode" ,INODE, "/opt"}, + {"tmp_inode" ,INODE, "/tmp"}, + {"usr_inode" ,INODE, "/usr"}, + {"home_inode" ,INODE, "/home"}, + {"md5sum_inetd" ,EXECUTE, "md5sum /etc/inetd.conf |cut -b0-32|tr 'abcdef' 'ABCDEF'|bc|cut -b0-8"}, + {"md5sum_kernel",EXECUTE, "md5sum /vmlinuz |cut -b0-32|tr 'abcdef' 'ABCDEF'|bc|cut -b0-8"}, + {"md5sum_passwd",EXECUTE, "md5sum /etc/passwd |cut -b0-32|tr 'abcdef' 'ABCDEF'|bc|cut -b0-8"}, + {"mon_history" ,EXECUTE, "echo 'select count(*) from history'|mysql monitor -uroot|tail -1"}, + {"mon_sucker_load" ,EXECUTE, "ps aux|grep mon_sucker|grep -v grep|cut -b16-20"}, + {"mon_alarmer_load" ,EXECUTE, "ps aux|grep mon_alarmer|grep -v grep|cut -b16-20"}, + {"proccount" ,EXECUTE, "cat /proc/loadavg|cut -f2 -d'/'|cut -f1 -d' '"}, + {"ping" ,PING, 0}, + {"procidle" ,EXECUTE, "vmstat 1 1|tail -1|awk {'print $16'}"}, + {"procload" ,PROCLOAD, 0}, + {"procload5" ,PROCLOAD5, 0}, + {"procload15" ,PROCLOAD15, 0}, + {"procrunning" ,EXECUTE, "cat /proc/loadavg|cut -f1 -d'/'|cut -f4 -d' '"}, + {"procsystem" ,EXECUTE, "vmstat 1 1|tail -1|awk {'print $15'}"}, + {"procuser" ,EXECUTE, "vmstat 1 1|tail -1|awk {'print $14'}"}, + {"swapfree" ,SWAPFREE, 0}, + {"syslog_size" ,FILESIZE, "/var/log/syslog"}, + {"tcp_count" ,EXECUTE, "netstat -tn|grep EST|wc -l"}, + {"users" ,EXECUTE, "who|wc -l"}, + {0 ,0} + }; + +void signal_handler( int sig ) +{ + if( SIGALRM == sig ) + { + signal( SIGALRM, signal_handler ); + +// fprintf(stderr,"Timeout while executing operation."); + } + + if( SIGQUIT == sig || SIGINT == sig || SIGTERM == sig ) + { +// fprintf(stderr,"\nGot QUIT or INT or TERM signal. Exiting..." ); + } + exit( FAIL ); +} + +int check_security(void) +{ + char *sname; + char *config; + struct sockaddr_in name; + int i; + int file; + + config=(char *)malloc(16); + + file=open("/etc/zabbix/zabbix_agent.conf",O_RDONLY); + if(file == -1) + { +// printf("Open failed"); + return FAIL; + } + i=read(file, config, 16); + config[i-1]=0; + close(file); + + i=sizeof(struct sockaddr_in); + + if(getpeername(0, &name, &i) == 0) + { +// printf("%d\n",name.sin_port); + sname=inet_ntoa(name.sin_addr); +// printf("From:=%s=\n",sname); + if(strcmp(sname,config)!=0) + { + return FAIL; + } + } + return SUCCEED; +} + +int main() +{ + char *s,*p; + float result; + int i; + float (*function)(); + char *parameter = NULL; + + if(check_security() == FAIL) + { + exit(FAIL); + } + + signal( SIGINT, signal_handler ); + signal( SIGQUIT, signal_handler ); + signal( SIGTERM, signal_handler ); + signal( SIGALRM, signal_handler ); + + s=(char *) malloc( 1024 ); + + fgets(s,1024,stdin); + + for( p=s+strlen(s)-1; p>s && ( *p=='\r' || *p =='\n' || *p == ' ' ); --p ); + p[1]=0; +// printf("=%s=\n",s); +// s[strlen(s)-2]=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 ) + { + alarm(AGENT_TIMEOUT); + result=function(parameter); + alarm(0); + printf("%f",result); + } + else + { + printf("%d\n",NOTSUPPORTED); + } + fflush(stdout); + + free(s); + return SUCCEED; +} diff --git a/src/zabbix_agent/zabbix_agent.h b/src/zabbix_agent/zabbix_agent.h new file mode 100644 index 00000000..9f92f835 --- /dev/null +++ b/src/zabbix_agent/zabbix_agent.h @@ -0,0 +1,12 @@ +#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_alarmer/Makefile.in b/src/zabbix_alarmer/Makefile.in new file mode 100644 index 00000000..110effa5 --- /dev/null +++ b/src/zabbix_alarmer/Makefile.in @@ -0,0 +1,10 @@ +# Build rules + +all: + + @CC@ @LIBS@ @CFLAGS@ -ggdb -I /usr/include/mysql -I../../include -L/usr/lib/mysql zabbix_alarmer.c ../../include/expression.c ../../include/debug.c ../../include/db.c -o zabbix_alarmer -Wall + strip zabbix_alarmer + +clean: + rm -fv *.o + diff --git a/src/zabbix_alarmer/configure.in b/src/zabbix_alarmer/configure.in new file mode 100644 index 00000000..8474b1fe --- /dev/null +++ b/src/zabbix_alarmer/configure.in @@ -0,0 +1,31 @@ +dnl Process this file with autoconf to produce a configure script. +AC_INIT(zabbix_alarmer.c) + +dnl Checks for programs. +AC_PROG_CC + +dnl Checks for libraries. +dnl Replace `main' with a function in -lmysqlclient: +AC_CHECK_LIB(mysqlclient, main) + +dnl Checks for header files. +AC_HEADER_STDC + +AC_CHECK_HEADERS(stdio.h) +AC_CHECK_HEADERS(stdlib.h) +AC_CHECK_HEADERS(unistd.h) +AC_CHECK_HEADERS(netdb.h) +AC_CHECK_HEADERS(signal.h) +AC_CHECK_HEADERS(time.h) +AC_CHECK_HEADERS(sys/stat.h) +AC_CHECK_HEADERS(netinet/in.h) + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_TYPE_PID_T + +dnl Checks for library functions. +AC_TYPE_SIGNAL +AC_CHECK_FUNCS(socket strtod) + +AC_CONFIG_HEADER(config.h) +AC_OUTPUT(Makefile) diff --git a/src/zabbix_alarmer/zabbix_alarmer.c b/src/zabbix_alarmer/zabbix_alarmer.c new file mode 100644 index 00000000..3ca4715c --- /dev/null +++ b/src/zabbix_alarmer/zabbix_alarmer.c @@ -0,0 +1,320 @@ +#include <stdio.h> +#include <stdlib.h> + +#include <unistd.h> + +#include <sys/stat.h> +#include <netinet/in.h> +#include <netdb.h> +#include <signal.h> +#include <time.h> + +#include "common.h" +#include "debug.h" +#include "expression.h" +#include "db.h" + +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); + } +} + +void SendMail(char *smtp_server,char *smtp_helo,char *smtp_email,char *MailTo,char *MailSubject,char *MailBody) +{ + int s; + int i,e; + char *c; + struct hostent *hp; +// struct servent *sp; + + struct sockaddr_in myaddr_in; + struct sockaddr_in servaddr_in; + + dbg_write( dbg_proginfo, "SENDING MAIL"); + + servaddr_in.sin_family=AF_INET; + hp=gethostbyname(smtp_server); + if(hp==NULL) + { + perror("Cannot get IP for mailserver."); + } + + servaddr_in.sin_addr.s_addr=((struct in_addr *)(hp->h_addr))->s_addr; + + servaddr_in.sin_port=htons(25); + + s=socket(AF_INET,SOCK_STREAM,0); + if(s==0) perror("socket"); + + myaddr_in.sin_family = AF_INET; + myaddr_in.sin_port=0; + myaddr_in.sin_addr.s_addr=INADDR_ANY; + + if(connect(s,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in))==-1) perror("Connect"); + + c=(char *)malloc(1024); + if(c==NULL) perror("Cannot allocate memory."); + sprintf(c,"HELO %s\n",smtp_helo); + e=sendto(s,c,strlen(c),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); + if(e==-1) perror("Error sending HELO to mailserver."); + + i=sizeof(struct sockaddr_in); + i=recvfrom(s,c,1023,0,(struct sockaddr *)&servaddr_in,&i); + if(i==-1) perror("Error receiving data answer on HELO reqest."); + + sprintf(c,"MAIL FROM: %s\n",smtp_email); + e=sendto(s,c,strlen(c),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); + if(e==-1) perror("Error sending MAIL FROM to mailserver."); + i=sizeof(struct sockaddr_in); + i=recvfrom(s,c,1023,0,(struct sockaddr *)&servaddr_in,&i); + if(i==-1) perror("Error receiving answer on MAIL FROM request."); + + sprintf(c,"RCPT TO: <%s>\n",MailTo); + e=sendto(s,c,strlen(c),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); + if(e==-1) perror("Error sending RCPT TO to mailserver."); + i=sizeof(struct sockaddr_in); + i=recvfrom(s,c,1023,0,(struct sockaddr *)&servaddr_in,&i); + if(i==-1) perror("Error receiving answer on RCPT TO request."); + + sprintf(c,"DATA\nSubject: %s\n",MailSubject); + e=sendto(s,c,strlen(c),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); + if(e==-1) perror("Error sending DATA to mailserver."); + i=sizeof(struct sockaddr_in); + i=recvfrom(s,c,1023,0,(struct sockaddr *)&servaddr_in,&i); + if(i==-1) perror("Error receiving answer on DATA request."); + sprintf(c,"%s\n",MailBody); + e=sendto(s,c,strlen(c),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); + if(e==-1) perror("Error sending MailBody to mailserver."); + sprintf(c,".\n"); + e=sendto(s,c,strlen(c),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); + if(e==-1) perror("Error sending . to mailserver."); + i=sizeof(struct sockaddr_in); + i=recvfrom(s,c,1023,0,(struct sockaddr *)&servaddr_in,&i); + + sprintf(c,"\n"); + e=sendto(s,c,strlen(c),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); + if(e==-1) perror("Error sending \\n to mailserver."); + i=sizeof(struct sockaddr_in); + i=recvfrom(s,c,1023,0,(struct sockaddr *)&servaddr_in,&i); + if(i==-1) perror("Error receiving answer on \\n request."); + + sprintf(c,"QUIT\n"); + e=sendto(s,c,strlen(c),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); + if(e==-1) perror("Error sending QUIT to mailserver."); + + close(s); + free(c); +} + +void SendToUser(int UserId,char *smtp_server,char *smtp_helo,char *smtp_email,char *Subject,char *Message) +{ + MEDIA Media; + char c[1024]; + DB_RESULT *result; + + DB_ROW row; + + sprintf(c,"select type,sendto,active from media where userid=%d",UserId); + DBexecute(c); + + result = DBget_result(); + + while ( (row = DBfetch_row(result)) ) + { + Media.Active=atoi(row[2]); + dbg_write( dbg_proginfo, "ACTIVE=%d or %s\n", Media.Active, row[2] ); + if(Media.Active!=1) // If media is enabled (active) + { + Media.Type=row[0]; + Media.SendTo=row[1]; + + if(strcmp(Media.Type,"EMAIL")==0) + { + dbg_write( dbg_proginfo, "Email sending to %s %s Subject:%s Message:%s to %d\n", Media.Type, Media.SendTo, Subject, Message, UserId ); + SendMail(smtp_server,smtp_helo,smtp_email,Media.SendTo,Subject,Message); + sprintf(c,"insert into alerts (alertid,clock,type,sendto,subject,message) values (NULL,unix_timestamp(),'%s','%s','%s','%s');",Media.Type,Media.SendTo,Subject,Message); + DBexecute(c); + } + else + { + dbg_write( dbg_syserr, "Type %s is not supported yet", Media.Type ); + } + } + } + DBfree_result(result); +} + +void ApplyActions(int TriggerId,int Good) +{ + DB_RESULT *result; + + DB_ROW row; + + ACTION Action; + + char c[1024]; + + char smtp_server[256], + smtp_helo[256], + smtp_email[256]; + + dbg_write( dbg_syswarn, "Applying actions"); + + /* Get smtp_server and smtp_helo from config */ + sprintf(c,"select smtp_server,smtp_helo,smtp_email from config"); + DBexecute(c); + result = DBget_result(); + + row = DBfetch_row(result); + + strcpy(smtp_server,row[0]); + strcpy(smtp_helo,row[1]); + strcpy(smtp_email,row[2]); + + DBfree_result(result); + + sprintf(c,"select actionid,userid,delay,subject,message from actions where triggerid=%d and good=%d and nextcheck<=unix_timestamp()",TriggerId,Good); + DBexecute(c); + + result = DBget_result(); + + while ( (row = DBfetch_row(result)) ) + { + dbg_write( dbg_proginfo, "Fetched:%s %s %s %s %s\n",row[0],row[1],row[2],row[3],row[4]); + + Action.ActionId=atoi(row[0]); + Action.UserId=atoi(row[1]); + Action.Delay=atoi(row[2]); + Action.Subject=row[3]; + Action.Message=row[4]; + + SubstituteFunctions(&*Action.Message); + SubstituteFunctions(&*Action.Subject); + + SendToUser(Action.UserId,smtp_server,smtp_helo,smtp_email,Action.Subject,Action.Message); + sprintf(c,"update actions set nextcheck=unix_timestamp()+%d where actionid=%d",Action.Delay,Action.ActionId); + DBexecute(c); + } + dbg_write( dbg_proginfo, "Actions applied for trigger %d %d\n", TriggerId, Good ); + DBfree_result(result); +} + +void update_triggers(void) +{ + char c[1024]; + char exp[8192]; + int b; + TRIGGER Trigger; + DB_RESULT *result; + DB_ROW row; + + sprintf(c,"select triggerid,expression,istrue from triggers where istrue!=2 order by triggerid"); + + DBexecute(c); + + result = DBget_result(); + + if(DBnum_rows(result)==0) + { + dbg_write( dbg_proginfo, "Zero, so returning..." ); + return; + } + while ( (row = DBfetch_row(result)) ) + { + dbg_write( dbg_proginfo, "Fetched: TrId[%s] Exp[%s] IsTrue[%s]\n", row[0], row[1], row[2] ); + Trigger.TriggerId=atoi(row[0]); + Trigger.Expression=row[1]; + Trigger.IsTrue=atoi(row[2]); + strcpy(exp, Trigger.Expression); + if( EvaluateExpression(&b, exp) != 0 ) + { + dbg_write( dbg_syswarn, "Expression %s - SUX.",Trigger.Expression); + continue; + } + + sprintf(c,"update triggers set lastcheck=unix_timestamp() where triggerid=%d",Trigger.TriggerId); + + DBexecute(c); + + + if((b==1)&&(Trigger.IsTrue!=1)) + { + sprintf(c,"update triggers set IsTrue=1, lastchange=unix_timestamp() where triggerid=%d",Trigger.TriggerId); + DBexecute(c); + + sprintf(c,"insert into alarms(triggerid,clock,istrue) values(%d,unix_timestamp(),1)",Trigger.TriggerId); + DBexecute(c); + + ApplyActions(Trigger.TriggerId,1); + + sprintf(c,"update actions set nextcheck=0 where triggerid=%d and good=0",Trigger.TriggerId); + DBexecute(c); + } + + if((b==0)&&(Trigger.IsTrue!=0)) + { + sprintf(c,"update triggers set IsTrue=0, lastchange=unix_timestamp() where triggerid=%d",Trigger.TriggerId); + DBexecute(c); + + sprintf(c,"insert into alarms(triggerid,clock,istrue) values(%d,unix_timestamp(),0)",Trigger.TriggerId); + DBexecute(c); + + ApplyActions(Trigger.TriggerId,0); + + sprintf(c,"update actions set nextcheck=0 where triggerid=%d and good=1",Trigger.TriggerId); + DBexecute(c); + } + } + DBfree_result(result); +} + +int main() +{ + time_t now,diff; + + daemon_init(); + + dbg_init( dbg_syswarn, "/var/tmp/zabbix_alarmer.log" ); +// dbg_init( dbg_proginfo, "/var/tmp/zabbix_alarmer.log" ); + + DBconnect(); + + for(;;) + { + now=time(NULL); + update_triggers(); + diff=time(NULL)-now; + dbg_write( dbg_proginfo, "Spent %d seconds while updating triggers", diff ); + if( diff<ALARMER_DELAY ) + { + if( diff>=0 ) + { + dbg_write( dbg_proginfo, "Sleeping for %d seconds", ALARMER_DELAY-diff ); + sleep(ALARMER_DELAY-diff); + } + } + } +} diff --git a/src/zabbix_sender/Makefile.in b/src/zabbix_sender/Makefile.in new file mode 100644 index 00000000..8c8bc5b5 --- /dev/null +++ b/src/zabbix_sender/Makefile.in @@ -0,0 +1,10 @@ +# Build rules + +all: + + @CC@ @LIBS@ @CFLAGS@ -ggdb -I /usr/include/mysql -I../../include -L/usr/lib/mysql zabbix_sender.c ../../include/debug.c ../../include/db.c -o zabbix_sender -Wall + strip zabbix_sender + +clean: + rm -fv *.o + diff --git a/src/zabbix_sender/configure.in b/src/zabbix_sender/configure.in new file mode 100644 index 00000000..3df8bb1f --- /dev/null +++ b/src/zabbix_sender/configure.in @@ -0,0 +1,32 @@ +dnl Process this file with autoconf to produce a configure script. +AC_INIT(zabbix_sender.c) + +dnl Checks for programs. +AC_PROG_CC + +dnl Checks for libraries. +dnl Replace `main' with a function in -lmysqlclient: +AC_CHECK_LIB(mysqlclient, main) + +dnl Checks for header files. +AC_HEADER_STDC + +AC_CHECK_HEADERS(stdio.h) +AC_CHECK_HEADERS(stdlib.h) +AC_CHECK_HEADERS(unistd.h) +AC_CHECK_HEADERS(netdb.h) +AC_CHECK_HEADERS(signal.h) +AC_CHECK_HEADERS(time.h) +AC_CHECK_HEADERS(sys/types.h) +AC_CHECK_HEADERS(sys/stat.h) +AC_CHECK_HEADERS(netinet/in.h) + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_TYPE_PID_T + +dnl Checks for library functions. +AC_TYPE_SIGNAL +AC_CHECK_FUNCS(socket strtod) + +AC_CONFIG_HEADER(config.h) +AC_OUTPUT(Makefile) diff --git a/src/zabbix_sender/zabbix_sender.c b/src/zabbix_sender/zabbix_sender.c new file mode 100644 index 00000000..202ae6a5 --- /dev/null +++ b/src/zabbix_sender/zabbix_sender.c @@ -0,0 +1,129 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <netinet/in.h> +#include <netdb.h> + +#include <signal.h> + +#include <time.h> + +#include "common.h" + +void signal_handler( int sig ) +{ + if( SIGALRM == sig ) + { + signal( SIGALRM, signal_handler ); + fprintf(stderr,"Timeout while executing operation.\n"); + } + + if( SIGQUIT == sig || SIGINT == sig || SIGTERM == sig ) + { +// fprintf(stderr,"\nGot QUIT or INT or TERM signal. Exiting..." ); + } + exit( FAIL ); +} + +int send_value(char *monserver,int port,char *shortname,char *value) +{ + int i,s; + char tosend[1024]; + char result[1024]; + struct hostent *hp; + + struct sockaddr_in myaddr_in; + struct sockaddr_in servaddr_in; + + servaddr_in.sin_family=AF_INET; + hp=gethostbyname(monserver); + + if(hp==NULL) + { + return FAIL; + } + + servaddr_in.sin_addr.s_addr=((struct in_addr *)(hp->h_addr))->s_addr; + + servaddr_in.sin_port=htons(port); + + s=socket(AF_INET,SOCK_STREAM,0); + if(s==0) + { + return FAIL; + } + + myaddr_in.sin_family = AF_INET; + myaddr_in.sin_port=0; + myaddr_in.sin_addr.s_addr=INADDR_ANY; + + if( connect(s,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)) == -1 ) + { + close(s); + return FAIL; + } + + sprintf(tosend,"%s:%s\n",shortname,value); + + if( sendto(s,tosend,strlen(tosend),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)) == -1 ) + { + perror("sendto"); + close(s); + return FAIL; + } + i=sizeof(struct sockaddr_in); + i=recvfrom(s,result,1023,0,(struct sockaddr *)&servaddr_in,&i); + if(s==-1) + { + perror("recfrom"); + close(s); + return FAIL; + } + + result[i-1]=0; + + if(strcmp(result,"OK") == 0) + { + printf("OK\n"); + } + + if( close(s)!=0 ) + { + perror("close"); + + } + + return SUCCEED; +} + +int main(int argc, char **argv) +{ + int port; + int ret=SUCCEED; + + signal( SIGINT, signal_handler ); + signal( SIGQUIT, signal_handler ); + signal( SIGTERM, signal_handler ); + signal( SIGALRM, signal_handler ); + + if(argc!=5) + { + printf("Usage: zabbix_sender <monitoring server> <port> <server:key> <value>\n"); + ret=FAIL; + } + + if(FAIL != ret) + { + port=atoi(argv[2]); + + alarm(SENDER_TIMEOUT); + + ret=send_value(argv[1],port,argv[3],argv[4]); + + alarm(0); + } + + return ret; +} diff --git a/src/zabbix_sucker/Makefile.in b/src/zabbix_sucker/Makefile.in new file mode 100644 index 00000000..13657246 --- /dev/null +++ b/src/zabbix_sucker/Makefile.in @@ -0,0 +1,10 @@ +# Build rules + +all: + + @CC@ @LIBS@ @CFLAGS@ -ggdb -I /usr/include/mysql -I../../include -L/usr/lib/mysql zabbix_sucker.c ../../include/debug.c ../../include/db.c ../../include/functions.c -o zabbix_sucker -Wall + strip zabbix_sucker + +clean: + rm -fv *.o + diff --git a/src/zabbix_sucker/configure.in b/src/zabbix_sucker/configure.in new file mode 100644 index 00000000..5e0f6e49 --- /dev/null +++ b/src/zabbix_sucker/configure.in @@ -0,0 +1,32 @@ +dnl Process this file with autoconf to produce a configure script. +AC_INIT(zabbix_sucker.c) + +dnl Checks for programs. +AC_PROG_CC + +dnl Checks for libraries. +dnl Replace `main' with a function in -lmysqlclient: +AC_CHECK_LIB(mysqlclient, main) + +dnl Checks for header files. +AC_HEADER_STDC + +AC_CHECK_HEADERS(stdio.h) +AC_CHECK_HEADERS(stdlib.h) +AC_CHECK_HEADERS(unistd.h) +AC_CHECK_HEADERS(netdb.h) +AC_CHECK_HEADERS(signal.h) +AC_CHECK_HEADERS(time.h) +AC_CHECK_HEADERS(sys/types.h) +AC_CHECK_HEADERS(sys/stat.h) +AC_CHECK_HEADERS(netinet/in.h) + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_TYPE_PID_T + +dnl Checks for library functions. +AC_TYPE_SIGNAL +AC_CHECK_FUNCS(socket strtod) + +AC_CONFIG_HEADER(config.h) +AC_OUTPUT(Makefile) diff --git a/src/zabbix_sucker/zabbix_sucker.c b/src/zabbix_sucker/zabbix_sucker.c new file mode 100644 index 00000000..b33c67bc --- /dev/null +++ b/src/zabbix_sucker/zabbix_sucker.c @@ -0,0 +1,334 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <netinet/in.h> +#include <netdb.h> + +#include <signal.h> + +#include <time.h> + +#include "common.h" +#include "db.h" +#include "debug.h" +#include "functions.h" + +void signal_handler( int sig ) +{ + if( SIGALRM == sig ) + { + signal( SIGALRM, signal_handler ); + + dbg_write( dbg_syswarn, "Timeout while executing operation." ); + } + + if( SIGQUIT == sig || SIGINT == sig || SIGTERM == sig ) + { + dbg_write( dbg_fatal, "\nGot QUIT or INT or TERM signal. Exiting..." ); + exit( FAIL ); + } + + return; +} + +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 get_value(double *Result,char *Key,char *Host,int Port) +{ + int s; + int i; + char c[1024]; + char *e; + void *sigfunc; + + struct hostent *hp; + + struct sockaddr_in myaddr_in; + struct sockaddr_in servaddr_in; + + dbg_write( dbg_proginfo, "%10s%25s\t", Host, Key ); + + servaddr_in.sin_family=AF_INET; + hp=gethostbyname(Host); + + if(hp==NULL) + { + dbg_write( dbg_syswarn, "Problem with gethostbyname" ); + return FAIL; + } + + servaddr_in.sin_addr.s_addr=((struct in_addr *)(hp->h_addr))->s_addr; + + servaddr_in.sin_port=htons(Port); + + s=socket(AF_INET,SOCK_STREAM,0); + if(s==0) + { + dbg_write( dbg_syswarn, "Problem with socket" ); + return FAIL; + } + + myaddr_in.sin_family = AF_INET; + myaddr_in.sin_port=0; + myaddr_in.sin_addr.s_addr=INADDR_ANY; + + sigfunc = signal( SIGALRM, signal_handler ); + + alarm(SUCKER_TIMEOUT); + + if( connect(s,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)) == -1 ) + { + dbg_write( dbg_syswarn, "Problem with connect" ); + close(s); + return FAIL; + } + alarm(0); + signal( SIGALRM, sigfunc ); + + sprintf(c,"%s\n",Key); + if( sendto(s,c,strlen(c),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)) == -1 ) + { + dbg_write( dbg_syswarn, "Problem with sendto" ); + close(s); + return FAIL; + } + i=sizeof(struct sockaddr_in); + + sigfunc = signal( SIGALRM, signal_handler ); + alarm(SUCKER_TIMEOUT); + + i=recvfrom(s,c,1023,0,(struct sockaddr *)&servaddr_in,&i); + if(s==-1) + { + dbg_write( dbg_syswarn, "Problem with recvfrom" ); + close(s); + return FAIL; + } + alarm(0); + signal( SIGALRM, sigfunc ); + + if( close(s)!=0 ) + { + dbg_write( dbg_syswarn, "Problem with close" ); + + } + c[i-1]=0; + + dbg_write( dbg_proginfo, "Got string:%10s", c ); + *Result=strtod(c,&e); + + if( (*Result==0) && (c==e) ) + { + return FAIL; + } + if( *Result<0 ) + { + if( *Result == NOTSUPPORTED) + { + return SUCCEED; + } + else + { + return FAIL; + } + } + return SUCCEED; +} + +int get_minnextcheck(void) +{ + char c[1024]; + + DB_RESULT *result; + DB_ROW row; + + int res; + + sprintf(c,"select min(nextcheck) from items i,hosts h where i.status=0 and h.status=0 and h.hostid=i.hostid"); + DBexecute(c); + + result = DBget_result(); + if(result==NULL) + { + dbg_write( dbg_proginfo, "No items to update for minnextcheck."); + DBfree_result(result); + return FAIL; + } + if(DBnum_rows(result)==0) + { + dbg_write( dbg_proginfo, "No items to update for minnextcheck."); + DBfree_result(result); + return FAIL; + } + + row = DBfetch_row(result); + if( row[0] == NULL ) + { + DBfree_result(result); + return FAIL; + } + + res=atoi(row[0]); + DBfree_result(result); + + return res; +} + +int get_values(void) +{ + double Value; + char c[1024]; + ITEM Item; + + DB_RESULT *result; + DB_ROW row; + + sprintf(c,"select i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.history,i.lastdelete from items i,hosts h where i.nextcheck<=unix_timestamp() and i.status=0 and h.status=0 and h.hostid=i.hostid order by i.nextcheck"); + DBexecute(c); + + result = DBget_result(); + if(result==NULL) + { + dbg_write( dbg_syswarn, "No items to update."); + DBfree_result(result); + return SUCCEED; + } + while ( (row = DBfetch_row(result)) != NULL ) + { + Item.ItemId=atoi(row[0]); + Item.Key=row[1]; + Item.Host=row[2]; + Item.Port=atoi(row[3]); + Item.Delay=atoi(row[4]); + Item.Description=row[5]; + Item.History=atoi(row[6]); + Item.LastDelete=atoi(row[7]); + Item.ShortName=row[8]; + + if( get_value(&Value,Item.Key,Item.Host,Item.Port) == SUCCEED ) + { + if( Value == NOTSUPPORTED) + { + sprintf(c,"update items set status=3 where itemid=%d",Item.ItemId); + DBexecute(c); + } + else + { + sprintf(c,"insert into history (itemid,clock,value) values (%d,unix_timestamp(),%g)",Item.ItemId,Value); + DBexecute(c); + + sprintf(c,"update items set NextCheck=unix_timestamp()+%d,PrevValue=LastValue,LastValue=%f,LastClock=unix_timestamp() where ItemId=%d",Item.Delay,Value,Item.ItemId); + DBexecute(c); + + if( updateFunctions( Item.ItemId ) == FAIL) + { + dbg_write( dbg_syswarn, "Updating simple functions failed" ); + } + } + } + else + { + dbg_write( dbg_syswarn, "Wrong value from host [HOST:%s KEY:%s VALUE:%f]", Item.Host, Item.Key, Value ); + dbg_write( dbg_syswarn, "The value is not stored in database."); + } + + if(Item.LastDelete+3600<time(NULL)) + { + sprintf (c,"delete from history where ItemId=%d and Clock<unix_timestamp()-%d",Item.ItemId,Item.History); + DBexecute(c); + + sprintf(c,"update items set LastDelete=unix_timestamp() where ItemId=%d",Item.ItemId); + DBexecute(c); + } + } + DBfree_result(result); + return SUCCEED; +} + +int main_loop() +{ + time_t now; + + int nextcheck,sleeptime; + + for(;;) + { + now=time(NULL); + get_values(); + + dbg_write( dbg_proginfo, "Spent %d seconds while updating values", time(NULL)-now ); + + nextcheck=get_minnextcheck(); + dbg_write( dbg_proginfo, "Nextcheck:%d Time:%d", nextcheck,time(NULL) ); + + if( FAIL == nextcheck) + { + sleeptime=SUCKER_DELAY; + } + else + { + sleeptime=nextcheck-time(NULL); + if(sleeptime<0) + { + sleeptime=0; + } + } + if(sleeptime>0) + { + dbg_write( dbg_proginfo, "Sleeping for %d seconds", sleeptime ); + dbg_flush(); + sleep( sleeptime ); + } + else + { + dbg_write( dbg_proginfo, "No sleeping" ); + dbg_flush(); + } + } +} + +int main(int argc, char **argv) +{ + daemon_init(); + + signal( SIGINT, signal_handler ); + signal( SIGQUIT, signal_handler ); + signal( SIGTERM, signal_handler ); + + dbg_init( dbg_syswarn, "/var/log/zabbix_sucker.log" ); +// dbg_init( dbg_proginfo, "/var/log/zabbi_sucker.log" ); + + DBconnect(); + + main_loop(); + + return SUCCEED; +} diff --git a/src/zabbix_traper/Makefile.in b/src/zabbix_traper/Makefile.in new file mode 100644 index 00000000..0d811f82 --- /dev/null +++ b/src/zabbix_traper/Makefile.in @@ -0,0 +1,10 @@ +# Build rules + +all: + + @CC@ @LIBS@ @CFLAGS@ -ggdb -I /usr/include/mysql -I../../include -L/usr/lib/mysql zabbix_traper.c ../../include/debug.c ../../include/db.c ../../include/functions.c -o zabbix_traper -Wall + strip zabbix_traper + +clean: + rm -fv *.o + diff --git a/src/zabbix_traper/configure.in b/src/zabbix_traper/configure.in new file mode 100644 index 00000000..cb714649 --- /dev/null +++ b/src/zabbix_traper/configure.in @@ -0,0 +1,32 @@ +dnl Process this file with autoconf to produce a configure script. +AC_INIT(zabbix_traper.c) + +dnl Checks for programs. +AC_PROG_CC + +dnl Checks for libraries. +dnl Replace `main' with a function in -lmysqlclient: +AC_CHECK_LIB(mysqlclient, main) + +dnl Checks for header files. +AC_HEADER_STDC + +AC_CHECK_HEADERS(stdio.h) +AC_CHECK_HEADERS(stdlib.h) +AC_CHECK_HEADERS(unistd.h) +AC_CHECK_HEADERS(netdb.h) +AC_CHECK_HEADERS(signal.h) +AC_CHECK_HEADERS(time.h) +AC_CHECK_HEADERS(sys/types.h) +AC_CHECK_HEADERS(sys/stat.h) +AC_CHECK_HEADERS(netinet/in.h) + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_TYPE_PID_T + +dnl Checks for library functions. +AC_TYPE_SIGNAL +AC_CHECK_FUNCS(socket strtod) + +AC_CONFIG_HEADER(config.h) +AC_OUTPUT(Makefile) diff --git a/src/zabbix_traper/zabbix_traper.c b/src/zabbix_traper/zabbix_traper.c new file mode 100644 index 00000000..90a8dd6e --- /dev/null +++ b/src/zabbix_traper/zabbix_traper.c @@ -0,0 +1,190 @@ +#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 strtok */ +#include <string.h> + +/* For config file operations */ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#include "common.h" +#include "db.h" +#include "functions.h" + +void signal_handler( int sig ) +{ + if( SIGALRM == sig ) + { + signal( SIGALRM, signal_handler ); + +// fprintf(stderr,"Timeout while executing operation."); + } + + if( SIGQUIT == sig || SIGINT == sig || SIGTERM == sig ) + { +// fprintf(stderr,"\nGot QUIT or INT or TERM signal. Exiting..." ); + } + exit( FAIL ); +} + +int check_security(void) +{ + char *sname; + char *config; + struct sockaddr_in name; + int i; + int file; + + config=(char *)malloc(16); + + file=open("/etc/zabbix/zabbix_agent.conf",O_RDONLY); + if(file == -1) + { +// printf("Open failed"); + return FAIL; + } + i=read(file, config, 16); + config[i-1]=0; + close(file); + + i=sizeof(struct sockaddr_in); + + if(getpeername(0, &name, &i) == 0) + { +// printf("%d\n",name.sin_port); + sname=inet_ntoa(name.sin_addr); +// printf("From:=%s=\n",sname); + if(strcmp(sname,config)!=0) + { + return FAIL; + } + } + return SUCCEED; +} + +int process_data(char *server,char *key, double value) +{ + char sql[1024]; + int itemid; + double lastvalue; + + DB_RESULT *result; + DB_ROW row; + + sprintf(sql,"select i.itemid,i.lastvalue from items i,hosts h where h.status=0 and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=2;",server,key); + DBexecute(sql); + + result = DBget_result(); + if(result==NULL) + { + DBfree_result(result); + return FAIL; + } + if(DBnum_rows(result)==0) + { + DBfree_result(result); + return FAIL; + } + row = DBfetch_row(result); + if( row[0] == NULL ) + { + DBfree_result(result); + return FAIL; + } + + itemid=atoi(row[0]); + + sprintf(sql,"insert into history (itemid,clock,value) values (%d,unix_timestamp(),%g);",itemid,value); + DBexecute(sql); + + if(NULL == row[1]) + { + sprintf(sql,"update items set lastvalue=%g,lastclock=unix_timestamp() where itemid=%d;",value,itemid); + } + else + { + lastvalue=atof(row[1]); + sprintf(sql,"update items set prevvalue=%g,lastvalue=%g,lastclock=unix_timestamp() where itemid=%d;",lastvalue,value,itemid); + } + + DBexecute(sql); + + updateFunctions( itemid ); + + DBfree_result(result); + + return SUCCEED; +} + +int main() +{ + char *s,*p; + char *server,*key,*value_string; + double value; + + int ret=SUCCEED; + + +// if(check_security() == FAIL) +// { +// exit(FAIL); +// } + + signal( SIGINT, signal_handler ); + signal( SIGQUIT, signal_handler ); + signal( SIGTERM, signal_handler ); + signal( SIGALRM, signal_handler ); + + s=(char *) malloc( 1024 ); + + alarm(TRAPER_TIMEOUT); + + fgets(s,1024,stdin); + for( p=s+strlen(s)-1; p>s && ( *p=='\r' || *p =='\n' || *p == ' ' ); --p ); + p[1]=0; + + server=(char *)strtok(s,":"); + if(NULL == server) + { + return FAIL; + } + + key=(char *)strtok(NULL,":"); + if(NULL == key) + { + return FAIL; + } + + value_string=(char *)strtok(NULL,":"); + if(NULL == value_string) + { + return FAIL; + } + value=atof(value_string); + + + DBconnect(); + + ret=process_data(server,key,value); + + alarm(0); + + if(SUCCEED == ret) + { + printf("OK\n"); + } + + free(s); + + return ret; +} |