{
  "$schema": "http://json-schema.org/draft-04/schema#",

  "description": "public-v2 Schema for messages published by Gateway.",
  "type": "object",
  "properties": {
    "data": {
      "oneOf": [
        {"$ref": "#/definitions/probeData" },
        {"$ref": "#/definitions/managedEntityData" },
        {"$ref": "#/definitions/metricsData" },
        {"$ref": "#/definitions/eventData" }
      ]
    },
    "operation": {
      "enum": [ "create", "update", "delete", "snapshot" ]
    },
    "type" : {
      "enum": [ "probe", "managedEntity", "headline", "table", "severity", "snooze", "userassignment" ]
    }
  },
  "required": [ "data", "operation", "type"],
  "additionalProperties": false,

  "definitions": {
    "probeData": {
      "description": "Schema for messages of type \"probe\"",
      "type": "object",
      "properties": {
        "timestamp": {
          "type": "string", "format": "date-time",
          "description": "Time message is published by Gateway."
        },
        "target": {
          "description": "Geneos path information identifying a probe.",
          "type": "object",
          "properties": {
            "gateway": {
              "type": "string",
              "description": "The Gateway name."
            },
            "probe": {
              "type": "string",
              "description": "The probe name."
            }
          },
          "required": ["gateway", "probe" ],
          "additionalProperties": false
        },
        "parameters": {
          "description": "Configured and run-time parameters of the probe.",
          "type": "object",
          "properties": {
            "osType": {
              "type": "string",
              "description": "The OS type."
            },
            "HostName": {
              "type": "string",
              "description": "The host name."
            },
            "Port": {
              "type": "string",
              "description": "The port."
            },
            "ConState": {
              "type": "string",
              "description": "The status of the probe connection."
            },
            "OS": {
              "type": "string",
              "description": "The OS type and version."
            },
            "Version": {
              "type": "string",
              "description": "The Probe version."
            }
          },
          "required": ["osType" ],
          "additionalProperties": { "type": "string" }
        }
      },
      "required": ["timestamp", "target", "parameters" ],
      "additionalProperties": false
    },

    "managedEntityData": {
      "description": "Schema for messages of type \"managed-entity\"",
      "type": "object",
      "properties": {
        "timestamp": {
          "type": "string", "format": "date-time",
          "description": "Time message is published by Gateway."
        },
        "target": {
          "description": "Geneos path information identifying a managed entity.",
          "type": "object",
          "properties": {
            "gateway": {
              "type": "string",
              "description": "The Gateway name."
            },
            "probe": {
              "type": "string",
              "description": "The probe name."
            },
            "managedEntity": {
              "type": "string",
              "description": "The managed entity name."
            }
          },
          "required": ["gateway", "probe", "managedEntity" ],
          "additionalProperties": false
        },
        "attributes": {
          "type": "object",
          "description": "Configured attributes of the managed entity (may be empty).",
          "additionalProperties": { "type": "string" }
        }
      },
      "additionalProperties": false,
      "required": ["timestamp", "target", "attributes"]
    },

    "metricsData": {
      "description": "Schema for messages of type \"headline\" and \"table\"",
      "type": "object",
      "properties": {
        "sampleTime": {
          "type": "string", "format": "date-time",
          "description": "Time message is published on Gateway."
        },
        "netprobeTime": {
          "type": "string", "format": "date-time",
          "description": "(Optional) Time message is published by data source."
        },
        "target": {
          "type": "object",
          "description": "Geneos path information identifying a dataview.",
          "properties": {
            "gateway": {
              "type": "string"
            },
            "probe": {
              "type": "string"
            },
            "managedEntity": {
              "type": "string"
            },
            "type": {
              "type": "string"
            },
            "sampler": {
              "type": "string"
            },
            "dataview": {
              "type": "string"
            },
            "row": {
              "description": "Row name; not present for headlines.",
              "type": "string"
            },
            "filter": {
              "type": "object",
              "description": "Additional information that helps determine the set of metrics to expect.",
              "required": [ "osType", "pluginName" ],
              "properties": {
                "osType": {
                  "type": "string",
                  "description": "The operating system of the probe hosting the dataview."
                },
                "pluginName": {
                  "type": "string",
                  "description": "The name of the plug-in implementing the sampler."
                }
              }
            }
          },
          "required": [ "gateway", "probe", "managedEntity", "type", "sampler", "dataview", "filter" ],
          "additionalProperties": false
        },
        "row": {
          "type": "object",
          "description": "Metrics data for all headlines or for all columns of a single row",
          "additionalProperties": { "type": "string" }
        },
        "computedColumn": {
          "description": "If present, name of a computed column which changed. If absent for an update, change was to raw columns only",
          "type": "string"
        },
        "computedRow": {
          "description": "If present with value 'true', indicates that the message relates to a computed row",
          "type": "boolean"
        }
      },
      "required": [ "sampleTime", "target", "row" ],
      "additionalProperties": false
    },

    "eventData": {
      "description": "Schema for messages of types \"severity\", \"snooze\" and \"userassignment\".",
      "type": "object",
      "properties": {
       "timestamp": {
         "type": "string", "format": "date-time",
         "description": "Time message is published."
       },
       "target": {
         "type": "object",
         "$ref": "#/definitions/eventTarget"
       },
       "data": {
         "oneOf": [
           { "$ref": "#/definitions/severityData" },
           { "$ref": "#/definitions/snoozeData" },
           { "$ref": "#/definitions/unsnoozeData" },
           { "$ref": "#/definitions/assignmentData" },
           { "$ref": "#/definitions/unassignmentData" }
         ]
       }
      },
      "required": [ "timestamp", "target", "data" ],
      "additionalProperties": false
    },

    "eventTarget": {
      "description": "Geneos path information identifying a single item at any level in the hierarchy.",
      "properties": {
        "gateway": {
          "type": "string"
        },
        "probe": {
          "type": "string"
        },
        "managedEntity": {
          "type": "string"
        },
        "type": {
          "type": "string"
        },
        "sampler": {
          "type": "string"
        },
        "dataview": {
          "type": "string"
        },
        "row": {
          "type": "string"
        },
        "column": {
          "type": "string"
        },
        "filter": {
          "type": "object"
        }
      },
      "required": [ "gateway" ],
      "dependencies": {
        "managedEntity": [ "probe" ],
        "type": [ "managedEntity", "sampler" ],
        "sampler": [ "managedEntity", "type" ],
        "dataview": [ "sampler" ],
        "column": [ "dataview" ],
        "row": [ "column" ],
        "filter": [ "probe" ]
      },
      "additionalProperties": false
    },
    "severityData": {
      "description": "Information about a severity chage and its context.",
      "type": "object",
      "properties": {
        "severity": {
          "enum": [ "UNDEFINED", "OK", "WARNING", "CRITICAL", "UNKNOWN" ],
          "description": "String representing the \"state/@severity\" attribute of the item."
        },
        "previousSeverity": {
          "enum": [ "UNDEFINED", "OK", "WARNING", "CRITICAL", "UNKNOWN" ],
          "description": "Previous severity of the item, if applicable."
        },
        "active": {
          "type": "boolean",
          "description": "The value of the \"state/@active\" attribute of the item."
        },
        "snoozed": {
          "type": "boolean",
          "description": "Whether the data item is currently snoozed."
        },
        "snoozedParents": {
          "type": "integer",
          "description": "The number of parent data items that are snoozed."
        },
        "userAssigned": {
          "type": "boolean",
          "description": "Whether a user is assigned to the data item."
        },
        "value": {
          "type": "object",
          "description": "Only present for a cell or headline: value at the time of the severity change.",
          "properties": {
            "cell": {
              "type": "string",
              "description": "Value of the cell as shown in Active Console."
            },
            "dateTime": {
              "type": "string", "format" : "date-time",
              "description": "The value of the cell as an ISO formatted date-time"
            },
            "number" : {
              "type": "number",
              "description": "The value of the cell as double."
            }
          },
          "required": ["cell"],
          "additionalProperties": false
        }
      },
      "required": [ "severity", "active", "snoozed", "snoozedParents", "userAssigned" ],
      "additionalProperties": false
    },
    "snoozeData": {
      "description": "event of type 'snooze' when item is snoozed",
      "type": "object",
      "properties": {
        "snoozed": {
          "enum": [ true ]
        },
        "snoozedBy": {
          "type": "string",
          "description": "Username of the user who snoozed the item."
        },
        "comment": {
          "type": "string",
          "description": "User entered comment."
        },
        "period": {
          "description": "Indicates form of command used to snooze the item.",
          "enum": [ "Manual", "SeverityTo", "SeverityFrom", "Time", "DateTime", "ValueChanges", "SeverityToOrTime", "Until", "Unknown" ]
        },
        "untilSeverity": {
          "enum": [ "UNDEFINED", "OK", "WARNING", "CRITICAL", "UNKNOWN" ],
          "description": "Value to which severity should change for data item to be automatically unsnoozed."
        },
        "untilSeverityNot": {
          "enum": [ "UNDEFINED", "OK", "WARNING", "CRITICAL", "UNKNOWN" ],
          "description": "Value from which severity should change for data item to be automatically unsnoozed."
        },
        "untilTime": {
          "type": "string", "format": "date-time",
          "description": "Time when the data item will be automatically unsnoozed."
        },
        "untilValueNot": {
          "type": "string",
          "description": "Value from which item should change for it to be automatically unsnoozed."
        }
      },
      "required": [ "snoozed", "snoozedBy", "comment", "period" ],
      "additionalProperties": false
    },
    "unsnoozeData": {
      "description": "event of type 'snooze' when item is unsnoozed",
      "type": "object",
      "properties": {
        "snoozed": {
          "enum": [ false ]
        },
        "unsnoozedBy": {
          "type":"string",
          "description": "Name of the user/system that unsnoozed the item."
        },
        "comment": {
          "type": "string",
          "description": "User entered comment."
        }
      },
      "required": [ "snoozed", "unsnoozedBy" ],
      "additionalProperties": false
    },
    "assignmentData": {
      "description": "event of type userassignment when item is assigned to a user.",
      "type": "object",
      "properties": {
        "userAssigned": {
          "enum": [ true ]
        },
        "assignedTo": {
          "type": "string",
          "description": "Username of the user the item is assigned to."
        },
        "assignedBy": {
          "type":"string",
          "description": "Username of the user who assigned the item."
        },
        "comment": {
          "type": "string",
          "description": "User entered comment."
        },
        "period": {
          "enum": [ "Manual", "SeverityToOK", "SeverityTo", "SeverityFrom", "Time", "SeverityToOrTime", "ValueChanges", "Until", "Unknown" ],
          "description": "Not published by Hub. 'Until' is not used at present by Gateway, but may be introduced without affecting Hub"
        },
        "untilSeverity": {
          "enum": [ "UNDEFINED", "OK", "WARNING", "CRITICAL", "UNKNOWN" ],
          "description": "Value to which severity should change for data item to be automatically unassigned."
        },
        "untilSeverityNot": {
          "enum": [ "UNDEFINED", "OK", "WARNING", "CRITICAL", "UNKNOWN" ],
          "description": "Value from which severity should change for data item to be automatically unassigned."
        },
        "untilTime": {
          "type": "string", "format": "date-time",
          "description": "Time at which data item will be automatically unassigned."
        },
        "untilValueNot": {
          "type": "string",
          "description": "Value from which item should change for it to be automatically unassigned."
        }
      },
      "required": [ "userAssigned", "assignedTo", "assignedBy", "comment", "period" ],
      "additionalProperties": false
    },
    "unassignmentData": {
      "description": "event of type userassignment when item is not assigned to a user.",
      "type": "object",
      "properties": {
        "userAssigned": {
          "enum": [ false ]
        },
        "unassignedBy": {
          "type":"string",
          "description": "Username of the user who unassigned the item."
        },
        "comment": {
          "type": "string",
          "description": "User entered comment."
        }
      },
      "required": [ "userAssigned", "unassignedBy" ],
      "additionalProperties": false
    }
  }
}
