launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #30488
[Merge] ~cjwatson/launchpad:remove-script-monitor into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:remove-script-monitor into launchpad:master.
Commit message:
Remove script-monitor
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/451918
The same underlying data is now monitored using Prometheus instead.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:remove-script-monitor into launchpad:master.
diff --git a/database/sampledata/current-dev.sql b/database/sampledata/current-dev.sql
index e4d13cd..79e3303 100644
--- a/database/sampledata/current-dev.sql
+++ b/database/sampledata/current-dev.sql
@@ -8947,8 +8947,6 @@ ALTER TABLE public.revisionstatusartifact ENABLE TRIGGER ALL;
ALTER TABLE public.scriptactivity DISABLE TRIGGER ALL;
-INSERT INTO public.scriptactivity (id, name, hostname, date_started, date_completed) VALUES (1, 'launchpad-targetnamecacheupdater', 'whatever', '2007-08-08 17:02:22.963565', '2007-08-08 17:02:23.869575');
-INSERT INTO public.scriptactivity (id, name, hostname, date_started, date_completed) VALUES (2, 'script-monitor-test', 'localhost', '2007-05-23 00:00:00', '2007-05-23 01:00:00');
ALTER TABLE public.scriptactivity ENABLE TRIGGER ALL;
diff --git a/database/sampledata/current.sql b/database/sampledata/current.sql
index 37d089b..6cb1534 100644
--- a/database/sampledata/current.sql
+++ b/database/sampledata/current.sql
@@ -8861,8 +8861,6 @@ ALTER TABLE public.revisionstatusartifact ENABLE TRIGGER ALL;
ALTER TABLE public.scriptactivity DISABLE TRIGGER ALL;
-INSERT INTO public.scriptactivity (id, name, hostname, date_started, date_completed) VALUES (1, 'launchpad-targetnamecacheupdater', 'whatever', '2007-08-08 17:02:22.963565', '2007-08-08 17:02:23.869575');
-INSERT INTO public.scriptactivity (id, name, hostname, date_started, date_completed) VALUES (2, 'script-monitor-test', 'localhost', '2007-05-23 00:00:00', '2007-05-23 01:00:00');
ALTER TABLE public.scriptactivity ENABLE TRIGGER ALL;
diff --git a/lib/lp/scripts/scriptmonitor.py b/lib/lp/scripts/scriptmonitor.py
deleted file mode 100644
index 02bf2ac..0000000
--- a/lib/lp/scripts/scriptmonitor.py
+++ /dev/null
@@ -1,50 +0,0 @@
-# Copyright 2009 Canonical Ltd. This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""Monitor whether scripts have run between specified time periods."""
-
-__all__ = ["check_script"]
-
-from lp.services.database.sqlbase import sqlvalues
-
-
-def check_script(con, log, hostname, scriptname, completed_from, completed_to):
- """Check whether a script ran on a specific host within stated timeframe.
-
- Return nothing on success, or log an error message and return error
- message.
- """
- cur = con.cursor()
- cur.execute(
- """
- SELECT id
- FROM ScriptActivity
- WHERE hostname=%s AND name=%s
- AND date_completed BETWEEN %s AND %s
- LIMIT 1
- """
- % sqlvalues(hostname, scriptname, completed_from, completed_to)
- )
- try:
- cur.fetchone()[0]
- return None
- except TypeError:
- output = "The script '%s' didn't run on '%s' between %s and %s" % (
- scriptname,
- hostname,
- completed_from,
- completed_to,
- )
- cur.execute(
- """
- SELECT MAX(date_completed)
- FROM ScriptActivity
- WHERE hostname=%s AND name=%s
- """
- % sqlvalues(hostname, scriptname)
- )
- date_last_seen = cur.fetchone()[0]
- if date_last_seen is not None:
- output += " (last seen %s)" % (date_last_seen,)
- log.fatal(output)
- return output
diff --git a/lib/lp/scripts/tests/test_scriptmonitor.py b/lib/lp/scripts/tests/test_scriptmonitor.py
deleted file mode 100644
index 7cefe5f..0000000
--- a/lib/lp/scripts/tests/test_scriptmonitor.py
+++ /dev/null
@@ -1,82 +0,0 @@
-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""Test scriptmonitor.py."""
-
-from unittest import TestCase
-
-from lp.scripts.scriptmonitor import check_script
-from lp.services.database.sqlbase import connect
-from lp.services.scripts import logger
-from lp.testing.layers import DatabaseLayer
-
-
-class CheckScriptTestCase(TestCase):
- """Test script activity."""
-
- layer = DatabaseLayer
-
- def setUp(self):
- # We need some fake options so that this test doesn't try to parse
- # sys.args. We don't care about the log messages, so just throw them
- # away.
- class FakeOptions:
- log_file = None
- loglevel = 1000
- verbose = False
- milliseconds = False
-
- self.con = connect()
- self.log = logger(FakeOptions())
-
- def tearDown(self):
- self.con.close()
-
- def test_scriptfound(self):
- self.assertEqual(
- check_script(
- self.con,
- self.log,
- "localhost",
- "script-monitor-test",
- "2007-05-23 00:30:00",
- "2007-05-23 01:30:00",
- ),
- None,
- )
-
- def test_scriptnotfound_timing(self):
- output = (
- "The script 'script-monitor-test' didn't run on "
- "'localhost' between 2007-05-23 01:30:00 and "
- "2007-05-23 02:30:00 (last seen 2007-05-23 01:00:00)"
- )
- self.assertEqual(
- check_script(
- self.con,
- self.log,
- "localhost",
- "script-monitor-test",
- "2007-05-23 01:30:00",
- "2007-05-23 02:30:00",
- ),
- output,
- )
-
- def test_scriptnotfound_hostname(self):
- output = (
- "The script 'script-monitor-test' didn't run on "
- "'notlocalhost' between 2007-05-23 00:30:00 and "
- "2007-05-23 01:30:00"
- )
- self.assertEqual(
- check_script(
- self.con,
- self.log,
- "notlocalhost",
- "script-monitor-test",
- "2007-05-23 00:30:00",
- "2007-05-23 01:30:00",
- ),
- output,
- )
diff --git a/scripts/script-monitor-nagios.py b/scripts/script-monitor-nagios.py
deleted file mode 100755
index 6832c44..0000000
--- a/scripts/script-monitor-nagios.py
+++ /dev/null
@@ -1,105 +0,0 @@
-#!/usr/bin/python3 -S
-#
-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""Nagios plugin for script monitoring.
-
-This script is needed as separate from script-monitor.py because Nagios
-only understands one line of returned text, and interprets specific
-return codes as plugin statuses. These are:
-
- 0: OK
- 1: WARNING
- 2: CRITICAL
- 3: UNKNOWN
-
-As such, it was felt more appropriate to separate out the scripts,
-even though there is some code duplication.
-"""
-
-__all__ = ["check_script"]
-
-import _pythonpath # noqa: F401
-
-import sys
-from datetime import datetime, timedelta
-from optparse import OptionParser
-from time import strftime
-
-from lp.scripts.scriptmonitor import check_script
-from lp.services.database.sqlbase import connect
-from lp.services.scripts import db_options, logger, logger_options
-
-
-def main():
- # XXX: Tom Haddon 2007-07-12
- # There's a lot of untested stuff here: parsing options -
- # this should be moved into a testable location.
- # Also duplicated code in scripts/script-monitor.py
- parser = OptionParser(
- "%prog [options] (minutes) (host:scriptname) [host:scriptname]"
- )
- db_options(parser)
- logger_options(parser)
-
- (options, args) = parser.parse_args()
-
- if len(args) < 2:
- print("Must specify time in minutes and at least one host and script")
- return 3
-
- # First argument is the number of minutes into the past
- # we want to look for the scripts on the specified hosts
- try:
- minutes_ago, args = int(args[0]), args[1:]
- start_date = datetime.now() - timedelta(minutes=minutes_ago)
-
- completed_from = strftime("%Y-%m-%d %H:%M:%S", start_date.timetuple())
- completed_to = strftime(
- "%Y-%m-%d %H:%M:%S", datetime.now().timetuple()
- )
-
- hosts_scripts = []
- for arg in args:
- try:
- hostname, scriptname = arg.split(":")
- except TypeError:
- print("%r is not in the format 'host:scriptname'" % arg)
- return 3
- hosts_scripts.append((hostname, scriptname))
- except ValueError:
- print("Must specify time in minutes and at least one host and script")
- return 3
-
- log = logger(options)
-
- try:
- log.debug("Connecting to database")
- con = connect()
- error_found = False
- msg = []
- for hostname, scriptname in hosts_scripts:
- failure_msg = check_script(
- con, log, hostname, scriptname, completed_from, completed_to
- )
- if failure_msg is not None:
- msg.append("%s:%s" % (hostname, scriptname))
- error_found = True
- if error_found:
- # Construct our return message
- print("Scripts failed to run: %s" % ", ".join(msg))
- return 2
- else:
- # Construct our return message
- print("All scripts ran as expected")
- return 0
- except Exception as e:
- # Squeeze the exception type and stringification of the exception
- # value on to one line.
- print("Unhandled exception: %s %r" % (e.__class__.__name__, str(e)))
- return 3
-
-
-if __name__ == "__main__":
- sys.exit(main())
diff --git a/scripts/script-monitor.py b/scripts/script-monitor.py
deleted file mode 100755
index b89e306..0000000
--- a/scripts/script-monitor.py
+++ /dev/null
@@ -1,107 +0,0 @@
-#!/usr/bin/python3 -S
-#
-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""Monitor scripts."""
-
-__all__ = ["check_script"]
-
-import _pythonpath # noqa: F401
-
-import smtplib
-import sys
-from datetime import datetime, timedelta
-from email.mime.text import MIMEText
-from optparse import OptionParser
-from time import strftime
-
-from lp.scripts.scriptmonitor import check_script
-from lp.services.database.sqlbase import connect
-from lp.services.scripts import db_options, logger, logger_options
-
-
-def main():
- # XXX: Tom Haddon 2007-07-12
- # There's a lot of untested stuff here: parsing options and sending
- # emails - this should be moved into a testable location.
- # Also duplicated code in scripts/script-monitor-nagios.py
- parser = OptionParser(
- "%prog [options] (minutes) (host:scriptname) [host:scriptname]"
- )
- db_options(parser)
- logger_options(parser)
-
- (options, args) = parser.parse_args()
-
- if len(args) < 2:
- parser.error(
- "Must specify at time in minutes and "
- "at least one host and script"
- )
-
- # First argument is the number of minutes into the past
- # we want to look for the scripts on the specified hosts
- try:
- minutes_ago, args = int(args[0]), args[1:]
- start_date = datetime.now() - timedelta(minutes=minutes_ago)
-
- completed_from = strftime("%Y-%m-%d %H:%M:%S", start_date.timetuple())
- completed_to = strftime(
- "%Y-%m-%d %H:%M:%S", datetime.now().timetuple()
- )
-
- hosts_scripts = []
- for arg in args:
- try:
- hostname, scriptname = arg.split(":")
- except TypeError:
- parser.error(
- "%r is not in the format 'host:scriptname'" % (arg,)
- )
- hosts_scripts.append((hostname, scriptname))
- except ValueError:
- parser.error(
- "Must specify time in minutes and " "at least one host and script"
- )
-
- log = logger(options)
-
- try:
- log.debug("Connecting to database")
- con = connect()
- error_found = False
- msg, subj = [], []
- for hostname, scriptname in hosts_scripts:
- failure_msg = check_script(
- con, log, hostname, scriptname, completed_from, completed_to
- )
- if failure_msg is not None:
- msg.append(failure_msg)
- subj.append("%s:%s" % (hostname, scriptname))
- error_found = 2
- if error_found:
- # Construct our email.
- msg = MIMEText("\n".join(msg))
- msg["Subject"] = "Scripts failed to run: %s" % ", ".join(subj)
- msg["From"] = "script-failures@xxxxxxxxxxxxx"
- msg["Reply-To"] = "canonical-launchpad@xxxxxxxxxxxxxxxxxxx"
- msg["To"] = "launchpad-error-reports@xxxxxxxxxxxxxxxxxxx"
-
- # Send out the email.
- smtp = smtplib.SMTP()
- smtp.connect()
- smtp.sendmail(
- "script-failures@xxxxxxxxxxxxx",
- ["launchpad-error-reports@xxxxxxxxxxxxxxxxxxx"],
- msg.as_string(),
- )
- smtp.close()
- return 2
- except Exception:
- log.exception("Unhandled exception")
- return 1
-
-
-if __name__ == "__main__":
- sys.exit(main())