File: //usr/lib/python2.7/site-packages/lap/mysql_replication.py
#!/usr/bin/python
import MySQLdb
import yaml
def __run__(params):
conn = None
##Get yaml info
db_thresholds = yaml.load(params.get('thresholds'))
db_host=params.get('host')
db_port=int(params.get('port'))
#Connect_db
try:
f = params.get("defaults-file", "/etc/check_mk/mysql.cfg")
conn = MySQLdb.connect(read_default_file=f)
cursor = conn.cursor()
cursor.execute( "SHOW SLAVE STATUS" )
row = cursor.fetchone()
Slave_IO_Running = row[10]
Slave_SQL_Running = row[11]
Last_Error = row[19]
Seconds_Behind_Master = row[32]
# check if a backup is running
cursor.execute("SELECT COUNT(1) mysqldumpThreads FROM information_schema.processlist WHERE info LIKE 'SELECT /*!40001 SQL_NO_CACHE */%'")
row = row = cursor.fetchone()
mysqldumpThreads = row[0]
if mysqldumpThreads != 0:
return [1, 'WARNING: Replication is delayed - Backup is running!']
elif Slave_SQL_Running != 'Yes':
return [2, 'CRITICAL - Slave SQL Running: %s - Slave is not running' % (Slave_SQL_Running)]
elif Seconds_Behind_Master >= db_thresholds['critical']:
return [2, 'CRITICAL: Seconds Behind Master: %s' % (Seconds_Behind_Master)]
elif int(Seconds_Behind_Master) >= db_thresholds['warning']:
return [1, 'WARNING: Seconds Behind Master: %s' % (Seconds_Behind_Master)]
else:
return [0, 'OK Seconds_Behind_Master: %s' % (Seconds_Behind_Master)]
except Exception, e:
return [2,'CRITICAL: %s' % repr(e)]