summaryrefslogtreecommitdiff
path: root/servers.py
blob: d2d7a506e4f2bb8ba44d1829c66755077d3caff3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python

import logging

from twisted.python.filepath import FilePath
from twisted.web import server, resource, http

class StatusSite(resource.Resource):
    isLeaf = True
    def __init__(self, statusTracker):
        resource.Resource.__init__(self)
        self.statusTracker = statusTracker
    def render_GET(self, request):
        if self.statusTracker.isMailGood() and self.statusTracker.isJobsGood():
            logging.debug("Indicating that everything seems to be okay")
            s = "True"
        elif not self.statusTracker.isMailGood():
            logging.warn("Indicating that we have a problem with Mail")
            s = "MailProblem"
        elif not self.statusTracker.isJobsGood():
            logging.warn("Indicating that we have a problem with Jobs")
            s = "JobProblem"

        request.setResponseCode(200)
        return s

class PingSite(resource.Resource):
    isLeaf = True
    def __init__(self, statusTracker):
        resource.Resource.__init__(self)
        self.statusTracker = statusTracker
    def render_POST(self, request):
        self.statusTracker.markJobRan()
        emailStatus = request.content.read()
        emailStatus = "True" in emailStatus
        
        logging.debug("Got notification of jobs ran")
        if emailStatus:
            logging.debug("Email is working")
        else:
            logging.warn("Email is _not_ working")

        self.statusTracker.markEmailStatus(emailStatus)
        request.setResponseCode(200)
        return "OK"