Ldirectord Mysql Replication Failover

file: /etc/ha.d/ldirector.cf

virtual = 10.0.0.1:3306
    real = 10.0.0.2:3306 gate
    fallback = 10.0.0.3:3306 gate
    login = "user"
    passwd = "pass"
    database = "database"
    checktype = external
    checkcommand = "/etc/ha.d/scripts/check_mysql_repl.sh"
    scheduler = wrr

 

file: /etc/ha.d/scripts/check_mysql_repl.sh

 

#!/bin/sh

virt_ip=$1
virt_port=$2
real_ip=$3
real_port=$4

EXITCODE=$(netcat -w 2 $real_ip $real_port > /dev/null 2>&1; echo $?)

if test $EXITCODE -eq 0; then
 SQLCMD="select if(variable_value = 'ON',0,1) from information_schema.global_status where variable_name = 'Slave_running'"
 EXITCODE=$(mysql -h $real_ip --port=$real_port -u <user> --password=<pass> --raw --batch --skip-column-names -e "$SQLCMD")
fi

if test $EXITCODE -eq 0; then
 SECONDS=$(mysql -e "show slave status\G" -h $real_ip --port=$real_port -u <user> --password=<pass> | grep "Seconds_Behind_Master" | awk '{ print $2 }')
 EXITCODE=$(( $SECONDS > 300 ))
fi

exit $EXITCODE;

 

 

 

Ldirectord Mysql Replication Failover

Xenial Dummy Interface -Workaround

For some reason Ubuntu 16.04 no longer excepts the numdummies=2 option in the /etc/modules files.

 

Work-Around:

Add the option separately:

 

1. Add the modules using one of the methods below

  • echo “dummy” > /etc/modules-load.d/dummy.conf
  • echo “dummy” >> /etc/modules

2. Add the module options in a separate file

  • echo “options dummy numdummies=2” > /etc/modprobe.d/dummy.conf
Xenial Dummy Interface -Workaround

Compress and prune directory of .avi

#!/bin/bash

#PREREQUISITES
#apt-get install cifs-utils
#apt-get install libav-tools

#fstab: \\server\videorecordings\ /media/videorecordings cifs username=<username>,password=<password>,iocharset=utf8,gid=1000,uid=1000,file_mode=0777,dir_mode=0777 0 0

dir=/media/videorecordings

#MAKE DIRECTORY IF MISSING
if [ ! -d $dir ]; then
mkdir -p $dir
fi

#MOUNT DIRECTORY IF DIRECTORY EXISTS AND IS EMPTY
if [[ -d $dir && ! “$(ls -A $dir)” ]]; then
mount $dir
fi

(
flock -n $FD

if [ $? -eq 0 ]; then

#Convert avi to mp4 to compress and save sapce
find /media/videorecordings/ -name *.avi -mtime +1 -exec avconv -y -i {} -vcodec libx264 -acodec libmp3lame -ac 2 {}.mp4 \; -exec rm {} -v \;

#Remove aged mp4 files
find /media/videorecordings/ -name *.mp4 -mtime +89 -exec rm {} \;

#Remove empty directories
find /media/videorecordings/ -type d -empty -delete

fi

) {FD}>/var/lock/prune_lock

Compress and prune directory of .avi

Zabbix External Check Time Comparison

OS: Ubuntu 14.04 LTS
Zabbix: 2.2.2

Enable External Checks:
mkdir -p /etc/zabbix/externalscripts
vi /etc/zabbix/zabbix-server.conf
add: ExternalScripts=/etc/zabbix/externalscripts
/etc/init.d/zabbix-server restart

Create External Check:
vi /etc/zabbix/externalscripts/timecheck.sh

if [ ! -z $1  ]; then
        SNMP_CMD="snmpget -Ov -c public -v1 $1 1.3.6.1.2.1.25.1.2.0"
        REMOTE_DATE=$($SNMP_CMD)
        REMOTE_DATE_HEX=$(echo ${REMOTE_DATE#Hex-STRING:})
        REMOTE_DATE_HEX_SIZE=${#REMOTE_DATE_HEX}

        if [ "$REMOTE_DATE_HEX_SIZE" -eq "23" ]; then # HANDLE SNMP TIMESTAMPS WITH AND WITHOUT TIMEZONE
                REMOTE_DATE_STR=$(perl -e '$octets = $ARGV[0]; $octets=~ s/ //g; $octets = pack("H*", $octets); @date = unpack("n C6 a C2",$octets); printf("%04d-%02d-%02d %02d:%02d:%02d.%d\n", @date);' "$REMOTE_DATE_HEX")
                else
                REMOTE_DATE_STR=$(perl -e '$octets = $ARGV[0]; $octets=~ s/ //g; $octets = pack("H*", $octets); @date = unpack("n C6 a C2",$octets); printf("%04d-%02d-%02d %02d:%02d:%02d.%d%s%02d:%02d\n", @date);' "$REMOTE_DATE_HEX")
        fi
        REMOTE_EPOCH=$(date -d "$REMOTE_DATE_STR" +"%s")
        LOCAL_EPOCH=$(date +%s);
        REMOTE_DIFF=$(echo "$REMOTE_EPOCH - $LOCAL_EPOCH" | bc)
        DIFF=$( echo $REMOTE_DIFF | tr -d -)
        echo "$DIFF
fi

Configure new Zabbix Item in Template or Host:

Name: Time Difference
Type: External check
Key: timecheck.sh[“{HOST.CONN}”]

Zabbix External Check Time Comparison