Showing posts with label zabbix. Show all posts
Showing posts with label zabbix. Show all posts

Keep both Zabbix 1.8 and 2.2 running for real world testing

Jephe Wu - http://linuxtechres.blogspot.com

Objective: keep both Zabbix 1.8 and 2.2 system running for same monitored hosts for real world testing.
Challenge: make zabbix 2.2 proxies to be able to monitor same set of agent hosts without adding new proxies into /etc/zabbix/zabbix_agentd.conf
Environment: CentOS 6.4 64bit, Zabbix 1.8(old system) and Zabbix 2.2(new system), Percona server 5.5(both old and new), Zabbix proxy 1.8(old system) and Zabbix proxy 2.2(new system)

Zabbix monitoring network is at 192.168.0.0/24, monitored hosts are at different network, we use about 10 zabbix proxies for monitoring. All agent hosts are configured to use these 10 zabbix proxies for monitoring.


Network diagram


Steps:
1.  Preparing Zabbix 2.2 system server/VM first 

We can prepare Zabbix 2.2 web server VM, zabbix 2.2 server VM and all zabbix 2.2 Proxies first.

2. Online clone Percona server 5.5 db01 to db02
refer to http://linuxtechres.blogspot.com.au/2014/02/preparing-mysql-slave-database-by.html

3.  Enable ip_forward and iptables NAT on existing proxies
For proxy servers prox01,prox02,....prox10, run:

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -p tcp -o eth0 -j SNAT --to 192.168.0.100

Note: this will enable ip forward for any traffic received from eth0, then the destination is not for prox01 itself

4.  on new proxies, enable default gateway to old proxies
on each proxy server 2.2, change default gateway to coresponding old 1.8 proxy server IP address 

5.  on each new proxy server, configure hostname as old proxy name
e.g. still use hostname=prox01 on prox01new

This way, new proxy will get data through old proxy server iptables IP Masquerading.

6. go to new Zabbix 2.2 web GUI to modify SMTP server setting to avoid sending double alert together with old 1.8 Zabbix system.

How to do migration to 2.2 after testing


1.  shutdown each proxy, bring up new coresponding proxy with same IP address
2.  remove default gateway, use normal default gateway instead.

How to install/backup Mysql 5.5 on CentOS 6 for zabbix database


Jephe Wu - http://linuxtechres.blogspot.com


Objective: upgrade Mysql to version 5.5 on CentOS 6 for zabbix installation
Environment: CentOS 6.2 64bit


Steps:

1. install epel and remi repository from http://blog.famillecollet.com/pages/Config-en

# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm
# wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
# rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm

2. install mysql and mysql-server
# yum --enablerepo=remi,remi-test install mysql mysql-server



3. make it automatic start on reboot
# service mysqld start
# chkconfig --list mysqld
# chkconfig mysqld on

4. Secure mysql 
# mysql_secure_installation
answer yes to disable root login remotely, drop test database, remove anonymous users etc

5. change mysql admin password
# mysqladmin -u root password password
note: assume your use 'password' as your root password.

6. create zabbix user and database
# mysql [-h localhost] -u root -ppassword
# mysql> create database zabbix;
# mysql> create user 'zabbix'[@'1.2.3.4'] identified by 'zabbix';
# mysql> grant all on zabbix.* to zabbix[@'1.2.3.4'];
# mysql> flush privileges;
# mysql> exit;

Note: [..] is optional

7. update firewall rules for iptables
update iptables firewall rules if necessary.

8. other options
use Percona mysql 5.5 at http://www.percona.com/software/

9. backup mysql - backup database 'jephe'

#!/bin/sh

WEEK=`date +%w`
mysqldump jephe --add-drop-table --add-locks --extended-insert --single-transaction --quick -u jephe -ppassword | bzip2 > /data/backup/jephe_mysql.sql.$WEEK.bz2


Setup snmp and snmptrap monitoring under Zabbix


Jephe Wu - http://linuxtechres.blogspot.com

Objective: understanding snmp, snmptrap under zabbix

Note:For zabbix, –with-net-snmp zabbix compiling option is not needed if you only want to receive traps. if you also want to poll snmp, then it is required.


part I - snmp monitoring - snmpget, snmpwalk

1. snmp items with zabbix
refer to http://www.zabbix.com/wiki/howto/monitor/snmp/snmp?s[]=snmp&s[]=item


2. get snmp item name
# snmpwalk snmpserver -v1 -c public
# snmpwalk -c public -v 2c ipaddress


root@snmp:~/ # snmpget -c public -v 1 172.16.62.3 .1.3.6.1.4.1.9.9.171.1.2.1.1.0
SNMPv2-SMI::enterprises.9.9.171.1.2.1.1.0 = Gauge32: 9

Note: 1.3.6.1.4.1.9.9.171.1.2.1.1 is a cisco ipsec mib at http://www.oidview.com/mibs/9/CISCO-IPSEC-FLOW-MONITOR-MIB.html, refer to cikeGlobalActiveTunnels


Refer to free snmp MIB library at http://www.oidview.com/mibs/detail.html
and http://www.iana.org/assignments/enterprise-numbers

Part II - snmptrap


1. snmptrapd.conf 
root@snmptrap:/etc/snmp/ # chkconfig --list snmptrapd
snmptrapd       0:off 1:off 2:on 3:on 4:on 5:on 6:off


root@snmptrap:/etc/snmp/ # /etc/init.d/snmptrapd status
snmptrapd (pid  27227) is running...


root@snmptrap:/etc/snmp/ # more snmptrapd.conf 
authCommunity execute public
authCommunity execute PUBLIC
disableAuthorization yes
#log syslog
traphandle default /usr/bin/zabbix_snmptraphandler.pl
traphandle default /usr/bin/perl /usr/bin/traptoemail -s jephe.mailserver.com -f snmptrap@snmptrap.domain jwu@domain.com


Note: if community string is not public, please change the first/second line.
refer to http://www.zabbix.com/wiki/howto/monitor/snmp/snmp_traps_-_a_new_solution for traphandle perl script




2. test it from snmptrap server itself, you should receive email.
# snmptrap -Ci -v 2c -c public localhost "" "NET-SNMP-MIB::netSnmpExperimental" NET-SNMP-MIB:netSnmpExperimental s "test"


root@snmptrap:/etc/snmp/ # which snmptrap
/usr/bin/snmptrap
root@snmptrap:/etc/snmp/ # rpm -qf /usr/bin/snmptrap
net-snmp-utils-5.3.2.2-14.el5_7.1


Note: you might want to look at SNMPTT at http://snmptt.sourceforge.net/ 




3. sample zabbix templates for snmp devices


http://www.zabbix.com/wiki/templates/cisco_2960



Part III - References
http://www.zabbix.com/wiki/howto/monitor/snmp/a_simple_snmp_trap_handler
http://www.oidview.com/mibs/detail.html
http://www.iana.org/assignments/enterprise-numbers

http://ireasoning.com/mibbrowser.shtml  (better to use for snmp walk)
http://www.manageengine.com/products/mibbrowser-free-tool/download.html  (absolutely free, for snmpwalk, put .iso.org.dod.internet.mgmt in the Object ID column, then click 'snmpwalk' button)

http://www.youtube.com/watch?v=TiBrB0qxQao
http://www.youtube.com/watch?v=J0fPuXZySXE&feature=related
http://www.youtube.com/watch?v=biH-UAPxo_0&feature=related


How to make partition under Zabbix


Jephe Wu - http://linuxtechres.blogspot.com

Environment: CentOS 6.2 64bit, newly configured Zabbix 1.8.6 server
Objective: make partition for those tables

Concepts:
In order to increase performance, you can create parititon for some tables, refer to http://zabbixzone.com/zabbix/partitioning-tables/ and http://pastebin.com/nY8WG9Fr


Steps:

1.  modified zabbix partition procedure, keep 2 days for daily partition and 2 months for monthly partition, only keep 12 months for trends and trends_uint tables.

# more createpartitionproc.sql
/**************************************************************
MySQL Auto Partitioning Procedure for Zabbix 1.8
  http://zabbixzone.com/zabbix/partitioning-tables/

  Author:  Ricardo Santos (rsantos at gmail.com)
  Version: 20110518
  Modied: Phil - 20110526
 should be run daily, can surive if run weekly for daily partitions

mysql -B -h localhost -u zabbix -pPASSWORD zabbix -e "CALL create_daily_zabbix_partitions();

 should be run monthly, can surive if run every year for monthly partitions

mysql -B -h localhost -u zabbix -pPASSWORD zabbix -e "CALL create_daily_zabbix_partitions();
mysql -B -h localhost -u zabbix -pPASSWORD zabbix -e "CALL create_monthly_zabbix_partitions();

**************************************************************/
DELIMITER //
DROP PROCEDURE IF EXISTS `zabbix`.`create_daily_zabbix_partitions` //
CREATE PROCEDURE `zabbix`.`create_daily_zabbix_partitions` ()
BEGIN
CALL zabbix.create_next_daily_partitions("zabbix","history");
CALL zabbix.create_next_daily_partitions("zabbix","history_log");
CALL zabbix.create_next_daily_partitions("zabbix","history_str");
CALL zabbix.create_next_daily_partitions("zabbix","history_text");
CALL zabbix.create_next_daily_partitions("zabbix","history_uint");
CALL zabbix.drop_old_daily_partitions("zabbix","history");
CALL zabbix.drop_old_daily_partitions("zabbix","history_log");
CALL zabbix.drop_old_daily_partitions("zabbix","history_str");
CALL zabbix.drop_old_daily_partitions("zabbix","history_text");
CALL zabbix.drop_old_daily_partitions("zabbix","history_uint");
END //
DROP PROCEDURE IF EXISTS `zabbix`.`create_monthly_zabbix_partitions` //
CREATE PROCEDURE `zabbix`.`create_monthly_zabbix_partitions` ()
BEGIN
CALL zabbix.create_next_monthly_partitions("zabbix","acknowledges");
CALL zabbix.create_next_monthly_partitions("zabbix","alerts");
CALL zabbix.create_next_monthly_partitions("zabbix","auditlog");
CALL zabbix.create_next_monthly_partitions("zabbix","events");
CALL zabbix.create_next_monthly_partitions("zabbix","service_alarms");
CALL zabbix.create_next_monthly_partitions("zabbix","trends");
CALL zabbix.create_next_monthly_partitions("zabbix","trends_uint");
CALL zabbix.drop_old_monthly_partitions("zabbix","acknowledges");
CALL zabbix.drop_old_monthly_partitions("zabbix","alerts");
CALL zabbix.drop_old_monthly_partitions("zabbix","auditlog");
CALL zabbix.drop_old_monthly_partitions("zabbix","events");
CALL zabbix.drop_old_monthly_partitions("zabbix","service_alarms");
CALL zabbix.drop_old_monthly_partitions2("zabbix","trends");
CALL zabbix.drop_old_monthly_partitions2("zabbix","trends_uint");
END //
/* create a week in advance, in case something happens to cron */
DROP PROCEDURE IF EXISTS `zabbix`.`create_next_daily_partitions` //
CREATE PROCEDURE `zabbix`.`create_next_daily_partitions` (SCHEMANAME varchar(64), TABLENAME varchar(64))
BEGIN
DECLARE NEXTCLOCK timestamp;
DECLARE PARTITIONNAME varchar(16);
DECLARE CLOCK int;
SET @totaldays = 7;
SET @i = 1;
createloop: LOOP
SET NEXTCLOCK = DATE_ADD(NOW(),INTERVAL @i DAY);
SET PARTITIONNAME = DATE_FORMAT( NEXTCLOCK, 'p%Y%m%d' );
SET CLOCK = UNIX_TIMESTAMP(DATE_FORMAT(DATE_ADD( NEXTCLOCK ,INTERVAL 1 DAY),'%Y-%m-%d 00:00:00'));
CALL zabbix.create_partition( SCHEMANAME, TABLENAME, PARTITIONNAME, CLOCK );
SET @i=@i+1;
IF @i > @totaldays THEN
LEAVE createloop;
END IF;
END LOOP;
END //
/* we want to keep at least 7, but we will scan and make sure we haven't missed and so 7-14 */
DROP PROCEDURE IF EXISTS `zabbix`.`drop_old_daily_partitions` //
CREATE PROCEDURE `zabbix`.`drop_old_daily_partitions` (SCHEMANAME varchar(64), TABLENAME varchar(64))
BEGIN
DECLARE OLDCLOCK timestamp;
DECLARE PARTITIONNAME varchar(16);
DECLARE CLOCK int;
SET @mindays = 2;
SET @maxdays = @mindays+7;
SET @i = @maxdays;
droploop: LOOP
SET OLDCLOCK = DATE_SUB(NOW(),INTERVAL @i DAY);
SET PARTITIONNAME = DATE_FORMAT( OLDCLOCK, 'p%Y%m%d' );
CALL zabbix.drop_partition( SCHEMANAME, TABLENAME, PARTITIONNAME );
SET @i=@i-1;
IF @i <= @mindays THEN
LEAVE droploop;
END IF;
END LOOP;
END //
/* we want to keep at least 12, but we will scan and make sure we haven't missed and so 7-14 */
DROP PROCEDURE IF EXISTS `zabbix`.`create_next_monthly_partitions` //
CREATE PROCEDURE `zabbix`.`create_next_monthly_partitions` (SCHEMANAME varchar(64), TABLENAME varchar(64))
BEGIN
DECLARE NEXTCLOCK timestamp;
DECLARE PARTITIONNAME varchar(16);
DECLARE CLOCK int;
SET @totalmonths = 12;
SET @i = 1;
createloop: LOOP
SET NEXTCLOCK = DATE_ADD(NOW(),INTERVAL @i MONTH);
SET PARTITIONNAME = DATE_FORMAT( NEXTCLOCK, 'p%Y%m' );
SET CLOCK = UNIX_TIMESTAMP(DATE_FORMAT(DATE_ADD( NEXTCLOCK ,INTERVAL 1 MONTH),'%Y-%m-01 00:00:00'));
CALL zabbix.create_partition( SCHEMANAME, TABLENAME, PARTITIONNAME, CLOCK );
SET @i=@i+1;
IF @i > @totalmonths THEN
LEAVE createloop;
END IF;
END LOOP;
END //

