Menu

test_task.py

Brett Solon

/opt/marvin/tasks/test_task.py

This is a test script to for checking MARVIN's configuration:

  1. Import the speak and new_message functions from marvin
  2. Create a new message
  3. Assign values to various fields in marvins_message
  4. Speak marvins_message

Explanation:

  1. MARVIN includes built-in functions for frequent use. The new_message function is designed to return a custom dictionary variable with common fields defined. The speak function calls MARVIN's "mouth" to deliver the message (per MARVIN's configuration).
  2. Create a new variable for storing the output from this task. The new_message function returns a predefined variable of the dictionary type. The metafields of the message (keys) are initialized with blank values. This specific format is required as the input of the speak function.
  3. Set some values so MARVIN will have something to say.
  4. Use the speak function to output the message. This will call the "mouth," which should be configured to output the message by SMTP or Syslog. This function expects a variable created by the new_message function.

THE CODE!

#!/usr/bin/python

from marvin import speak, new_message

marvins_message = new_message()
marvins_message['task'] = 'test_task'
marvins_message['name'] = 'MARVIN'
marvins_message['message'] = "I'm alive!!"
marvins_message['sourceHostname'] = 'localhost'
marvins_message['sourceAddress'] = '127.0.0.1'
marvins_message['sourcePort'] = '31337'
marvins_message['sourceUsername'] = 'testuser'
marvins_message['url'] = 'http://www.example.com'

speak(marvins_message)

MongoDB Logo MongoDB