~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to scripts/script-monitor-nagios.py

  • Committer: Stuart Bishop
  • Date: 2011-09-28 12:49:24 UTC
  • mfrom: (9893.10.1 trivial)
  • mto: This revision was merged to the branch mainline in revision 14178.
  • Revision ID: stuart.bishop@canonical.com-20110928124924-m5a22fymqghw6c5i
Merged trivial into distinct-db-users.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python -S
2
2
#
3
 
# Copyright 2009 Canonical Ltd.  This software is licensed under the
 
3
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
4
4
# GNU Affero General Public License version 3 (see the file LICENSE).
5
5
 
6
6
"""Nagios plugin for script monitoring.
21
21
__metaclass__ = type
22
22
__all__ = ['check_script']
23
23
 
24
 
import _pythonpath
25
 
 
26
 
from datetime import datetime, timedelta
 
24
from datetime import (
 
25
    datetime,
 
26
    timedelta,
 
27
    )
27
28
from optparse import OptionParser
 
29
import sys
28
30
from time import strftime
29
 
import sys
 
31
 
 
32
import _pythonpath
30
33
 
31
34
from canonical.database.sqlbase import connect
32
 
from canonical.launchpad.scripts import db_options, logger_options, logger
 
35
from canonical.launchpad.scripts import (
 
36
    db_options,
 
37
    logger,
 
38
    logger_options,
 
39
    )
33
40
from canonical.launchpad.scripts.scriptmonitor import check_script
34
41
 
35
42
 
58
65
        start_date = datetime.now() - timedelta(minutes=minutes_ago)
59
66
 
60
67
        completed_from = strftime("%Y-%m-%d %H:%M:%S", start_date.timetuple())
61
 
        completed_to = strftime("%Y-%m-%d %H:%M:%S", datetime.now().timetuple())
 
68
        completed_to = strftime(
 
69
            "%Y-%m-%d %H:%M:%S", datetime.now().timetuple())
62
70
 
63
71
        hosts_scripts = []
64
72
        for arg in args:
95
103
            print "All scripts ran as expected"
96
104
            return 0
97
105
    except Exception, e:
98
 
        # Squeeze the exception type and stringification of the exception value
99
 
        # on to one line.
 
106
        # Squeeze the exception type and stringification of the exception
 
107
        # value on to one line.
100
108
        print "Unhandled exception: %s %r" % (e.__class__.__name__, str(e))
101
109
        return 3
102
110