Skip to Content
Learning MCollective
book

Learning MCollective

by Jo Rhett
August 2014
Intermediate to advanced
284 pages
5h 24m
English
O'Reilly Media, Inc.
Content preview from Learning MCollective

Chapter 16. Extending the Agent

Here we’ll introduce you to more complex things you can do in your agent. There isn’t a use for this functionality in our thanks plugin just yet, but it’s good to know what is possible.

We’ll give it the ability to execute external scripts or command lines; how to send custom log lines; and best of all, we’ll review how to blow up tragically, er, I mean error out gracefully. Of course.

Executing Scripts

You can call any external script, written in any programming language (including bash) that is capable of writing out the results to a file in JSON format:

action "python_script" do
  implemented_by "/lovely/little/python/script.py"
end

The script will be given two types of input:

  • A path to the file containing the request data in JSON format:

    • The first command-line parameter

    • Environment variable $MCOLLECTIVE_REQUEST_FILE

  • A path to the file where the response should be written in JSON format:

    • The second command-line parameter

    • Environment variable $MCOLLECTIVE_REPLY_FILE

The script should write the reply as a JSON hash into the reply file. The return code of your script should be one of the standard result codes from the table in “Results and Exceptions”.

If you do not specify a full path to the script, it will look for the script in the agent’s plugin directory. This makes it easy to bundle your scripts in with your agent plugins:

action "bundled_script" do
  implemented_by "bundled_script.py"
end

Location:
  $libdir/agent/agentname ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Russell Rules

Russell Rules

Bill Russell
What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz
How to Become a Game-Changing Leader

How to Become a Game-Changing Leader

Douglas A. Ready, Alan Mulally
How You Play the Game

How You Play the Game

Jerry Colangelo, Len Sherman

Publisher Resources

ISBN: 9781491945681Errata