/* we want to keep at least 12 months, but we will scan and make sure we haven't missed and so 7-14 */
DROP PROCEDURE IF EXISTS `zabbix`.`drop_old_monthly_partitions2` //
CREATE PROCEDURE `zabbix`.`drop_old_monthly_partitions2` (SCHEMANAME varchar(64), TABLENAME varchar(64))
BEGIN
DECLARE OLDCLOCK timestamp;
DECLARE PARTITIONNAME varchar(16);
DECLARE CLOCK int;
SET @minmonths = 12;
SET @maxmonths = @minmonths+3;
SET @i = @maxmonths;
droploop: LOOP
SET OLDCLOCK = DATE_SUB(NOW(),INTERVAL @i MONTH);
SET PARTITIONNAME = DATE_FORMAT( OLDCLOCK, 'p%Y%m' );

CALL zabbix.drop_partition( SCHEMANAME, TABLENAME, PARTITIONNAME );
SET @i=@i-1;
IF @i <= @minmonths THEN
LEAVE droploop;
END IF;
END LOOP;
END //
/* we want to keep at least 2 months, but we will scan and make sure we haven't missed and so 7-14 */
DROP PROCEDURE IF EXISTS `zabbix`.`drop_old_monthly_partitions` //
CREATE PROCEDURE `zabbix`.`drop_old_monthly_partitions` (SCHEMANAME varchar(64), TABLENAME varchar(64))
BEGIN
DECLARE OLDCLOCK timestamp;
DECLARE PARTITIONNAME varchar(16);
DECLARE CLOCK int;
SET @minmonths = 2;
SET @maxmonths = @minmonths+3;
SET @i = @maxmonths;
droploop: LOOP
SET OLDCLOCK = DATE_SUB(NOW(),INTERVAL @i MONTH);
SET PARTITIONNAME = DATE_FORMAT( OLDCLOCK, 'p%Y%m' );

CALL zabbix.drop_partition( SCHEMANAME, TABLENAME, PARTITIONNAME );
SET @i=@i-1;
IF @i <= @minmonths THEN
LEAVE droploop;
END IF;
END LOOP;
END //
DROP PROCEDURE IF EXISTS `zabbix`.`create_partition` //
CREATE PROCEDURE `zabbix`.`create_partition` (SCHEMANAME varchar(64), TABLENAME varchar(64), PARTITIONNAME varchar(64), CLOCK int)
BEGIN
DECLARE RETROWS int;
SELECT COUNT(1) INTO RETROWS
FROM `information_schema`.`partitions`
WHERE `table_schema` = SCHEMANAME AND `table_name` = TABLENAME AND `partition_name` = PARTITIONNAME;

IF RETROWS = 0 THEN
SELECT CONCAT( "create_partition(", SCHEMANAME, ",", TABLENAME, ",", PARTITIONNAME, ",", CLOCK, ")" ) AS msg;
      SET @sql = CONCAT( 'ALTER TABLE `', SCHEMANAME, '`.`', TABLENAME, '`',
' ADD PARTITION (PARTITION ', PARTITIONNAME, ' VALUES LESS THAN (', CLOCK, '));' );
PREPARE STMT FROM @sql;
EXECUTE STMT;
DEALLOCATE PREPARE STMT;
END IF;
END //
DROP PROCEDURE IF EXISTS `zabbix`.`drop_partition` //
CREATE PROCEDURE `zabbix`.`drop_partition` (SCHEMANAME varchar(64), TABLENAME varchar(64), PARTITIONNAME varchar(64))
BEGIN
DECLARE RETROWS int;
SELECT COUNT(1) INTO RETROWS
FROM `information_schema`.`partitions`
WHERE `table_schema` = SCHEMANAME AND `table_name` = TABLENAME AND `partition_name` = PARTITIONNAME;

IF RETROWS = 1 THEN
SELECT CONCAT( "drop_partition(", SCHEMANAME, ",", TABLENAME, ",", PARTITIONNAME, ")" ) AS msg;
      SET @sql = CONCAT( 'ALTER TABLE `', SCHEMANAME, '`.`', TABLENAME, '`',
' DROP PARTITION ', PARTITIONNAME, ';' );
PREPARE STMT FROM @sql;
EXECUTE STMT;
DEALLOCATE PREPARE STMT;
END IF;
END //
DELIMITER ;

2. import procedure into mysql database
mysql -uroot -ppassword < createpartitionproc.sql

3. alter table to create initial parititon

if you directly run command in cronjob like 'mysql -B -h localhost -u zabbix -pzabbix zabbix -e "CALL create_daily_zabbix_partitions();"', you will get error:
create_partition(zabbix,history,p20120517,1337263200)
ERROR 1505 (HY000) at line 1: Partition management on a not partitioned table is not possible

