File: //proc/self/root/lib/python2.7/site-packages/lap/check_mysql_command.py
import MySQLdb
def __run__(params):
user = params.get("mysql_user")
password = params.get("mysql_password")
host = params.get('mysql_host')
check_command = params.get("mysql_query")
expected_string = params.get("mysql_value")
try:
if all([user, password, check_command]):
connection = MySQLdb.connect(host, user, password)
cursor = connection.cursor()
cursor.execute(check_command)
result = cursor.fetchone()
field, value = result
if not result:
return([2, "Critical: MySQL query error!"])
elif value != expected_string:
return([2, "Critical: %s" % params.get("error_msg")])
else:
return([0, "OK"])
except Exception, err:
return([2, "Critical: %s" % err])