コード例 #1
0
    def stats_sender(self, program_id, stats, contexts):
        message_count = len(stats)
        if message_count > 0:
            event = LwesEvent (None, LWES_STATS_MSG)
            event.set_STRING("prog_id", program_id)


            i = 0
            event.set_U_INT_16("num", message_count)
            for stat_key, stat_value in stats.iteritems():
                event.set_STRING("k%d" % i, stat_key)
                event.set_STRING("t%d" % i,
                                 MondemandStatTypeString[stat_value['type']])
                event.set_INT_64("v%d" % i, stat_value['value'])
                i += 1

            context_count = len(contexts)

            i = 0
            event.set_U_INT_16("ctxt_num", context_count)
            for context_key, context_value in contexts.iteritems():
                event.set_STRING("ctxt_k%d" % i, context_key)
                event.set_STRING("ctxt_v%d" % i, context_value)
                i += 1

            self.transport['userdata'].emit(event)

        return 0
コード例 #2
0
    def trace_sender(self, program_id, owner, trace_id, message, trace_dict):

        hostname = get_hostname(1024)

        event = LwesEvent (None, LWES_TRACE_MSG)
        event.set_STRING("mondemand.prog_id", program_id)
        event.set_STRING("mondemand.trace_id", trace_id)
        event.set_STRING("mondemand.owner", owner)
        event.set_STRING("mondemand.src_host", hostname)
        event.set_STRING("mondemand.message", message)

        for key in trace_dict:
            event.set_STRING(key, trace_dict[key])

        #lwes.lwes_emitter_emit(self.transport['userdata'], event)
        self.transport['userdata'].emit(event)

        return 0
コード例 #3
0
ファイル: demo.py プロジェクト: charleslaw/lwes-python
from lwes.emitter import LwesEmitter
from lwes.event import LwesEvent

# Create an emitter to send messages
address = "127.0.0.1"
interface = ""  # Not yet supported
port = 20402
heartbeat_flag = 0  # Not yet supported
heartbeat_freq = 0  # Not yet supported

emitter = LwesEmitter(address, interface, port, heartbeat_flag, heartbeat_freq, ttl=1)


db = None
event = LwesEvent(db, "My LWES Event")


event.set_STRING("Hello", "World")
event.set_U_INT_16("unsigned_int16", 42)
event.set_INT_16("signed_int16", -1)
event.set_U_INT_32("unsigned_int32", 75535)
event.set_INT_32("signed_int32", -42768)
event.set_U_INT_64("unsigned_int64", 5294967295)
event.set_INT_64("signed_int64", -314748364)
event.set_BOOLEAN("boolT", True)
event.set_BOOLEAN("boolF", False)
event.set_IP_ADDR("addr", "127.1.255.3")

emitter.emit(event)