4. put cronjob in /etc/cron.d
[root@db01 cron.d]# more mysqlpartition
30 1 * * * mysql  mysql -B -h localhost -u zabbix -pzabbix zabbix -e "CALL create_daily_zabbix_partitions();"
30 1 1 * * mysql mysql -B -h localhost -u zabbix -pzabbix zabbix -e "CALL create_monthly_zabbix_partitions();"

5. create initial partitions

 alter table history partition by range(clock) (partition p20120516 values less than (unix_timestamp("2012-05-17 00:00:00")));
 alter table history_str partition by range(clock) (partition p20120516 values less than (unix_timestamp("2012-05-17 00:00:00")));
 alter table history_uint partition by range(clock) (partition p20120516 values less than (unix_timestamp("2012-05-17 00:00:00")));

 But when running for history_log and history_text tables, we got error below:
 mysql> alter table history_log partition by range(clock) (partition p20120516 values less than (1337176800));
 ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function

 mysql> alter table history_text partition by range(clock) (partition p20120516 values less than (1337176800));
 ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function

 You need to put 'clock' column into primary key column and unique index key column as follows:

 ALTER TABLE  `zabbix`.`history_log` DROP PRIMARY KEY ,
 ADD PRIMARY KEY (  `id` ,  `clock` ,  `itemid` )


 ALTER TABLE  `zabbix`.`history_log` DROP INDEX  `history_log_2` ,
 ADD UNIQUE  `history_log_2` (  `itemid` ,  `id` ,  `clock` )


  Same thing happens to monthly tables:

  mysql> alter table acknowledges partition by range (clock) ( partition p201205 values less than (unix_timestamp("2012-06-01 00:00:00")));
  ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function
  mysql> alter table alerts partition by range (clock) ( partition p201205 values less than (unix_timestamp("2012-06-01 00:00:00")));
  ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function
  mysql> alter table auditlog partition by range (clock) ( partition p201205 values less than (unix_timestamp("2012-06-01 00:00:00")));
  ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function
  mysql> alter table events partition by range (clock) ( partition p201205 values less than (unix_timestamp("2012-06-01 00:00:00")));
  ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function
  mysql> alter table service_alarms partition by range (clock) ( partition p201205 values less than (unix_timestamp("2012-06-01 00:00:00")));
  ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function
  
  mysql> alter table trends partition by range (clock) ( partition p201205 values less than (unix_timestamp("2012-06-01 00:00:00")));
  Query OK, 64 rows affected (0.05 sec)
  Records: 64  Duplicates: 0  Warnings: 0


  mysql> alter table trends_uint partition by range (clock) ( partition p201205 values less than (unix_timestamp("2012-06-01 00:00:00")));
  Query OK, 90 rows affected (0.02 sec)
  Records: 90  Duplicates: 0  Warnings: 0

  6. manually run cronjob once to create necessary daily and monthly tables in advance.



mysql -B -h localhost -u zabbix -pzabbix zabbix -e "CALL create_daily_zabbix_partitions();
mysql -B -h localhost -u zabbix -pzabbix zabbix -e "CALL create_monthly_zabbix_partitions();


  7. verify tables with partitions
  mysql -uzabbix -pzabbix zabbix
  mysql> show create table history;

  8. References:
  http://zabbixzone.com/zabbix/partitioning-tables/
  http://pastebin.com/nY8WG9Fr
   


















Zabbix partition deleting accident


Jephe Wu - http://linuxtechres.blogspot.com

Env: Zabbix 1.8.5 on CentOS 6.2 64bit.
config: daily and monthly partition has been configured on zabbix database, please refer to http://zabbixzone.com/zabbix/partitioning-tables/ and http://pastebin.com/nY8WG9Fr
accident: changed the minimum value of month from 12 to 2 to keep only 2 months data for trends and trends_uint tables.
e.g. the current month is Apr, deleted 201106-201201, left 201202-201204 plus the future months till 201204 objective: undo the deletion

Concept: restore the whole set of data from tape, then export the trends and trends_uint tables by mysqldump, create partitions again then import back to production database.


