Summary
Using https://github.com/choria-io/go-external I created a simple choria agent that should list users with a list action (user list
) that doesn't take any inputs (none are declared in the ddl or json), but when I try to invoke it via mco rpc I get an error about missing inputs:
$ mco rpc --verbose -I csqmgmt-puppetmaster02.grass.corp user list
* [ ============================================================> ] 1 / 1
csqmgmt-puppetmaster02.grass.corp : Validation failed: request contains inputs while none are declared in the DDL
{}
I suspect that this is because somewhere along the line the lack of input is converted into an empty hash which is not the same as no input and thus fails validation in the mcorpc-agent-provider library.
Note that I verified that my agent generally works - the echo
action which I copied from example in the README works fine within the same agent:
[alexander.hermes@csqmgmt-puppetmaster02 ~]$ mco rpc user echo -I csqmgmt-puppetmaster02.grass.corp "message=foo"
* [ ============================================================> ] 1 / 1
csqmgmt-puppetmaster02.grass.corp
Echo: foo
Logs
choria-audit.log
extract showing the two actions being submitted.
{"timestamp":"2019-11-25T02:09:45.182154+0000","request_id":"39619513748a511fa60dd547c94af119","request_time":1574647785,"caller":"choria=alexander.hermes.mcollective","sender":"csqmgmt-puppetmaster02.grass.corp","agent":"user","action":"echo","data":{"message":"foo","process_results":true}}
{"timestamp":"2019-11-25T02:09:50.854554+0000","request_id":"f7c4e19db756502191196f9903ba1f39","request_time":1574647790,"caller":"choria=alexander.hermes.mcollective","sender":"csqmgmt-puppetmaster02.grass.corp","agent":"user","action":"list","data":{"process_results":true}}
choria.log
extract showing the successful echo
action followed by a failed list
action:
{"agent":"user","component":"server","identity":"csqmgmt-puppetmaster02.grass.corp","level":"debug","msg":"Attempting to call external agent user#echo (/opt/puppetlabs/mcollective/plugins/mcollective/agent/user) with a timeout 15","subsystem":"agents","time":"2019-11-25T10:09:45+08:00"}
{"level":"debug","msg":"Sending a broadcast message to NATS target 'mcollective.reply.csqmgmt-puppetmaster02.grass.corp.3381.1' for message 39619513748a511fa60dd547c94af119 type reply","time":"2019-11-25T10:09:45+08:00"}
{"level":"debug","msg":"Publishing 785 bytes to mcollective.reply.csqmgmt-puppetmaster02.grass.corp.3381.1","time":"2019-11-25T10:09:45+08:00"}
<snip validation stuff>
{"component":"server","identity":"csqmgmt-puppetmaster02.grass.corp","level":"debug","msg":"Matching request f7c4e19db756502191196f9903ba1f39 with agent filters '[]string{\"user\"}'","subsystem":"discovery","time":"2019-11-25T10:09:50+08:00"}
{"component":"server","identity":"csqmgmt-puppetmaster02.grass.corp","level":"debug","msg":"Handling message f7c4e19db756502191196f9903ba1f39 with timeout 15000000000","subsystem":"agents","time":"2019-11-25T10:09:50+08:00"}
{"agent":"user","component":"server","identity":"csqmgmt-puppetmaster02.grass.corp","level":"info","msg":"Handling message f7c4e19db756502191196f9903ba1f39 for user#list from choria=alexander.hermes.mcollective","subsystem":"agents","time":"2019-11-25T10:09:50+08:00"}
{"agent":"user","component":"server","identity":"csqmgmt-puppetmaster02.grass.corp","level":"debug","msg":"Attempting to call external agent user#list (/opt/puppetlabs/mcollective/plugins/mcollective/agent/user) with a timeout 15","subsystem":"agents","time":"2019-11-25T10:09:50+08:00"}
{"agent":"user","component":"server","identity":"csqmgmt-puppetmaster02.grass.corp","level":"error","msg":"Validation failed: request contains inputs while none are declared in the DDL","subsystem":"agents","time":"2019-11-25T10:09:50+08:00"}
{"level":"debug","msg":"Sending a broadcast message to NATS target 'mcollective.reply.csqmgmt-puppetmaster02.grass.corp.3412.1' for message f7c4e19db756502191196f9903ba1f39 type reply","time":"2019-11-25T10:09:50+08:00"}
{"level":"debug","msg":"Publishing 853 bytes to mcollective.reply.csqmgmt-puppetmaster02.grass.corp.3412.1","time":"2019-11-25T10:09:50+08:00"}
Details of my test setup
System
$ uname -a
Linux csqmgmt-puppetmaster02.grass.corp 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.6.1810 (Core)
Release: 7.6.1810
Codename: Core
Agent source
See the repo at https://github.com/ExalDraen/choria-plugin-user-agent
DDL
metadata :name => "user",
:description => "Interact with users on a system",
:author => "Alexander Hermes (@ExalDraen)",
:license => "GNU General Public License v3.0",
:version => "0.1.0",
:url => "https://github.com/exaldraen/choria-plugin-user-agent",
:provider => "external",
:timeout => 15
action "echo", :description => "Echo text back" do
display :ok
input :message,
:prompt => "The message to send for echoing",
:description => "This message will be echoed back",
:type => :string,
:validation => :shellsafe,
:maxlength => 512,
:optional => false
output :message,
:description => "Echo of the original message",
:display_as => "Echo",
:type => "string"
end
action "list", :description => "List logged-in users on a system" do
display :ok
output :user_list,
:description => "List of logged-in users",
:display_as => "User LIst",
:type => "string"
end
JSON
{
"$schema": "https://choria.io/schemas/mcorpc/ddl/v1/agent.json",
"metadata": {
"license": "GNU General Public License v3.0",
"author": "Alexander Hermes (@ExalDraen)",
"timeout": 15,
"name": "user",
"version": "0.1.0",
"url": "https://github.com/exaldraen/choria-plugin-user-agent",
"description": "Interact with users on a system",
"provider": "external"
},
"actions": [
{
"action": "echo",
"input": {
"message": {
"prompt": "The message to send for echoing",
"description": "This message will be echoed back",
"type": "string",
"optional": false,
"validation": "shellsafe",
"maxlength": 512
}
},
"output": {
"message": {
"description": "Echo of the original message",
"display_as": "Echo",
"type": "string"
}
},
"display": "ok",
"description": "Echo text back"
},
{
"action": "list",
"input": {},
"output": {
"user_list": {
"description": "List of logged-in users",
"display_as": "User LIst",
"type": "string"
}
},
"display": "ok",
"description": "List logged-in users on a system"
}
]
}