示例#1
0
文件: rhnTB.py 项目: flavio/spacewalk
def exitWithTraceback(e, msg, exitnum, mail=0):
    tbOut = StringIO()
    Traceback(mail, ostream=tbOut, with_locals=1)
    log_error(-1, _('ERROR: %s %s: %s') %
              (e.__class__.__name__, msg, e))
    log_error(-1, _('TRACEBACK: %s') % tbOut.getvalue())
    sys.exit(exitnum)
示例#2
0
def send(headers, body, sender = None, lazy = 0):
    headers = __check_headers(headers)

    sendmail = "/usr/sbin/sendmail"
    cmds = ["sendmail", "-oi", "-t"]
    if sender:
        cmds.append("-f%s" % sender)
    if lazy:
        cmds.append("-ODeliveryMode=q")
        
    (read, write) = os.pipe()
    childpid = os.fork()
    if childpid < 0: # fork failed
        log_error("ERROR: fork of sendmail process failed.\nAlert being sent:\n%s" % body)
        return -1
    if childpid == 0:
        # in the child
        os.dup2(read, 0)
        os.close(write)
        os.execv(sendmail, cmds)
        # not reached
        sys.exit(1)
    # main process
    os.close(read)
    # Now write the message out
    keys = headers.keys()
    keys.sort()
    for h in keys:
        os.write(write, "%s: %s\n" % (h, headers[h]))
    os.write(write, "\n%s\n" % body)
    os.close(write)
    # clean up
    (pid, status) = os.waitpid(childpid, 0)    
    return status
示例#3
0
    def _init_request_processor(self, req):
        # first, make sure we only allow certain methods
        if req.method == "GET":
            # This is a request from a cache/client, so verify the signature,
            # system_id, and expiration exist and push into rhnFlags.
            token = self._setSessionToken(req.headers_in)
            if token is None:
                return apache.HTTP_METHOD_NOT_ALLOWED
            return apache.OK

        elif req.method == "POST":
            return apache.OK

        elif req.method == "HEAD":
            # We should only receive this type of request from ourself.
            return apache.OK

        log_error("Unknown HTTP method", req.method)
        return apache.HTTP_METHOD_NOT_ALLOWED
示例#4
0
    def _init_request_processor(self, req):
        # first, make sure we only allow certain methods
        if req.method == "GET":
            # This is a request from a cache/client, so verify the signature,
            # system_id, and expiration exist and push into rhnFlags.
            token = self._setSessionToken(req.headers_in)
            if token is None:
                return apache.HTTP_METHOD_NOT_ALLOWED
            return apache.OK

        elif req.method == "POST":
            return apache.OK

        elif req.method == "HEAD":
            # We should only receive this type of request from ourself.
            return apache.OK

        log_error("Unknown HTTP method", req.method)
        return apache.HTTP_METHOD_NOT_ALLOWED
示例#5
0
def exitWithTraceback(e, msg, exitnum, mail=0):
    tbOut = StringIO()
    Traceback(mail, ostream=tbOut, with_locals=1)
    log_error(-1, _('ERROR: %s %s: %s') % (e.__class__.__name__, msg, e))
    log_error(-1, _('TRACEBACK: %s') % tbOut.getvalue())
    sys.exit(exitnum)