After incident, the table trends partition becomes this:
CREATE TABLE `trends` (
  `itemid` bigint(20) unsigned NOT NULL DEFAULT '0',
  `clock` int(11) NOT NULL DEFAULT '0',
  `num` int(11) NOT NULL DEFAULT '0',
  `value_min` double(16,4) NOT NULL DEFAULT '0.0000',
  `value_avg` double(16,4) NOT NULL DEFAULT '0.0000',
  `value_max` double(16,4) NOT NULL DEFAULT '0.0000',
  PRIMARY KEY (`itemid`,`clock`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE ( clock)
(PARTITION p201202 VALUES LESS THAN (1330520400) ENGINE = InnoDB,
 PARTITION p201203 VALUES LESS THAN (1333198800) ENGINE = InnoDB,
 PARTITION p201204 VALUES LESS THAN (1335794400) ENGINE = InnoDB,
 PARTITION p201205 VALUES LESS THAN (1338472800) ENGINE = InnoDB,
 PARTITION p201206 VALUES LESS THAN (1341064800) ENGINE = InnoDB,
 PARTITION p201207 VALUES LESS THAN (1343743200) ENGINE = InnoDB,
 PARTITION p201208 VALUES LESS THAN (1346421600) ENGINE = InnoDB,
 PARTITION p201209 VALUES LESS THAN (1349013600) ENGINE = InnoDB,
 PARTITION p201210 VALUES LESS THAN (1351688400) ENGINE = InnoDB,
 PARTITION p201211 VALUES LESS THAN (1354280400) ENGINE = InnoDB,
 PARTITION p201212 VALUES LESS THAN (1356958800) ENGINE = InnoDB,
 PARTITION p201301 VALUES LESS THAN (1359637200) ENGINE = InnoDB,
 PARTITION p201302 VALUES LESS THAN (1362056400) ENGINE = InnoDB,
 PARTITION p201303 VALUES LESS THAN (1364734800) ENGINE = InnoDB,
 PARTITION p201304 VALUES LESS THAN (1367330400) ENGINE = InnoDB) */ |


Steps: 


1. restore the whole set of backup data from tape, export the deleted partition data as .sql file.
  mysqldump -uzabbix -pzabbix zabbix --no-create-info --skip-add-locks -w "clock >=1309442400 and clock <1312120800" trends > trends_201107.sql
  mysqldump -uzabbix -pzabbix zabbix --no-create-info --skip-add-locks -w "clock >=1312120800 and clock <1314799200" trends > trends_201108.sql
  mysqldump -uzabbix -pzabbix zabbix --no-create-info --skip-add-locks -w "clock >=1314799200 and clock <1317391200" trends > trends_201109.sql
  ...
  mysqldump -uzabbix -pzabbix zabbix --no-create-info --skip-add-locks -w "clock >=1309442400 and clock <1312120800" trends_uint > 


trends_uint_201107.sql
  mysqldump -uzabbix -pzabbix zabbix --no-create-info --skip-add-locks -w "clock >=1312120800 and clock <1314799200" trends_uint > 


trends_uint_201108.sql
  mysqldump -uzabbix -pzabbix zabbix --no-create-info --skip-add-locks -w "clock >=1314799200 and clock <1317391200" trends_uint > 


trends_uint_201109.sql
  ...

2. create partiton back first ( it will use temporary name during creation, after finish, it will use trends.* name back again)

echo "ALTER TABLE trends PARTITION BY RANGE( clock ) (
 PARTITION p201106 VALUES LESS THAN (1309442400) ENGINE = InnoDB,
 PARTITION p201107 VALUES LESS THAN (1312120800) ENGINE = InnoDB,
 PARTITION p201108 VALUES LESS THAN (1314799200) ENGINE = InnoDB,
 PARTITION p201109 VALUES LESS THAN (1317391200) ENGINE = InnoDB,
 PARTITION p201110 VALUES LESS THAN (1320066000) ENGINE = InnoDB,
 PARTITION p201111 VALUES LESS THAN (1322658000) ENGINE = InnoDB,
 PARTITION p201112 VALUES LESS THAN (1325336400) ENGINE = InnoDB,
 PARTITION p201201 VALUES LESS THAN (1328014800) ENGINE = InnoDB,
 PARTITION p201202 VALUES LESS THAN (1330520400) ENGINE = InnoDB,
 PARTITION p201203 VALUES LESS THAN (1333198800) ENGINE = InnoDB,
 PARTITION p201204 VALUES LESS THAN (1335794400) ENGINE = InnoDB,
 PARTITION p201205 VALUES LESS THAN (1338472800) ENGINE = InnoDB,
 PARTITION p201206 VALUES LESS THAN (1341064800) ENGINE = InnoDB,
 PARTITION p201207 VALUES LESS THAN (1343743200) ENGINE = InnoDB,
 PARTITION p201208 VALUES LESS THAN (1346421600) ENGINE = InnoDB,
 PARTITION p201209 VALUES LESS THAN (1349013600) ENGINE = InnoDB,
 PARTITION p201210 VALUES LESS THAN (1351688400) ENGINE = InnoDB,
 PARTITION p201211 VALUES LESS THAN (1354280400) ENGINE = InnoDB,
 PARTITION p201212 VALUES LESS THAN (1356958800) ENGINE = InnoDB,
 PARTITION p201301 VALUES LESS THAN (1359637200) ENGINE = InnoDB,
 PARTITION p201302 VALUES LESS THAN (1362056400) ENGINE = InnoDB,
 PARTITION p201303 VALUES LESS THAN (1364734800) ENGINE = InnoDB,
 PARTITION p201304 VALUES LESS THAN (1367330400) ENGINE = InnoDB )" | mysql -u zabbix -pzabbix zabbix


echo "ALTER TABLE trends_uint PARTITION BY RANGE( clock ) (
 PARTITION p201106 VALUES LESS THAN (1309442400) ENGINE = InnoDB,
 PARTITION p201107 VALUES LESS THAN (1312120800) ENGINE = InnoDB,
 PARTITION p201108 VALUES LESS THAN (1314799200) ENGINE = InnoDB,
 PARTITION p201109 VALUES LESS THAN (1317391200) ENGINE = InnoDB,
 PARTITION p201110 VALUES LESS THAN (1320066000) ENGINE = InnoDB,
 PARTITION p201111 VALUES LESS THAN (1322658000) ENGINE = InnoDB,
 PARTITION p201112 VALUES LESS THAN (1325336400) ENGINE = InnoDB,
 PARTITION p201201 VALUES LESS THAN (1328014800) ENGINE = InnoDB,
 PARTITION p201202 VALUES LESS THAN (1330520400) ENGINE = InnoDB,
 PARTITION p201203 VALUES LESS THAN (1333198800) ENGINE = InnoDB,
 PARTITION p201204 VALUES LESS THAN (1335794400) ENGINE = InnoDB,
 PARTITION p201205 VALUES LESS THAN (1338472800) ENGINE = InnoDB,
 PARTITION p201206 VALUES LESS THAN (1341064800) ENGINE = InnoDB,
 PARTITION p201207 VALUES LESS THAN (1343743200) ENGINE = InnoDB,
 PARTITION p201208 VALUES LESS THAN (1346421600) ENGINE = InnoDB,
 PARTITION p201209 VALUES LESS THAN (1349013600) ENGINE = InnoDB,
 PARTITION p201210 VALUES LESS THAN (1351688400) ENGINE = InnoDB,
 PARTITION p201211 VALUES LESS THAN (1354280400) ENGINE = InnoDB,
 PARTITION p201212 VALUES LESS THAN (1356958800) ENGINE = InnoDB,
 PARTITION p201301 VALUES LESS THAN (1359637200) ENGINE = InnoDB,
 PARTITION p201302 VALUES LESS THAN (1362056400) ENGINE = InnoDB,
 PARTITION p201303 VALUES LESS THAN (1364734800) ENGINE = InnoDB,
 PARTITION p201304 VALUES LESS THAN (1367330400) ENGINE = InnoDB )" | mysql -u zabbix -pzabbix zabbix


or there's a better way, just split partition as follows (less disruptive way, need to re-arrange less data)


