Skip to content
Snippets Groups Projects
Commit 2bfa3691 authored by nimrod's avatar nimrod
Browse files

- Initial commit.

parents
No related branches found
No related tags found
No related merge requests found
MIT License
Copyright (c) 2016 Adar Nimrod
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
recursive-include check_mysql_slave *.py
exclude .pre-commit-config.yaml
include *.rst
include VERSION
include *.txt
check_mysql_slave
#################
Check MySQL seconds behind master for Nagios-like monitoring.
Usage
-----
.. code:: shell
$ check_mysql_slave --help
usage: check_mysql_slave [-h] -u [USER] -p [PASSWORD] [--host [HOST]]
[--port PORT]
[warning_threshold] [critical_threshold]
positional arguments:
warning_threshold Warning threshold (defaults to 60)
critical_threshold Critical threshold (defualts to 300)
optional arguments:
-h, --help show this help message and exit
-u [USER], --user [USER]
Login username
-p [PASSWORD], --password [PASSWORD]
Login password
--host [HOST] Login host
--port PORT Login port
License
-------
This software is licensed under the MIT license (see the :code:`LICENSE.txt`
file).
Author
------
Nimrod Adar, `contact me <nimrod@shore.co.il>`_ or visit my `website
<https://www.shore.co.il/>`_. Patches are welcome via `git send-email
<http://git-scm.com/book/en/v2/Git-Commands-Email>`_. The repository is located
at: https://www.shore.co.il/git/.
0.0.1
#!/usr/bin/env python
'''Check MySQL seconds behind master for Nagios-like monitoring.'''
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import argparse
from argparse import ArgumentParser
try:
from MySQLdb import connect
except ImportError:
print('Failed to import MySQLdb. Is mysqlclient installed?')
exit(3)
def getSlaveStatus(host, user, passwd, port):
'''Returns a dictionary of the 'SHOW SLAVE STATUS;' command output.'''
try:
conn = connect(user=user, passwd=passwd, host=host, port=port)
except BaseException as e:
print('Failed to connect.')
exit(3)
cur = conn.cursor()
cur.execute('''SHOW SLAVE STATUS;''')
keys = [desc[0] for desc in cur.description]
values = cur.fetchone()
return dict(zip(keys, values))
def main():
parser = ArgumentParser()
parser.add_argument('-u',
'--user',
help='Login username',
required=True,
nargs='?')
parser.add_argument('-p',
'--password',
help='Login password',
required=True,
nargs='?')
parser.add_argument('--host',
help='Login host',
nargs='?',
default='localhost')
parser.add_argument('--port',
help='Login port',
nargs=1,
type=int,
default=3306)
parser.add_argument('warning_threshold',
help='Warning threshold (defaults to 60)',
default=60,
type=int,
nargs='?')
parser.add_argument('critical_threshold',
help='Critical threshold (defualts to 300)',
default=300,
type=int,
nargs='?')
args = parser.parse_args()
status = getSlaveStatus(host=args.host,
user=args.user,
passwd=args.password,
port=args.port)
if not 'Slave_IO_Running' in status or not 'Slave_SQL_Running' in status or not status[
'Slave_IO_Running'] == 'Yes' or not status[
'Slave_SQL_Running'] == 'Yes':
print('Replication is turned off.')
exit(0)
lag = status['Seconds_Behind_Master']
if lag > args.critical_threshold:
print('Seconds behind master is above the critical threshold.')
exit(2)
elif lag > args.warning_threshold:
print('Seconds behind master is above the warning threshold.')
exit(1)
else:
print('Seconds behind master is below the warning threshold.')
exit(0)
if __name__ == '__main__':
main()
[bdist_wheel]
universal=1
[flake8]
exclude = .tox,*.egg,build,data
select = E,W,F
setup.py 0 → 100644
#!/usr/bin/env python
from setuptools import setup, find_packages
setup(
name='check_mysql_slave',
version=open('VERSION', 'r').read(),
description='''Check MySQL seconds behind master for Nagios-like
monitoring.''',
long_description=open('README.rst', 'r').read(),
url='https://www.shore.co.il/git/check_mysql_slave',
author='Nimrod Adar',
author_email='nimrod@shore.co.il',
license='MIT',
classifiers=[
'Development status :: 4 - Beta',
'Intended Audience :: System Administrators',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 2',
'Topic :: Utilities',
'License :: OSI Approved :: MIT License'
],
keywords='nagios mysql slave replication monitoring',
packages=find_packages(),
install_requires=['MySQL-python'],
entry_points={
'console_scripts': [
'check_mysql_slave=check_mysql_slave:main'], },
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment