Ejemplo n.º 1
0
    def formatException(self, ei):
        etype, exc, tb = ei
        exception_list = traceback2.extract_tb(tb, extract_locals=True)
        if tb:
            caught_list = traceback2.extract_stack(tb.tb_frame)
        else:
            caught_list = traceback2.extract_stack(up=2)
        formatted_exception = traceback2.format_exception_only(etype, exc)
        stack, stackID = GetStack(exception_list,
                                  caught_list,
                                  show_locals=True)
        sio = cStringIO.StringIO()
        for line in stack:
            sio.write(line)

        for line in formatted_exception:
            sio.write(line)

        self._LogThreadLocals(sio)
        self._LogServerInfo(sio)
        try:
            sio.write('Stackhash: {}\n'.format(stackID[0]))
        except Exception:
            pass

        s = sio.getvalue()
        sio.close()
        return s
Ejemplo n.º 2
0
async def get_greeting(order_state):
    order_state = order_state.upper()
    with (await greetings['acquire']):
        if order_state in greetings.keys():
            return greetings[order_state]
        else:
            try:
                data = await get_sounds(
                    'select name, description from asterisk_sounds where (sound_type=4) and (description is not null)'
                )
                # data = {k.upper(): v for k, v in data.items()}
                logger.info(f'get_greeting: {data}')
                greetings.update(data)
                logger.info(f'{greetings[order_state]}')
                return greetings[order_state]
            except Exception as e:
                logger.error(e)
                logger.error(traceback2.extract_tb(sys.exc_info()[2]))
                return ''
Ejemplo n.º 3
0
def _LogException(exc_info, extraText, channel, toConsole, toLogServer, toAlertSvc, toMsgWindow, severity, show_locals):
    exctype, exc, tb = exc_info
    exception_list = traceback2.extract_tb(tb, extract_locals=show_locals)
    if tb:
        caught_list = traceback2.extract_stack(tb.tb_frame)
    else:
        caught_list = traceback2.extract_stack(up=2)
    stack, stackID = GetStack(exception_list, caught_list, show_locals=show_locals)
    if severity is None:
        severity = (ERR, WARN)[isinstance(exc, UserError)]
    if toAlertSvc is None:
        toAlertSvc = severity in (ERR,)
    if toMsgWindow and isinstance(exc, UserError) and boot.role == 'client':
        toMsgWindow = 0
        uiMessageFunc(*exc.args)
    multiplexToConsole = False if toLogServer else toConsole
    out = GetMultiplex(channel, severity, multiplexToConsole, toLogServer, toMsgWindow, toAlertSvc, stackID)
    formatted_exception = traceback2.format_exception_only(exctype, exc)
    if not extraText:
        try:
            extraText = 'Info: %s' % formatted_exception[-1].strip()
        except:
            extraText = 'Info: <none>'

    prefix = 'REMOTE ' if channel == 'remote.exc' else ''
    traceID = NextTraceID()
    print >> out, '%sEXCEPTION #%d logged at %s %s : %s ' % (prefix,
     traceID,
     blue.os.FormatUTC()[0],
     blue.os.FormatUTC()[2],
     extraText)
    print >> out, ' '
    print >> out, 'Formatted exception info:',
    for line in formatted_exception:
        print >> out, line,

    print >> out, ' '
    for line in stack:
        print >> out, line,

    print >> out, ' '
    if exctype is MemoryError:
        try:
            DumpMemoryStatus(out)
            DumpMemHistory(out)
        except:
            pass

    try:
        _LogThreadLocals(out)
    except MemoryError:
        pass

    if boot.role != 'client':
        try:
            ram = blue.sysinfo.GetMemory().pageFile / 1024 / 1024
            cpuLoad = sm.GetService('machoNet').GetCPULoad()
            memLeft = blue.sysinfo.GetMemory().availablePhysical / 1024 / 1024
            txt = 'System Information: '
            txt += ' Node ID: %s' % sm.GetService('machoNet').GetNodeID()
            if boot.role == 'server':
                txt += ' | Node Name: %s' % sm.GetService('machoNet').GetLocalHostName()
            txt += ' | Total CPU load: %s%%' % int(cpuLoad)
            txt += ' | Process memory in use: %s MB' % ram
            txt += ' | Physical memory left: %s MB' % memLeft
            print >> out, txt
        except Exception as e:
            sys.exc_clear()

    try:
        print >> out, 'Stackhash: %s' % stackID[0]
    except Exception:
        pass

    print >> out, 'Reported from: ', __name__
    print >> out, '%sEXCEPTION END' % (prefix,)
    out.flush()
    if toConsole:
        if toLogServer:
            print >> sys.stderr, '#nolog: An exception has occurred. It has been logged in the log server as exception #%d' % traceID
        else:
            print >> sys.stderr, 'There is no useful information accompanying this exception in the log server'
Ejemplo n.º 4
0
def _LogException(exc_info, extraText, channel, toConsole, toLogServer, toAlertSvc, toMsgWindow, severity, show_locals):
    global traceID
    exctype, exc, tb = exc_info
    exception_list = traceback2.extract_tb(tb, extract_locals=show_locals)
    if tb:
        caught_list = traceback2.extract_stack(tb.tb_frame)
    else:
        caught_list = traceback2.extract_stack(up=2)
    formatted_exception = traceback2.format_exception_only(exctype, exc)
    stack, stackID = GetStack(exception_list, caught_list, show_locals=show_locals)
    if severity is None:
        severity = (ERR, WARN)[isinstance(exc, UserError)]
    if toAlertSvc is None:
        toAlertSvc = severity in (ERR,)
    if toMsgWindow and isinstance(exc, UserError) and boot.role == 'client':
        toMsgWindow = 0
        uiMessageFunc(*exc.args)
    out = GetMultiplex(channel, severity, [toConsole, 0][toLogServer == 1], toLogServer, toMsgWindow, toAlertSvc, stackID)
    pre = ('', 'REMOTE')[channel == 'remote.exc']
    tmpTraceID = traceID
    traceID += 1
    print >> out, '%sEXCEPTION #%d logged at ' % (pre, tmpTraceID), blue.os.FormatUTC()[0], blue.os.FormatUTC()[2], extraText
    for line in stack:
        print >> out, line,

    for line in formatted_exception:
        print >> out, line,

    if exctype is MemoryError:
        try:
            DumpMemoryStatus(out)
            DumpMemHistory(out)
        except:
            pass

    try:
        _LogThreadLocals(out)
    except MemoryError:
        pass

    try:
        print >> out, 'Stackhash:%s\n' % stackID[0]
    except Exception:
        pass

    print >> out
    if boot.role != 'client':
        try:
            nodeID = getattr(sm.services['machoNet'], 'nodeID', None)
            ram = blue.win32.GetProcessMemoryInfo()['PagefileUsage'] / 1024 / 1024
            cpuLoad = sm.GetService('machoNet').GetCPULoad()
            m = blue.win32.GlobalMemoryStatus()
            memLeft = m['AvailPhys'] / 1024 / 1024
            txt = 'System Information: '
            txt += ' Node ID: %s' % sm.GetService('machoNet').GetNodeID()
            if boot.role == 'server':
                txt += ' | Node Name: %s' % sm.GetService('machoNet').GetNodeName()
            txt += ' | Total CPU load: %s%%' % int(cpuLoad)
            txt += ' | Process memory in use: %s MB' % ram
            txt += ' | Physical memory left: %s MB' % memLeft
            print >> out, txt
        except Exception as e:
            sys.exc_clear()

    print >> out, '%sEXCEPTION END' % (pre,)
    out.flush()
    if toConsole:
        if toLogServer:
            print >> sys.stderr, 'An exception has occurred.  It has been logged in the log server as exception #%d' % tmpTraceID
        else:
            print >> sys.stderr, 'There is no useful information accompanying this exception in the log server'
Ejemplo n.º 5
0
def _LogException(exc_info, extraText, channel, toConsole, toLogServer,
                  toAlertSvc, toMsgWindow, severity, show_locals):
    exctype, exc, tb = exc_info
    exception_list = traceback2.extract_tb(tb, extract_locals=show_locals)
    if tb:
        caught_list = traceback2.extract_stack(tb.tb_frame)
    else:
        caught_list = traceback2.extract_stack(up=2)
    formatted_exception = traceback2.format_exception_only(exctype, exc)
    stack, stackID = GetStack(exception_list,
                              caught_list,
                              show_locals=show_locals)
    if severity is None:
        severity = (ERR, WARN)[isinstance(exc, UserError)]
    if toAlertSvc is None:
        toAlertSvc = severity in (ERR, )
    if toMsgWindow and isinstance(exc, UserError) and boot.role == 'client':
        toMsgWindow = 0
        uiMessageFunc(*exc.args)
    out = GetMultiplex(channel, severity, [toConsole, 0][toLogServer == 1],
                       toLogServer, toMsgWindow, toAlertSvc, stackID)
    pre = ('', 'REMOTE')[channel == 'remote.exc']
    traceID = NextTraceID()
    print >> out, '%sEXCEPTION #%d logged at ' % (
        pre,
        traceID), blue.os.FormatUTC()[0], blue.os.FormatUTC()[2], extraText
    for line in stack:
        print >> out, line,

    for line in formatted_exception:
        print >> out, line,

    if exctype is MemoryError:
        try:
            DumpMemoryStatus(out)
            DumpMemHistory(out)
        except:
            pass

    try:
        _LogThreadLocals(out)
    except MemoryError:
        pass

    try:
        print >> out, 'Stackhash:%s\n' % stackID[0]
    except Exception:
        pass

    print >> out
    if boot.role != 'client':
        try:
            ram = blue.win32.GetProcessMemoryInfo(
            )['PagefileUsage'] / 1024 / 1024
            cpuLoad = sm.GetService('machoNet').GetCPULoad()
            m = blue.win32.GlobalMemoryStatus()
            memLeft = m['AvailPhys'] / 1024 / 1024
            txt = 'System Information: '
            txt += ' Node ID: %s' % sm.GetService('machoNet').GetNodeID()
            if boot.role == 'server':
                txt += ' | Node Name: %s' % sm.GetService(
                    'machoNet').GetLocalHostName()
            txt += ' | Total CPU load: %s%%' % int(cpuLoad)
            txt += ' | Process memory in use: %s MB' % ram
            txt += ' | Physical memory left: %s MB' % memLeft
            print >> out, txt
        except Exception as e:
            sys.exc_clear()

    print >> out, '%sEXCEPTION END' % (pre, )
    out.flush()
    if toConsole:
        if toLogServer:
            print >> sys.stderr, 'An exception has occurred.  It has been logged in the log server as exception #%d' % traceID
        else:
            print >> sys.stderr, 'There is no useful information accompanying this exception in the log server'
Ejemplo n.º 6
0
    def CallUp(self, packet):
        try:
            try:
                return self.ForwardCallUp(packet)
            except (UnMachoDestination,
             MachoException,
             objectCaching.CacheOK,
             util.UpdateMoniker,
             UserError,
             exceptions.CrestSessionExists) as e:
                if isinstance(e, UnMachoDestination) and getattr(packet.destination, 'nodeID', None):
                    if packet.destination.nodeID < const.maxNodeID and macho.mode == 'proxy':
                        self.machoNet.HandleUnMachoDestination(packet.destination.nodeID, packet)
                return packet.ErrorResponse(const.cluster.MACHONETERR_WRAPPEDEXCEPTION, (macho.DumpsSanitized(e),))
            except Exception as e:
                exctype, exc = sys.exc_info()[:2]
                stack, serverStackKey = log.GetStack(traceback2.extract_tb(sys.exc_info()[2], extract_locals=1), show_locals=1)
                dasID = self.GetErrorID()
                desc = ['%s caught an exception while handling a remote call.  The caller should send a traceback with ID %s, which hopefully arrive at the originating node.  Server info follows:' % (macho.mode, dasID)]
                desc += stack
                desc += traceback2.format_exception_only(exctype, exc)
                try:
                    ram = blue.win32.GetProcessMemoryInfo()['PagefileUsage'] / 1024 / 1024
                    cpuLoad = self.machoNet.GetCPULoad()
                    m = blue.win32.GlobalMemoryStatus()
                    memLeft = m['AvailPhys'] / 1024 / 1024
                    txt = 'System Information: '
                    txt += 'Total CPU load: %s%%' % int(cpuLoad)
                    txt += ' | Process memory in use: %s MB' % ram
                    txt += ' | Physical memory left: %s MB\n' % memLeft
                    desc.append(txt)
                    sessionInfo = 'session was ' + str(session)
                    desc.append(sessionInfo)
                except Exception as e:
                    sys.exc_clear()

                with self.machoNet.LogfileError() as f:
                    for each in desc:
                        print >> f, each,

                session.LogSessionHistory('An exception occurred while handling a remote call.  Traceback ID=%s' % dasID)
                session.hasproblems = 1
                sm.GetService('alert').SendStackTraceAlert(serverStackKey, ''.join(desc), 'Delivering Error To Remote Host')
                variables = []
                if macho.mode == 'client':
                    variables += ['Context info logged on the client, session=%s\n' % (strx(session),)]
                elif prefs.clusterMode in ('LOCAL', 'MASTER', 'TRANSLATION') or session and 0 != session.role & (service.ROLE_QA | service.ROLE_PROGRAMMER):
                    variables += ['Context info logged on %s node %d, host=%s\n' % (macho.mode, self.machoNet.GetNodeID(), self.machoNet.GetNodeName())]
                else:
                    variables = []
                    stack = ['//%s/host=%s/nodeID=%d/errorHashKey=%d\n' % (macho.mode,
                      self.machoNet.GetNodeName(),
                      self.machoNet.GetNodeID(),
                      serverStackKey[0])]
                return packet.ErrorResponse(const.cluster.MACHONETERR_WRAPPEDEXCEPTION, (macho.DumpsSanitized(e), (1,
                  stack,
                  variables,
                  dasID,
                  serverStackKey,
                  self.machoNet.GetNodeID(),
                  macho.mode)))

        except:
            log.LogException('Could not create ErrorResponse, sending an empty one')
            return packet.ErrorResponse(const.cluster.MACHONETERR_WRAPPEDEXCEPTION, ())