echo "ALTER TABLE trends REORGANIZE PARTITION p201202 INTO 
( PARTITION p201106 VALUES LESS THAN (1309442400) ENGINE = InnoDB,
 PARTITION p201107 VALUES LESS THAN (1312120800) ENGINE = InnoDB,
 PARTITION p201108 VALUES LESS THAN (1314799200) ENGINE = InnoDB,
 PARTITION p201109 VALUES LESS THAN (1317391200) ENGINE = InnoDB,
 PARTITION p201110 VALUES LESS THAN (1320066000) ENGINE = InnoDB,
 PARTITION p201111 VALUES LESS THAN (1322658000) ENGINE = InnoDB,
 PARTITION p201112 VALUES LESS THAN (1325336400) ENGINE = InnoDB,
 PARTITION p201201 VALUES LESS THAN (1328014800) ENGINE = InnoDB,
 PARTITION p201202 VALUES LESS THAN (1330520400) ENGINE = InnoDB)" | mysql -u zabbix -pzabbix zabbix


echo "ALTER TABLE trends_uint REORGANIZE PARTITION p201202 INTO 
( PARTITION p201106 VALUES LESS THAN (1309442400) ENGINE = InnoDB,
 PARTITION p201107 VALUES LESS THAN (1312120800) ENGINE = InnoDB,
 PARTITION p201108 VALUES LESS THAN (1314799200) ENGINE = InnoDB,
 PARTITION p201109 VALUES LESS THAN (1317391200) ENGINE = InnoDB,
 PARTITION p201110 VALUES LESS THAN (1320066000) ENGINE = InnoDB,
 PARTITION p201111 VALUES LESS THAN (1322658000) ENGINE = InnoDB,
 PARTITION p201112 VALUES LESS THAN (1325336400) ENGINE = InnoDB,
 PARTITION p201201 VALUES LESS THAN (1328014800) ENGINE = InnoDB,
 PARTITION p201202 VALUES LESS THAN (1330520400) ENGINE = InnoDB)" | mysql -u zabbix -pzabbix zabbix

If the partitioned table data is too large, you can reorganize or rebuild partition to reduce size as follows:

According to my test, after running

 'echo "ALTER TABLE trends_uint REORGANIZE PARTITION p201202 INTO ( PARTITION p201202 VALUES LESS THAN (1330520400) ENGINE = InnoDB)" | mysql -u zabbix -pzabbix zabbix'

, it reduce size to almost half of it.

you can also use rebuild partition just for reducing size.

echo "ALTER TABLE trends_uint rebuild PARTITION p201203" | mysql -uzabbix -pzabbix zabbix


3. import back to the database, for example
mysql -uzabbix -pzabbix zabbix < trends_201201.sql

4. references

mysql -uroot -ppasword -e "select * from mysql.proc"  
mysql -B -h localhost -u zabbix -pzabbix zabbix -e "CALL create_monthly_zabbix_partitions();" 
mysql -uroot -ppassword < createpartitionproc.sql 
mysql -uzabbix -pzabbix zabbix -e "show create table trends"
mysql> alter table trends_uint add partition ( partition p201201 VALUES LESS THAN (1328014800) ENGINE = InnoDB);
ERROR 1493 (HY000): VALUES LESS THAN value must be strictly increasing for each partition


http://zabbixzone.com/zabbix/history-and-trends/
http://zabbixzone.com/zabbix/partitioning-tables/
http://pastebin.com/nY8WG9Fr
http://zabbixzone.com/zabbix/making-your-frontend-faster/
http://zabbixzone.com/zabbix/backuping-only-the-zabbix-configuration/


mysqldump -u username -ppassword [--no-create-info] [--no-data]  database_name > dump.sql
mysqldump -u username -ppassword --all-databases > dump.sql

selinux should be disabled, otherwise web setup wizard is unable to connect to database
centos 6.2 minumal install installs iptables and selinux by default

strings trends_uint.frm # check partition info
strings trends_uint.par # check partition info

============
[root@db01 trends_partition_data]# mysql -uzabbix -pzabbix zabbix < trends_201201.sql
ERROR 1062 (23000) at line 42: Duplicate entry '100100000089189-1326373200' for key 'PRIMARY'
 solution: delete 1201 month partition data first, then import again.
---------
delete from trends where clock >= 1325336400 and clock < 1328014800;


[root@db01 etc]# mysql -uzabbix -pzabbix zabbix < trends_201201.sql 


echo "delete from trends where clock >= 1325336400 and clock < 1328014800" | mysql -uzabbix -pzabbix zabbix
echo "delete from trends_uint where clock >= 1325336400 and clock < 1328014800" | mysql -uzabbix -pzabbix zabbix
----------

/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
/*!40101 SET character_set_client = @saved_cs_client */;

If you encounter some error like character set client, use above in the front of sql data file for insert, remove 'lock table trends write' also

5. some command output
[root@db01 etc]# mysql -uzabbix -pzabbix zabbix -e "alter table trends repair patition p201106"
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right

syntax to use near 'patition p201106' at line 1
[root@db01 etc]# mysql -uzabbix -pzabbix zabbix -e "alter table trends repair partition p201106"
+---------------+--------+----------+---------------------------------------------------------+
| Table         | Op     | Msg_type | Msg_text                                                |
+---------------+--------+----------+---------------------------------------------------------+
| zabbix.trends | repair | note     | The storage engine for the table doesn't support repair |
+---------------+--------+----------+---------------------------------------------------------+
[root@db01 etc]# mysql -uzabbix -pzabbix zabbix -e "alter table trends analyze partition p201106"
+---------------+---------+----------+----------+
| Table         | Op      | Msg_type | Msg_text |
+---------------+---------+----------+----------+
| zabbix.trends | analyze | status   | OK       |
+---------------+---------+----------+----------+
[root@db01 etc]# mysql -uzabbix -pzabbix zabbix -e "alter table trends check partition p201106"
+---------------+-------+----------+----------+
| Table         | Op    | Msg_type | Msg_text |
+---------------+-------+----------+----------+
| zabbix.trends | check | status   | OK       |
+---------------+-------+----------+----------+
[root@db01 etc]# mysql -uzabbix -pzabbix zabbix -e "alter table trends optimize partition p201106"
+---------------+----------+----------+-------------------------------------------------------------------+
| Table         | Op       | Msg_type | Msg_text                                                          |
+---------------+----------+----------+-------------------------------------------------------------------+
| zabbix.trends | optimize | note     | Table does not support optimize, doing recreate + analyze instead |
| zabbix.trends | optimize | status   | OK                                                                |
+---------------+----------+----------+-------------------------------------------------------------------+

Refer to http://dev.mysql.com/doc/refman/5.1/en/alter-table-partition-operations.html for alter table partition commands

Only a single instance of any one of the following options can be used in a given ALTER TABLE statement: PARTITION BY, ADD PARTITION, DROP PARTITION, TRUNCATE PARTITION, REORGANIZE PARTITION, or COALESCE PARTITION, ANALYZE PARTITION, CHECK PARTITION, OPTIMIZE PARTITION, REBUILD PARTITION, REMOVE PARTITIONING.

How to use zabbix to monitor MS SQL database performance

Jephe Wu - http://linuxtechres.blogspot.com

Environment: Zabbix 1.8.X monitoring system, MS SQL server 2005
Objective: to monitor MS SQL server performance by zabbix,


Concept: use sys.dm_os_performance_counters which resides in master and msdb database.

According to http://madebysql.blogspot.com.au/2011_01_01_archive.html, sys.dm_os_performance_counters has 3 kinds of values as follows

1. value/base: (e.g. buffer cache hit ratio)


take counter with cntr_type = 537003264 and divide it by
'base' counter with cntr_type = 1073939712.

for example:
("Buffer cache hit ratio" / "Buffer cache hit ratio base") *100
will give you the 'Buffer cache hit ratio'

2. Point In Time:
These are point-in-time counters.They hold the value at the
current point-in-time.These counters have cntr_type = 65792.

SELECT *
FROM sys.dm_os_performance_counters
WHERE counter_name = 'User Connections'
              AND object_name Like '%General Statistics%'

3. cumulative values

meaning the
value must be compared at 2 diffrerent times by calculating the
differences between the values.For instance,get a counter value,
save it, then get it again after 5 seconds for example and the right
final counter value will be:
(@SecondCounterValue-@FirstCounterValue)/5 seconds.

These counters have cntr_type = 272696576.

Methods:
1. use zabbix agent to monitor performance counter
You can run 'perfmon' from run command line, then add a performance counter to list all kinds of sql server counters.

SQL: Number Users Connected         perf_counter["\SQLServer:General Statistics\User Connections"]   
SQL: Lock Waits per second         perf_counter["\SQLServer:Locks(_Total)\Lock Waits/sec"]   
SQL: Number of Deadlocks per second    perf_counter["\SQLServer:Locks(_Total)\Number of Deadlocks/sec"]
SQL: Total Server Memory         perf_counter["\SQLServer:Memory Manager\Total Server Memory (KB)"]


For sql server services monitoring:
use zabbix agent and key 'service_state[MSSQLSERVER]' to monitor , show value is 'Windows service state', type of information is 'Numeric(unsigned)', data type is DEcimal.
Same for service_state[SQLServerAgent] and service_state[SQLBrowser]

that is service_state[<service_name>].

2. use Dbforbix to monitor performance counter

