~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to scripts/script-monitor.py

  • Committer: Tom Haddon
  • Date: 2007-06-26 17:42:59 UTC
  • mto: This revision was merged to the branch mainline in revision 5016.
  • Revision ID: tom.haddon@canonical.com-20070626174259-z07ul8uc34r3l0jh
Checking command line options

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
"""Monitor scripts."""
5
5
 
6
6
__metaclass__ = type
7
 
__all__ = []
 
7
__all__ = ['check_script']
8
8
 
9
9
import _pythonpath
10
10
 
43
43
            """ % (hostname, scriptname))
44
44
            date_last_seen = cur.fetchone()[0]
45
45
            log.fatal(
46
 
                "The script '%s' didn't run on '%s' between %s and %s (last seen %s)"
47
 
                    % (scriptname, hostname, completed_from, completed_to, date_last_seen)
 
46
                "The script '%s' didn't run on '%s' between "
 
47
                "%s and %s (last seen %s)"
 
48
                    % (scriptname, hostname, completed_from, 
 
49
                        completed_to, date_last_seen)
48
50
                )
49
51
        except:
50
52
            log.fatal(
51
 
                "The script '%s' didn't run on '%s' between %s and %s" 
 
53
                "The script '%s' didn't run on '%s' between %s and %s"
52
54
                    % (scriptname, hostname, completed_from, completed_to)
53
55
                )
54
56
        return False
55
57
 
56
58
def main():
57
59
    parser = OptionParser(
58
 
            '%prog [options] (username|email) [...]'
 
60
            '%prog [options] (minutes) (host:scriptname) [host:scriptname]'
59
61
            )
60
62
    db_options(parser)
61
63
    logger_options(parser)
62
64
 
63
65
    (options, args) = parser.parse_args()
64
66
 
65
 
    if len(args) == 0:
66
 
        parser.error("Must specify at least one host and script")
 
67
    if len(args) < 2:
 
68
        parser.error("Must specify at time in minutes and "
 
69
            "at least one host and script")
67
70
 
68
71
    # First argument is the number of minutes into the past
69
72
    # we want to look for the scripts on the specified hosts
70
 
    minutes_ago, args = int(args[0]), args[1:]
71
 
    start_date = datetime.now() - timedelta(minutes=minutes_ago)
72
 
 
73
 
    completed_from = strftime("%Y-%m-%d %H:%M:%S", start_date.timetuple())
74
 
    completed_to = strftime("%Y-%m-%d %H:%M:%S", datetime.now().timetuple())
 
73
    try:
 
74
        minutes_ago, args = int(args[0]), args[1:]
 
75
        start_date = datetime.now() - timedelta(minutes=minutes_ago)
 
76
 
 
77
        completed_from = strftime("%Y-%m-%d %H:%M:%S", start_date.timetuple())
 
78
        completed_to = strftime("%Y-%m-%d %H:%M:%S", datetime.now().timetuple())
 
79
 
 
80
        for arg in args:
 
81
            if len(arg.split(":")) != 2:
 
82
                raise
 
83
    except:
 
84
        parser.error("Must specify at time in minutes and "
 
85
            "at least one host and script")
75
86
 
76
87
    log = logger(options)
77
88
 
88
99
 
89
100
        error_found = 0
90
101
        for hs in hosts_scripts:
91
 
            if not check_script(con, log, hs['hostname'], hs['scriptname'], completed_from, completed_to):
 
102
            if not check_script(con, log, hs['hostname'], hs['scriptname'],
 
103
                completed_from, completed_to):
92
104
                error_found = 1
93
105
        return error_found
94
106
    except: