{
  "$id": "https://schemas.binaryedge.io/minion/v2/result",
  "title": "Scanning Engine v2 Minion Result",
  "description": "Results that are emitted by the Minion should match this schema.",
  "type": "object",
  "properties": {
    "body": {
      "$comment": "Conditionals below may apply a module-specific schema to this object."
    },
    "error": {
      "$comment": "No restrictions are placed on what can appear as an error."
    },
    "origin": {
      "$comment": "The host from which the traffic originated.",
      "$ref": "#/$defs/origin"
    },
    "target": {
      "$comment": "The target to which traffic was sent, or the entity which this result describes.",
      "$ref": "#/$defs/target"
    },
    "task": {
      "$comment": "References to objects that describe the work that the scanning engine was directed to perform.",
      "$ref": "#/$defs/task"
    },
    "@timestamp": {
      "$comment": "ISO 8601 date and time at which the result entered the data lake.",
      "type": "string"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "amqp"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/amqp"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "bluekeep"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/bluekeep"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "cassandra"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/cassandra"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "confluence"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/confluence"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "elasticsearch"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/elasticsearch"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "exchange-owa"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/exchange-owa"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "fortinet"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/fortinet"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "ftp"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/ftp"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "grabber"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/grabber"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "influxdb"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/influxdb"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "jarm"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/jarm"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "kubernetes"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/kubernetes"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "manageengine"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/manageengine"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "memcached"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/memcached"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "mongodb"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/mongodb"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "mqtt"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/mqtt"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "mqttinfo"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/mqttinfo"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "netscaler"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/netscaler"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "noop"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/noop"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "nuclei"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/nuclei"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "portscan"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/portscan"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "prestodb"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/prestodb"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "pulse-secure"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/pulse-secure"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "rdp"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/rdp"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "rdp-udp"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/rdp-udp"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "rdweb"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/rdweb"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "redis"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/redis"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "remote-powershell"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/remote-powershell"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "rethinkdb"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/rethinkdb"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "rpcdump"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/rpcdump"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "rsync"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/rsync"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "service"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/service"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "service-simple"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/service-simple"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "smb"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/smb"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "sharepoint"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/sharepoint"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "snmp"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/snmp"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "socks"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/socks"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "ssh"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/ssh"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "sonicwall"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/sonicwall"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "ssl-simple"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/ssl-simple"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "vmware"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/vmware"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "vnc"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/vnc"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "vpn-detect"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/vpn-detect"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "websocket"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/websocket"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "webv2"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/webv2"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task": {
            "properties": {
              "module_name": {
                "const": "x11"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "$ref": "https://schemas.binaryedge.io/minion/modules/x11"
          }
        }
      }
    }
  ],
  "required": [
    "origin",
    "target",
    "task"
  ],
  "additionalProperties": false,
  "$defs": {
    "origin": {
      "type": "object",
      "properties": {
        "address": {
          "$comment": "The IPv4 or IPv6 address from which the traffic that produced this result originated.",
          "$ref": "https://schemas.binaryedge.io/minion/shared-types#/ip-address"
        },
        "country": {
          "$country": "The ISO 3166-1 alpha-2 code associated with a country in which the host that produced this result was located.",
          "type": "string"
        },
        "metacluster": {
          "$comment": "The name of the group of machines to which the host that produced this result belonged.",
          "type": "string"
        },
        "port": {
          "$comment": "The TCP or UDP port from which the traffic that produced this result originated.",
          "$ref": "https://schemas.binaryedge.io/minion/shared-types#/port-integer"
        },
        "provider": {
          "$country": "The provider with which the host that produced this result was hosted.",
          "type": "string"
        },
        "region": {
          "$country": "The provider-specific region name in which the host that produced this result was located.",
          "type": "string"
        },
        "ts": {
          "$comment": "This is the most accurate timestamp of when the result was generated, in milliseconds since the UTC Unix Epoch.",
          "$ref": "https://schemas.binaryedge.io/minion/shared-types#/epoch-milliseconds-integer"
        }
      },
      "required": [
        "ts"
      ],
      "additionalProperties": false
    },
    "target": {
      "type": "object",
      "properties": {
        "address": {
          "$comment": "The IPv4 or IPv6 address to which the traffic that produced this result was destined.",
          "$ref": "https://schemas.binaryedge.io/minion/shared-types#/ip-address"
        },
        "as_name": {
          "$comment": "The autonomous system name (e.g., Google LLC) associated with the target's address.",
          "type": "string"
        },
        "asn": {
          "$comment": "The autonomous system number (e.g., AS15169) associated with the target's address.",
          "type": "string"
        },
        "country_code": {
          "$comment": "The ISO 3166-1 alpha-2 code for the country associated with the target's address.",
          "type": "string"
        },
        "encryption": {
          "$comment": "The encryption protocol used to produce this result, if any.",
          "type": "string",
          "enum": [
            "SSLv3.0",
            "TLSv1.0",
            "TLSv1.1",
            "TLSv1.2",
            "TLSv1.3",
            "DTLSv1.0",
            "DTLSv1.2",
            "DTLSv1.3"
          ]
        },
        "hostname": {
          "$comment": "The hostname of the target, if available.",
          "type": "string"
        },
        "port": {
          "$comment": "The TCP or UDP port to which the traffic that produced this result was destined.",
          "$ref": "https://schemas.binaryedge.io/minion/shared-types#/port-integer"
        },
        "protocol": {
          "$comment": "The transport protocol of the traffic, if any, used to produce this result.",
          "type": "string",
          "enum": [
            "TCP",
            "UDP"
          ]
        },
        "tags": {
          "$comment": "Target metadata defined by either the scanning engine or its users (e.g., `default-address`, `tls`).",
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    },
    "task": {
      "type": "object",
      "properties": {
        "client_id": {
          "$comment": "The ID of the client that submitted the job that generated this result.",
          "type": "string"
        },
        "id": {
          "$comment": "The ID of the task that produced this result.",
          "type": "string",
          "format": "uuid"
        },
        "job_id": {
          "$comment": "The ID of the job that generated the task that produced this result.",
          "type": "string",
          "format": "uuid"
        },
        "job_date": {
          "$comment": "The YYYY-MM-DD of the job that generated the task that produced this result. This date is extracted from the job_id's UUIDv7.",
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
        },
        "module_index": {
          "$comment": "Job definitions can contain multiple module invocations for the same module with potentially different configurations. This field is a 1-based index of the `modules` key of a job, allowing results to be mapped to module invocations. Zero represents modules that were implicitly added to the job (e.g., portscan)",
          "type": "integer",
          "minimum": 0
        },
        "module_name": {
          "$anchor": "module-name-enum",
          "$comment": "This is an exhaustive list of all publicly-available modules.",
          "type": "string",
          "enum": [
            "amqp",
            "bluekeep",
            "cassandra",
            "confluence",
            "elasticsearch",
            "exchange-owa",
            "fortinet",
            "ftp",
            "grabber",
            "influxdb",
            "jarm",
            "kubernetes",
            "manageengine",
            "memcached",
            "mongodb",
            "mqtt",
            "mqttinfo",
            "netscaler",
            "noop",
            "nuclei",
            "portscan",
            "prestodb",
            "pulse-secure",
            "rdp",
            "rdp-udp",
            "rdweb",
            "redis",
            "remote-powershell",
            "rethinkdb",
            "rpcdump",
            "rsync",
            "service",
            "service-simple",
            "sharepoint",
            "smb",
            "snmp",
            "socks",
            "sonicwall",
            "ssh",
            "ssl-simple",
            "vmware",
            "vnc",
            "vpn-detect",
            "websocket",
            "webv2",
            "x11"
          ]
        },
        "module_version": {
          "$comment": "The version of the module that produced this result.",
          "type": "string"
        },
        "result_index": {
          "$comment": "The 1-based index of this result in the result stream produced by the Minion.",
          "type": "integer",
          "minimum": 1
        },
        "shard_id": {
          "$comment": "The ID of the shard that produced this result.",
          "type": "string",
          "format": "uuid"
        },
        "topic_id": {
          "$comment": "The topic in which the job was placed, limiting the metaclusters that could execute the task.",
          "type": "string"
        }
      },
      "required": [
        "client_id",
        "id",
        "job_id",
        "module_index",
        "module_name",
        "module_version",
        "result_index",
        "shard_id",
        "topic_id"
      ],
      "additionalProperties": false
    }
  }
}
