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

Implement Job Scheduler logic #103

Merged
merged 90 commits into from
Dec 4, 2024
Merged

Conversation

f-galland
Copy link
Member

Description

This PR adds job scheduler logic to the command-manager plugin.

Issues Resolved

Resolves #87

Copy link
Member

@AlexRuiz7 AlexRuiz7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commands sent to the API are indexed.

image

Details

{
  "took": 8,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 5,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": ".commands",
        "_id": "SklIkpMBrdRQWmVi5DGO",
        "_score": 1,
        "_source": {
          "agent": {
            "groups": [
              "groups000"
            ]
          },
          "command": {
            "source": "Engine",
            "user": "user53",
            "target": {
              "type": "agent",
              "id": "target4"
            },
            "action": {
              "name": "restart",
              "args": [
                "/path/to/executable/arg6",
                "/path/to/executable/arg6"
              ],
              "version": "v4"
            },
            "timeout": 30,
            "status": "PENDING",
            "order_id": "QUlIkpMBrdRQWmVi5DGO",
            "request_id": "QElIkpMBrdRQWmVi5DGO"
          },
          "@timestamp": "2024-12-04T15:27:50Z",
          "delivery_timestamp": "2024-12-04T15:28:20Z"
        }
      },
      {
        "_index": ".commands",
        "_id": "S0lIkpMBrdRQWmVi5DGP",
        "_score": 1,
        "_source": {
          "agent": {
            "groups": [
              "groups000"
            ]
          },
          "command": {
            "source": "Engine",
            "user": "user53",
            "target": {
              "type": "agent",
              "id": "target4"
            },
            "action": {
              "name": "restart",
              "args": [
                "/path/to/executable/arg6",
                "/path/to/executable/arg6",
                "/path/to/executable/arg6",
                "/path/to/executable/arg6"
              ],
              "version": "v4"
            },
            "timeout": 30,
            "status": "PENDING",
            "order_id": "Q0lIkpMBrdRQWmVi5DGO",
            "request_id": "QklIkpMBrdRQWmVi5DGO"
          },
          "@timestamp": "2024-12-04T15:27:50Z",
          "delivery_timestamp": "2024-12-04T15:28:20Z"
        }
      },
      {
        "_index": ".commands",
        "_id": "TElIkpMBrdRQWmVi5DGP",
        "_score": 1,
        "_source": {
          "agent": {
            "groups": [
              "groups000"
            ]
          },
          "command": {
            "source": "Engine",
            "user": "user53",
            "target": {
              "type": "agent",
              "id": "target4"
            },
            "action": {
              "name": "restart",
              "args": [
                "/path/to/executable/arg6",
                "/path/to/executable/arg6",
                "/path/to/executable/arg6"
              ],
              "version": "v4"
            },
            "timeout": 30,
            "status": "PENDING",
            "order_id": "RUlIkpMBrdRQWmVi5DGO",
            "request_id": "RElIkpMBrdRQWmVi5DGO"
          },
          "@timestamp": "2024-12-04T15:27:50Z",
          "delivery_timestamp": "2024-12-04T15:28:20Z"
        }
      },
      {
        "_index": ".commands",
        "_id": "TUlIkpMBrdRQWmVi5DGP",
        "_score": 1,
        "_source": {
          "agent": {
            "groups": [
              "groups000"
            ]
          },
          "command": {
            "source": "Engine",
            "user": "user53",
            "target": {
              "type": "agent",
              "id": "target4"
            },
            "action": {
              "name": "restart",
              "args": [
                "/path/to/executable/arg6",
                "/path/to/executable/arg6",
                "/path/to/executable/arg6",
                "/path/to/executable/arg6"
              ],
              "version": "v4"
            },
            "timeout": 30,
            "status": "PENDING",
            "order_id": "R0lIkpMBrdRQWmVi5DGO",
            "request_id": "RklIkpMBrdRQWmVi5DGO"
          },
          "@timestamp": "2024-12-04T15:27:50Z",
          "delivery_timestamp": "2024-12-04T15:28:20Z"
        }
      },
      {
        "_index": ".commands",
        "_id": "TklIkpMBrdRQWmVi5DGP",
        "_score": 1,
        "_source": {
          "agent": {
            "groups": [
              "groups000"
            ]
          },
          "command": {
            "source": "Engine",
            "user": "user53",
            "target": {
              "type": "agent",
              "id": "target4"
            },
            "action": {
              "name": "restart",
              "args": [],
              "version": "v4"
            },
            "timeout": 30,
            "status": "PENDING",
            "order_id": "SUlIkpMBrdRQWmVi5DGO",
            "request_id": "SElIkpMBrdRQWmVi5DGO"
          },
          "@timestamp": "2024-12-04T15:27:50Z",
          "delivery_timestamp": "2024-12-04T15:28:20Z"
        }
      }
    ]
  }
}

