mirror of https://github.com/zulip/zulip.git
nagios: Replace check_fts_update_log with a process_fts_updates flag.
This avoids having to duplicate the connection logic from process_fts_updates. Co-authored-by: Adam Birds <adam.birds@adbwebdesigns.co.uk>
This commit is contained in:
parent
ab130ceb35
commit
4f017614c5
|
@ -1,40 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Nagios plugin to check the length of the FTS update log.
|
||||
"""
|
||||
import sys
|
||||
|
||||
sys.path.append("/home/zulip/deployments/current")
|
||||
try:
|
||||
from scripts.lib.setup_path import setup_path
|
||||
|
||||
setup_path()
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
import psycopg2
|
||||
|
||||
states = {
|
||||
"OK": 0,
|
||||
"WARNING": 1,
|
||||
"CRITICAL": 2,
|
||||
"UNKNOWN": 3,
|
||||
}
|
||||
|
||||
|
||||
def report(state: str, num: str) -> None:
|
||||
print(f"{state}: {num} rows in fts_update_log table")
|
||||
exit(states[state])
|
||||
|
||||
|
||||
conn = psycopg2.connect(database="zulip")
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("SELECT count(*) FROM fts_update_log")
|
||||
num = cursor.fetchall()[0][0]
|
||||
|
||||
if num > 5:
|
||||
report("CRITICAL", num)
|
||||
|
||||
report("OK", num)
|
|
@ -41,6 +41,7 @@ BATCH_SIZE = 1000
|
|||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--quiet", action="store_true")
|
||||
parser.add_argument("--nagios-check", action="store_true")
|
||||
options = parser.parse_args()
|
||||
|
||||
logging.Formatter.converter = time.gmtime
|
||||
|
@ -135,6 +136,28 @@ except ImportError:
|
|||
pg_args["host"] = "localhost"
|
||||
pg_args["dbname"] = get_config(config_file, "postgresql", "database_name", "zulip")
|
||||
|
||||
|
||||
if options.nagios_check:
|
||||
conn = psycopg2.connect(**pg_args)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT count(*) FROM fts_update_log")
|
||||
num = cursor.fetchall()[0][0]
|
||||
|
||||
# nagios exit codes
|
||||
states = {
|
||||
"OK": 0,
|
||||
"WARNING": 1,
|
||||
"CRITICAL": 2,
|
||||
"UNKNOWN": 3,
|
||||
}
|
||||
|
||||
state = "OK"
|
||||
if num > 5:
|
||||
state = "CRITICAL"
|
||||
print(f"{state}: {num} rows in fts_update_log table")
|
||||
exit(states[state])
|
||||
|
||||
|
||||
conn = None
|
||||
|
||||
retries = 1
|
||||
|
|
|
@ -153,7 +153,7 @@ define command {
|
|||
|
||||
define command {
|
||||
command_name check_fts_update_log
|
||||
command_line /usr/lib/nagios/plugins/check_by_ssh -l nagios -t 30 -i /var/lib/nagios/.ssh/id_ed25519 -H $HOSTADDRESS$ -C '/usr/lib/nagios/plugins/zulip_postgresql/check_fts_update_log'
|
||||
command_line /usr/lib/nagios/plugins/check_by_ssh -l nagios -t 30 -i /var/lib/nagios/.ssh/id_ed25519 -H $HOSTADDRESS$ -C '/usr/local/bin/process_fts_updates --nagios-check'
|
||||
}
|
||||
|
||||
define command {
|
||||
|
|
|
@ -123,7 +123,7 @@ echo
|
|||
echo "Now running additional Nagios tests"
|
||||
echo
|
||||
if ! /usr/lib/nagios/plugins/zulip_app_frontend/check_queue_worker_errors \
|
||||
|| ! su zulip -c /usr/lib/nagios/plugins/zulip_postgresql/check_fts_update_log; then # || \
|
||||
|| ! su zulip -c "/usr/local/bin/process_fts_updates --nagios-check"; then # || \
|
||||
# ! su zulip -c "/usr/lib/nagios/plugins/zulip_app_frontend/check_send_receive_time --site=https://127.0.0.1/api --nagios --insecure"; then
|
||||
set +x
|
||||
echo
|
||||
|
|
Loading…
Reference in New Issue