commit aa17162871c6bfd65cc4f8ac3206e906252dfc12 Author: benoit Date: Fri Jul 2 12:34:28 2021 +0200 Initial commit diff --git a/check_patroni/__init__.py b/check_patroni/__init__.py new file mode 100644 index 0000000..f102a9c --- /dev/null +++ b/check_patroni/__init__.py @@ -0,0 +1 @@ +__version__ = "0.0.1" diff --git a/check_patroni/__main__.py b/check_patroni/__main__.py new file mode 100644 index 0000000..9ae637f --- /dev/null +++ b/check_patroni/__main__.py @@ -0,0 +1,4 @@ +from .cli import main + +if __name__ == "__main__": + main() diff --git a/check_patroni/cli.py b/check_patroni/cli.py new file mode 100644 index 0000000..036c39f --- /dev/null +++ b/check_patroni/cli.py @@ -0,0 +1,17 @@ +import requests + + +def check_is_master(address: str = "127.0.0.1", port: int = 8008): + r = requests.get(f"{address}:{int(port)}/leader") + return r.status_code == 200 + + +def check_is_replica(address: str = "127.0.0.1", port: int = 8008): + r = requests.get(f"{address}:{int(port)}/replica") + return r.status_code == 200 + + +def main() -> None: + print(check_is_master()) + print(check_is_replica()) + print("allgood") diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..2c2f93a --- /dev/null +++ b/setup.py @@ -0,0 +1,54 @@ +import pathlib + +from setuptools import find_packages, setup + +HERE = pathlib.Path(__file__).parent + +long_description = (HERE / "README.md").read_text() + + +def get_version() -> str: + fpath = HERE / "check_patroni" / "__init__.py" + with fpath.open() as f: + for line in f: + if line.startswith("__version__"): + return line.split('"')[1] + raise Exception(f"version information not found in {fpath}") + + +setup( + name="check_patroni", + version=get_version(), +# author="Dalibo", +# author_email="contact@dalibo.com", + packages=find_packages("."), + include_package_data=True, +# url="https://github.com/dalibo/pg_activity", + license="PostgreSQL", + description="Nagios plugin to check on patroni", + long_description=long_description, + long_description_content_type="text/markdown", +# classifiers=[ +# "Development Status :: 5 - Production/Stable", +# "Environment :: Console", +# "License :: OSI Approved :: PostgreSQL License", +# "Programming Language :: Python :: 3", +# "Topic :: Database", +# ], + keywords="patroni nagios cehck", + python_requires=">=3.6", + extras_require={ + "dev": [ + "black", + "check-manifest", + "flake8", + "mypy", + ], + }, + entry_points={ + "console_scripts": [ + "check_patroni=check_patroni.cli:main", + ], + }, + zip_safe=False, +)