After 1m, we can see these are processed.

Details

{
  "took": 7,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 5,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": ".commands",
        "_id": "S0lIkpMBrdRQWmVi5DGP",
        "_score": 1,
        "_source": {
          "agent": {
            "groups": [
              "groups000"
            ]
          },
          "@timestamp": "2024-12-04T15:27:50Z",
          "delivery_timestamp": "2024-12-04T15:28:20Z",
          "command": {
            "action": {
              "args": [
                "/path/to/executable/arg6",
                "/path/to/executable/arg6",
                "/path/to/executable/arg6",
                "/path/to/executable/arg6"
              ],
              "name": "restart",
              "version": "v4"
            },
            "source": "Engine",
            "user": "user53",
            "order_id": "Q0lIkpMBrdRQWmVi5DGO",
            "request_id": "QklIkpMBrdRQWmVi5DGO",
            "timeout": 30,
            "target": {
              "id": "target4",
              "type": "agent"
            },
            "status": "SENT"
          }
        }
      },
      {
        "_index": ".commands",
        "_id": "SklIkpMBrdRQWmVi5DGO",
        "_score": 1,
        "_source": {
          "agent": {
            "groups": [
              "groups000"
            ]
          },
          "@timestamp": "2024-12-04T15:27:50Z",
          "delivery_timestamp": "2024-12-04T15:28:20Z",
          "command": {
            "action": {
              "args": [
                "/path/to/executable/arg6",
                "/path/to/executable/arg6"
              ],
              "name": "restart",
              "version": "v4"
            },
            "source": "Engine",
            "user": "user53",
            "order_id": "QUlIkpMBrdRQWmVi5DGO",
            "request_id": "QElIkpMBrdRQWmVi5DGO",
            "timeout": 30,
            "target": {
              "id": "target4",
              "type": "agent"
            },
            "status": "SENT"
          }
        }
      },
      {
        "_index": ".commands",
        "_id": "TUlIkpMBrdRQWmVi5DGP",
        "_score": 1,
        "_source": {
          "agent": {
            "groups": [
              "groups000"
            ]
          },
          "@timestamp": "2024-12-04T15:27:50Z",
          "delivery_timestamp": "2024-12-04T15:28:20Z",
          "command": {
            "action": {
              "args": [
                "/path/to/executable/arg6",
                "/path/to/executable/arg6",
                "/path/to/executable/arg6",
                "/path/to/executable/arg6"
              ],
              "name": "restart",
              "version": "v4"
            },
            "source": "Engine",
            "user": "user53",
            "order_id": "R0lIkpMBrdRQWmVi5DGO",
            "request_id": "RklIkpMBrdRQWmVi5DGO",
            "timeout": 30,
            "target": {
              "id": "target4",
              "type": "agent"
            },
            "status": "SENT"
          }
        }
      },
      {
        "_index": ".commands",
        "_id": "TElIkpMBrdRQWmVi5DGP",
        "_score": 1,
        "_source": {
          "agent": {
            "groups": [
              "groups000"
            ]
          },
          "@timestamp": "2024-12-04T15:27:50Z",
          "delivery_timestamp": "2024-12-04T15:28:20Z",
          "command": {
            "action": {
              "args": [
                "/path/to/executable/arg6",
                "/path/to/executable/arg6",
                "/path/to/executable/arg6"
              ],
              "name": "restart",
              "version": "v4"
            },
            "source": "Engine",
            "user": "user53",
            "order_id": "RUlIkpMBrdRQWmVi5DGO",
            "request_id": "RElIkpMBrdRQWmVi5DGO",
            "timeout": 30,
            "target": {
              "id": "target4",
              "type": "agent"
            },
            "status": "SENT"
          }
        }
      },
      {
        "_index": ".commands",
        "_id": "TklIkpMBrdRQWmVi5DGP",
        "_score": 1,
        "_source": {
          "agent": {
            "groups": [
              "groups000"
            ]
          },
          "@timestamp": "2024-12-04T15:27:50Z",
          "delivery_timestamp": "2024-12-04T15:28:20Z",
          "command": {
            "action": {
              "args": [],
              "name": "restart",
              "version": "v4"
            },
            "source": "Engine",
            "user": "user53",
            "order_id": "SUlIkpMBrdRQWmVi5DGO",
            "request_id": "SElIkpMBrdRQWmVi5DGO",
            "timeout": 30,
            "target": {
              "id": "target4",
              "type": "agent"
            },
            "status": "SENT"
          }
        }
      }
    ]
  }
}

