Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command management endpoints #72

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

f-galland
Copy link
Member

Description

This PR adds HTTP endpoints to the Command Manager plugin that will be used to queue/schedule tasks.

Issues Resolved

Resolves #69

@f-galland f-galland self-assigned this Sep 18, 2024
@f-galland
Copy link
Member Author

I added validation inspired by the opensearch-job-scheduler plugin repository model.

I'm currently getting an error when indexing:

$ curl -XPOST "http://127.0.0.1:9200/_plugins/_commandmanager/1234" -H 'Content-Type: application/json' -d'
{
  "command_order_id": "value",
  "command_request_id": "value",
  "command_source": "value",
  "command_target": "value",
  "command_timeout": "value",
  "command_type": "value",
  "command_user": "value",
  "command_action": {"field":"value"},
  "command_result": {"field":"value"}
}'


{"response":"failed"}

The engine logs are showing the following error:

java.lang.NullPointerException: Cannot read field "commandOrderId" because "copyCommandDetails" is null
	at com.wazuh.commandmanager.model.CommandDetails.<init>(CommandDetails.java:159) ~[?:?]

@f-galland
Copy link
Member Author

I removed the document update functionality off the plugin after discussion with Alex, with this change, the endpoint now works as expected:

$ curl -XPOST "http://127.0.0.1:9200/command-manager/_search?pretty" -H 'Content-Type: application/json' -d'
{
   "size": 1,
   "query": {
      "match_all": {}
   }
}'
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "command-manager",
        "_id" : "JEChD5IBPt7qjCU0RVfs",
        "_score" : 1.0,
        "_source" : {
          "command_order_id" : "value",
          "command_request_id" : "value",
          "command_source" : "value",
          "command_target" : "value",
          "command_timeout" : "value",
          "command_type" : "value",
          "command_user" : "value",
          "command_action" : {
            "field" : "value"
          },
          "command_result" : {
            "field" : "value"
          }
        }
      }
    ]
  }
}

@f-galland
Copy link
Member Author

The order and request IDs are generated randomly (for tests purposes) and the document ID is a concatenation of both:

$ 
curl -XPOST "http://127.0.0.1:9200/_plugins/_commandmanager" -H 'Content-Type: application/json' -d'
{
  "command_order_id": "value",
  "command_request_id": "value",
  "command_source": "value",
  "command_target": "value",
  "command_timeout": "value",
  "command_type": "value",
  "command_user": "value",
  "command_action": {"field":"value"},
  "command_result": {"field":"value"}
}'
{"response":"success","document_id":"pBjePGfvgm"}



fede@tyner:~
$ curl -XPOST "http://127.0.0.1:9200/command-manager/_search?pretty" -H 'Content-Type: application/json' -d'
{
   "size": 1,
   "query": {
      "match_all": {}
   }
}'




{
  "took" : 40,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "command-manager",
        "_id" : "pBjePGfvgm",
        "_score" : 1.0,
        "_source" : {
          "command_order_id" : "pBjeP",
          "command_request_id" : "Gfvgm",
          "command_source" : "value",
          "command_target" : "value",
          "command_timeout" : "value",
          "command_type" : "value",
          "command_user" : "value",
          "command_action" : {
            "field" : "value"
          },
          "command_result" : {
            "field" : "value"
          }
        }
      }
    ]
  }
}

@f-galland f-galland marked this pull request as ready for review September 20, 2024 19:29
@f-galland f-galland requested a review from a team as a code owner September 20, 2024 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create new endpoint on the Command Manager plugin
2 participants