Execute-command via API on Remote System

Hi all

I’m trying to get scripts executed via API on a remote Host (Agent Based). The Intend is to execute Scripts on Request.

I created a command definition:

//###################### TEST REMOTE COMMAND ############################
object CheckCommand “remote_command_execute” {
import “plugin-check-command”
command = [ PluginDir + “/remote_command.sh” ]
}

This is the API Command I use:

curl -k -s -S -i -u USER:PW -H ‘Accept: application/json’ -X POST ‘https://localhost:5665/v1/actions/execute-command’ -d ‘{“type”: “Service”, “service”: “DUMMYSERVICE”, “ttl”: 15, “macros”: { “command_endpoint”: “SERVERNAME” }, “command”: “remote_command_execute”, “command_type”: “CheckCommand” }’

Unfortunately I get following Error:

HTTP/1.1 404 Not Found
Content-Type: application/json
Transfer-Encoding: chunked
Server: Icinga/r2.10.5-1

Did anybody do this already and can give me a hint ? Can I debug what exactly is missing or wrong in the API Request ? Where to find the issue?

Many Thanks in advance

The host name is missing in front of DUMMYSERVICE.

Many Thanks for the Hint, but It still doesnt work…

curl -k -s -S -i -u USER:PW -H ‘Accept: application/json’ -X POST ‘https://localhost:5665/v1/actions/execute-command’ -d ‘{“type”: “Service”, “service”: “HOSTNAME!SERVICENAME”, “ttl”: 15, “macros”: { “command_endpoint”: “HOSTNAME” }, “command”: “remote_command_execute”, “command_type”: “CheckCommand” }’

I now receive:
HTTP/1.1 404 Not Found
Content-Type: application/json
Transfer-Encoding: chunked
Server: Icinga/r2.10.5-1

{“error”:404.0,“status”:“Action ‘execute-command’ does not exist.”}

Is a specific version of Icinga needed ? I have 2.10.5 installed.

I assume you have enabled the API on localhost?

https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/

Antony.

Yes, it was added with v2.13.0.

Many Thanks :slight_smile:

Will Upgrade and check again.