Ejemplo n.º 7
0
def _LogException(exc_info, extraText, channel, toConsole, toLogServer,
                  toAlertSvc, toMsgWindow, severity, show_locals):
    if raven_client:
        raven_client(message=extraText, exc_info=exc_info)
    exctype, exc, tb = exc_info
    exception_list = traceback2.extract_tb(tb, extract_locals=show_locals)
    if tb:
        caught_list = traceback2.extract_stack(tb.tb_frame)
    else:
        caught_list = traceback2.extract_stack(up=2)
    stack, stackID = GetStack(exception_list,
                              caught_list,
                              show_locals=show_locals)
    if severity is None:
        severity = (ERR, WARN)[isinstance(exc, UserError)]
    if toAlertSvc is None:
        toAlertSvc = severity in (ERR, )
    if toMsgWindow and isinstance(exc, UserError) and boot.role == 'client':
        toMsgWindow = 0
        uiMessageFunc(*exc.args)
    multiplexToConsole = False if toLogServer else toConsole
    out = GetMultiplex(channel, severity, multiplexToConsole, toLogServer,
                       toMsgWindow, toAlertSvc, stackID)
    formatted_exception = traceback2.format_exception_only(exctype, exc)
    if not extraText:
        try:
            extraText = 'Info: %s' % formatted_exception[-1].strip()
        except:
            extraText = 'Info: <none>'

    prefix = 'REMOTE ' if channel == 'remote.exc' else ''
    traceID = NextTraceID()
    print >> out, '%sEXCEPTION #%d logged at %s %s : %s ' % (
        prefix, traceID, blue.os.FormatUTC()[0], blue.os.FormatUTC()[2],
        extraText)
    print >> out, ' '
    print >> out, 'Formatted exception info:',
    for line in formatted_exception:
        print >> out, line,

    print >> out, ' '
    for line in stack:
        print >> out, line,

    print >> out, ' '
    if exctype is MemoryError:
        try:
            DumpMemoryStatus(out)
            DumpMemHistory(out)
        except:
            pass

    try:
        _LogThreadLocals(out)
    except MemoryError:
        pass

    if boot.role != 'client':
        try:
            ram = blue.sysinfo.GetMemory().pageFile / 1024 / 1024
            cpuLoad = sm.GetService('machoNet').GetCPULoad()
            memLeft = blue.sysinfo.GetMemory().availablePhysical / 1024 / 1024
            txt = 'System Information: '
            txt += ' Node ID: %s' % sm.GetService('machoNet').GetNodeID()
            if boot.role == 'server':
                txt += ' | Node Name: %s' % sm.GetService(
                    'machoNet').GetLocalHostName()
            txt += ' | Total CPU load: %s%%' % int(cpuLoad)
            txt += ' | Process memory in use: %s MB' % ram
            txt += ' | Physical memory left: %s MB' % memLeft
            print >> out, txt
        except Exception as e:
            sys.exc_clear()

    try:
        print >> out, 'Stackhash: %s' % stackID[0]
    except Exception:
        pass

    print >> out, 'Reported from: ', __name__
    print >> out, '%sEXCEPTION END' % (prefix, )
    out.flush()
    if toConsole:
        if toLogServer:
            print >> sys.stderr, '#nolog: An exception has occurred. It has been logged in the log server as exception #%d' % traceID
        else:
            print >> sys.stderr, 'There is no useful information accompanying this exception in the log server'