You need to create a sql user 'zabbix' under security inside sql server managament studio(security-logins) and grant sysadmin role to it.
And make sure zabbix is able to login through sql authentication mode. (right click server name in object explorer, properities, security, choose 'SQL server and Windows authentication mode' instead of just Windows authentication mode. Otherwise, zabbix user is not able to login. (Check sql error log if it's unable to login)

You can use the following settings in dbforbix ms sql query configuration:

restoredelay.Query=select restore_delay from msdb.dbo.log_shipping_secondary_databases where secondary_database='WSS_CONTENT';

pagelifeexpectancy.Query=select cntr_value from sys.dm_os_performance_counters where counter_name='Page life expectancy' and instance_name='';
lockwait.Query=select cntr_value from sys.dm_os_performance_counters where counter_name='Lock Waits/sec' and instance_name='_Total';
processblocked.Query=select cntr_value from sys.dm_os_performance_counters where counter_name='Processes blocked';
checkpointpage.Query=select cntr_value from sys.dm_os_performance_counters where counter_name='Checkpoint pages/sec';
pagesplit.Query=select cntr_value from sys.dm_os_performance_counters where counter_name='Page Split/sec';
userconnections.Query=select cntr_value from sys.dm_os_performance_counters where counter_name='User Connections';
batchrequest.Query=select cntr_value from sys.dm_os_performance_counters where counter_name='Batch Requests/sec';
sqlcompilation.Query=select cntr_value from sys.dm_os_performance_counters where counter_name='SQL Compilations/sec';
sqlrecompilation.Query=select cntr_value from sys.dm_os_performance_counters where counter_name='SQL Re-Compilations/sec';


note: table sys.dm_os_performance_counters is in master/msdb system views.

References:


1. http://www.databasejournal.com/features/mssql/article.php/3932406/Top-10-SQL-Server-Counters-for-Monitoring-SQL-Server-Performance.htm 

2. http://www.smartmarmot.com/wiki/index.php/Dbforbix#Steps_for_Installation_on_Microsoft_SQL_Server

3. http://madebysql.blogspot.com.au/2011_01_01_archive.html - How to use performance counters in sys.dm_os_performance_counters DMV

4. http://www.smartmarmot.com/product/dbforbix/ and http://www.smartmarmot.com/wiki/index.php/Main_Page

How to setup compression for high volume zabbix server

Jephe Wu - http://linuxtechres.blogspot.com 

Environment: CentOS 5 64bit, zabbix server with very large items.
Objective: make 'latest data' with group and host set to 'all' page loading faster.


Steps:
1. make sure deflate_module is enabled in apache configuration

LoadModule deflate_module modules/mod_deflate.so

2. filtered by type
for example:

<Location />
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/x-js text/css
</Location>


Note: you can use Lynx or similar to do a headers dump on the file and it will tell you want the mime type is,

e.g.:

$ lynx -head -dump http://www.example.com/js/jquery-1.2.6.min.js
HTTP/1.1 200 OK
Date: Wed, 25 Jun 2008 03:25:53 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Wed, 25 Jun 2008 03:24:47 GMT
ETag: "38016-d9de-37f45dc0"
Accept-Ranges: bytes
Content-Length: 55774
Connection: close
Content-Type: application/x-javascript

<Location />
    AddOutputFilterByType DEFLATE application/x-javascript
</Location>

--------------------
3. example settings
root@zabbixserver01:/var/log/httpd/ # more /etc/httpd/conf.d/deflate.conf
<IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/plain
        AddOutputFilterByType DEFLATE text/html
        AddOutputFilterByType DEFLATE text/xml
        AddOutputFilterByType DEFLATE text/css
        AddOutputFilterByType DEFLATE application/xml
        AddOutputFilterByType DEFLATE application/xhtml+xml
        AddOutputFilterByType DEFLATE application/rss+xml
        AddOutputFilterByType DEFLATE application/javascript
        AddOutputFilterByType DEFLATE application/x-javascript
        DeflateCompressionLevel 9
        BrowserMatch ^Mozilla/4 gzip-only-text/html
        BrowserMatch ^Mozilla/4\.0[678] no-gzip
        BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    # Don't compress images
    SetEnvIfNoCase Request_URI \
    \.(?:gif|jpe?g|png)$ no-gzip dont-vary

    # Make sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary
       
    DeflateFilterNote Input instream
        DeflateFilterNote Output outstream
        DeflateFilterNote Ratio ratio
        LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
    CustomLog logs/deflate_log deflate
</IfModule>


4. References
a. Apache mod_deflate example:
http://httpd.apache.org/docs/2.0/mod/mod_deflate.html

b. http://www.linuxjournal.com/article/6802?page=0,1

c. use php zlib compress by modifying php.ini

PHP with the --with-zlib configure option and then reconfiguring the php.ini file.

Below is what the output buffer method looks like:

output_buffering = On
output_handler = ob_gzhandler
zlib.output_compression = Off


The ZLIB method uses:

output_buffering = Off
output_handler =
zlib.output_compression = On

How dbbix works with Zabbix

Jephe Wu - http://linuxtechres.blogspot.com

Environment
: dbforbix running on separated CentOS 5 box, Zabbix server or zabbix proxy is on another server
Objective: use separated server running dbbix to serve database performance check and show graph on zabbix web gui
Concept:
dbforbix collects data from separated server, then send it to zabbix server(destination server was configured without proxy) or zabbix proxy(server was configured with proxy)


Steps:
1. on dbforbix, configure it as follows:

ZabbixServerList=zabbixserver01,zabbixproxy01
zabbixserver01.Address=172.16.4.1
zabbixserver01.Port=10051

zabbixproxy01.Address=172.16.4.2
zabbixproxy01.Port=10051

DatabaseList=db01,db02


db01.Url=jdbc:mysql://db01:3306/mysqldb01.User=zabbix
db01.Password=zabbix
db01.DatabaseType=mysql
db01.QueryListFile=./conf/mysql/mysqlquery.props

oradb-01.Url=jdbc:oracle:thin:@oradb-01-vip:1521:LIVEDB1
oradb-01.User=zabbix
oradb-01.Password=zabbix
oradb-01.QueryListFile=./conf/oracle/query.props

dbent.Url=jdbc:jtds:sqlserver://172.16.7.2:1987/master
dbent.User=zabbix
dbent.Password=zabbix
dbent.DatabaseType=mssql
dbent.QueryListFile=./conf/mssql/mssqlquery.props

host1.Url=jdbc:postgresql://host1:5432/databasename
host1.User=zabbix
host1.Password=zabbix
host1.DatabaseType=pgsql
host1.QueryListFile=./conf/pgsql/pgsqlquery.props

.....

2. debug if the gui is not updating data

make sure dbforbix server can telnet zabbix server or proxy at port 10051, if not, make sure proxy or server is not running iptables.
otherwise, you will get !X (man traceroute, it's administratively prohibitted indication))
use traceroute or tcptraceroute to troubleshoot.

3. installation guide:
refer to http://www.smartmarmot.com/wiki/index.php/DBforBIX

How to install zabbix agent on Windows and backup zabbix database configuration

Jephe Wu - http://linuxtechres.blogspot.com


steps:

1. refer to doc at http://www.zabbix.com/documentation/1.8/manual/processes/zabbix_agentd_win

2. copy 32bit or 64bit unzipped files to c:\Program Files\Zabbix Agent\ (create this directory first)

3. copy configuration file from zabbix source to above directory as zabbix_agentd.conf

An example configuration file is available in Zabbix source archive as misc/conf/zabbix_agentd.win.conf.

EnableRemoteCommands=0
Server=172.16.1.1,172.16.1.2
Hostname=JEPHE
ListenPort=10050
ServerPort=10051
StartAgents=5

4. install it
go to cmd,
cd "Program Files\Zabbix Agent"
zabbix_agentd.exe -c "c:\Program Files\Zabbix Agent\zabbix_agentd.conf" -i

5. go to services.msc, start zabbix agent.

6. test
from agent host, telnet zabbixserver 10051
from server host, telnet zabbixagent 10050

7. add agent host into zabbix monitored server list

========
backup zabbix configuration shell script:

root@db01:~/bin/ # more zabbix_config_backup.sh
#!/bin/sh
DAY=`date +%w`
HOSTNAME=`hostname`
TABLES="acknowledges actions applications autoreg_host conditions config dchecks dhosts drules dservices escalations expressions functions globalmacro graph_theme graphs graphs_items groups help_items hostmacro hosts hosts_groups hosts_profiles hosts_prof
les_ext hosts_templates housekeeper httpstep httpstepitem httptest httptestitem ids images items items_applications maintenances maintenances_groups maintenances_hosts maintenances_windows mappings media media_type nodes opconditions operations opmediatypes profiles proxy_autoreg_host regexps rights screens screens_items scripts services services_links sessions slides slideshows sysmaps sysmaps_elements sysmaps_link_triggers sysmaps_links timeperiods trigger_depends triggers users users_backup users_groups usrgrp valuemaps"
COMMAND="mysqldump -uzabbix -pzabbix zabbix --add-drop-table --add-locks --extended-insert --single-transaction --quick"
DIR="/mysql/config_backup"
DATATABLES="alerts auditlog events history history_log history_str history_str_sync history_sync history_text history_uint history_uint_sync node_cksum proxy_dhistory proxy_history service_alarms services_times trends trends_uint"

# program starts here
$COMMAND --tables $TABLES | gzip > $DIR/zabbix_config_db.$DAY.gz

(echo "From: `hostname`<root@`hostname`>";echo "Subject: Finished daily Zabbix config backup"; echo "To: jwu@domain.com"; echo "";echo "According to Zabbix
.8 network monitoring book page 377, the following tables are data tables, all others are configuration tables"; echo "";echo "$DATATABLES";echo "";echo "running command $COMMAND --tables $TABLES | gzip > $DIR/zabbix_config_db.$DAY.gz"; echo ""; echo "`ls
-lat /srv/mysql/config_backup`") | /usr/sbin/sendmail jwu@domain.com