In the Imposter logs, we can see the reception:

16:28:31 INFO  i.g.i.p.o.s.ResponseTransmissionServiceImpl - Serving mock example for POST https://127.0.0.1:55000/orders with status code 200 (response body 225 bytes)
16:28:31 DEBUG i.g.i.h.AbstractResourceMatcher - Matched resource config for POST https://127.0.0.1:55000/orders
16:28:31 WARN  i.g.i.s.ResponseServiceImpl - Response file and data are blank for [873be66d-e438-4bfa-afc8-da78abcd036d] POST https://127.0.0.1:55000/orders
16:28:31 DEBUG i.g.i.p.o.OpenApiPluginImpl - Setting content type [application/json] from specification for POST https://127.0.0.1:55000/orders
16:28:31 DEBUG i.g.i.p.o.s.ExampleServiceImpl - No exact match found for accepted content types - choosing first item found (application/json) from specification. You can switch off this behaviour by setting configuration option 'pickFirstIfNoneMatch: false'
16:28:31 INFO  i.g.i.p.o.s.ResponseTransmissionServiceImpl - Serving mock example for POST https://127.0.0.1:55000/orders with status code 200 (response body 225 bytes)
16:28:31 DEBUG i.g.i.h.AbstractResourceMatcher - Matched resource config for POST https://127.0.0.1:55000/orders
16:28:31 WARN  i.g.i.s.ResponseServiceImpl - Response file and data are blank for [4d1758df-c0b7-4177-a0a2-12198f26e683] POST https://127.0.0.1:55000/orders
16:28:31 DEBUG i.g.i.p.o.OpenApiPluginImpl - Setting content type [application/json] from specification for POST https://127.0.0.1:55000/orders
16:28:31 DEBUG i.g.i.p.o.s.ExampleServiceImpl - No exact match found for accepted content types - choosing first item found (application/json) from specification. You can switch off this behaviour by setting configuration option 'pickFirstIfNoneMatch: false'

@AlexRuiz7 AlexRuiz7 merged commit 270e9b5 into master Dec 4, 2024
1 check passed
@AlexRuiz7 AlexRuiz7 deleted the 87-implement-job-schduler-logic branch December 4, 2024 15:46
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.

Implement the job-scheduler logic
3 participants