2013-04-16 20:07:53 +02:00
|
|
|
import time
|
2019-07-23 23:58:11 +02:00
|
|
|
from typing import Tuple
|
2016-07-30 01:09:08 +02:00
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def nagios_from_file(results_file: str) -> Tuple[int, str]:
|
2013-04-16 20:07:53 +02:00
|
|
|
"""Returns a nagios-appropriate string and return code obtained by
|
|
|
|
parsing the desired file on disk. The file on disk should be of format
|
|
|
|
|
|
|
|
%s|%s % (timestamp, nagios_string)
|
|
|
|
|
|
|
|
This file is created by various nagios checking cron jobs such as
|
|
|
|
check-rabbitmq-queues and check-rabbitmq-consumers"""
|
|
|
|
|
2019-08-29 23:15:35 +02:00
|
|
|
try:
|
|
|
|
with open(results_file) as f:
|
|
|
|
data = f.read().strip()
|
|
|
|
except FileNotFoundError:
|
2021-02-12 08:20:45 +01:00
|
|
|
state = "UNKNOWN"
|
2013-04-16 20:07:53 +02:00
|
|
|
ret = 3
|
2019-08-29 23:15:35 +02:00
|
|
|
data = "Results file is missing"
|
2013-04-16 20:07:53 +02:00
|
|
|
else:
|
2021-02-12 08:20:45 +01:00
|
|
|
pieces = data.split("|")
|
2013-04-16 20:07:53 +02:00
|
|
|
|
2019-08-29 23:15:35 +02:00
|
|
|
if not len(pieces) == 4:
|
2021-02-12 08:20:45 +01:00
|
|
|
state = "UNKNOWN"
|
2019-08-29 23:15:35 +02:00
|
|
|
ret = 3
|
|
|
|
data = "Results file malformed"
|
2013-04-16 20:07:53 +02:00
|
|
|
else:
|
2019-08-29 23:15:35 +02:00
|
|
|
timestamp = int(pieces[0])
|
|
|
|
|
|
|
|
time_diff = time.time() - timestamp
|
|
|
|
if time_diff > 60 * 2:
|
|
|
|
ret = 3
|
2021-02-12 08:20:45 +01:00
|
|
|
state = "UNKNOWN"
|
2019-08-29 23:15:35 +02:00
|
|
|
data = "Results file is stale"
|
|
|
|
else:
|
|
|
|
ret = int(pieces[1])
|
|
|
|
state = pieces[2]
|
|
|
|
data = pieces[3]
|
2013-04-16 20:07:53 +02:00
|
|
|
|
2020-06-10 06:41:04 +02:00
|
|
|
return (ret, f"{state}: {data}")
|