Exemplo n.º 1
0
def send_message(**kwargs):
    """Send a message to server.

    kwargs   a dict of keyword arguments

    Send a JSON representation of the kwargs dict.
    Add the User, Project, Scenario, Setup global values.
    """

    # add the global values
    kwargs['user'] = User
    kwargs['project'] = Project
    kwargs['scenario'] = Scenario
    kwargs['setup'] = Setup
    kwargs['instance'] = Instance
    kwargs['project_id'] = ProjectID
    kwargs['scenario_id'] = ScenarioID

    # add time as float and string (UTC, ISO 8601 format)
    kwargs['time'] = time.time()
    kwargs['timestamp'] = time.strftime('%Y-%m-%d %H:%M:%SZ', time.gmtime())

    # get JSON string
    msg = json.dumps(kwargs)
    log.debug('message JSON: %s' % msg)

    amqp.post_server_message(msg)
Exemplo n.º 2
0
def send_message_lite(**kwargs):
    """Send a message.  Can't assume any environment.

    kwargs   a dict of keyword arguments

    Send a JSON representation of the kwargs dict ONLY.
    Can't assume logging is set up
    """

    # add time as float and string (UTC, ISO 8601 format)
    kwargs['timestamp'] = time.strftime('%Y-%m-%d %H:%M:%SZ', time.gmtime())

    # get JSON string
    msg = json.dumps(kwargs)

    amqp.post_server_message(msg)