{
    "id": "health.json",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "description": "Describes the links and schemas for a specified tenant.",
    "$ref": "#/definitions/healthSummary",
    "links": [
        {
            "title": "Summary",
            "href": "/",
            "method": "GET",
            "schema": {
                "$ref": "#/definitions/healthSummary"
            }
        },
        {
            "title": "Nodes Status",
            "href": "/nodes",
            "method": "GET",
            "schema": {
                "$ref": "#/definitions/nodesStatusList"
            }
        },
        {
            "title": "Status of a specific node",
            "href": "/nodes/{nodeId}",
            "method": "GET",
            "rel": "self",
            "schema": {
                "$ref": "#/definitions/nodeStatus"
            }
        },
        {
            "title": "Get Node specific time",
            "href": "/nodes/{nodeId}/time",
            "method": "GET",
            "rel": "self",
            "schema": {
                "$ref": "#/definitions/nodeTime"
            }
        },
        {
            "title": "Status of a specific node",
            "href": "/nodes/{nodeId}/{processName}",
            "method": "GET",
            "rel": "self",
            "schema": {
                "$ref": "#/definitions/processStatus"
            }
        },
        {
            "title": "Status of a specific node",
            "href": "/nodes/{nodeId}/{processName}/history",
            "method": "GET",
            "rel": "self",
            "schema": {
                "$ref": "#/definitions/processHealthHistory"
            }
        },
        {
            "title": "Get Thresholds",
            "href": "/thresholds",
            "method": "GET",
            "rel": "self",
            "schema": {
                "$ref": "#/definitions/thresholdList"
            }
        },
        {
            "title": "Update Thresholds",
            "href": "/thresholds",
            "method": "PUT",
            "rel": "self",
            "schema": {
                "$ref": "#/definitions/thresholdList"
            }
        },
        {
            "title": "Get Disk Util Thresholds",
            "href": "/thresholds/diskUtilization",
            "method": "GET",
            "rel": "self",
            "schema": {
                "$ref": "#/definitions/diskThreshold"
            }
        },
        {
            "title": "Update Disk Util Thresholds",
            "href": "/thresholds/diskUtilization",
            "method": "PUT",
            "rel": "self",
            "schema": {
                "$ref": "#/definitions/diskThreshold"
            }
        },
        {
            "title": "Update SMTP Config",
            "href": "/smtpconfig",
            "method": "PUT",
            "rel": "self",
            "targetSchema" : {
                "$ref" : "#/definitions/smtpconfig"
            },
            "schema": {
                "$ref": "#/definitions/updateSmtpconfig"
            }
        },
        {
            "title": "GET SMTP Config",
            "href": "/smtpconfig",
            "method": "GET",
            "rel": "self",           
            "schema": {
                "$ref": "#/definitions/smtpconfig"
            }
        },
        {
            "title": "Update Email Alert subscribers",
            "href": "/subscribers",
            "method": "PUT",
            "rel": "self",
            "schema": {
                "$ref": "#/definitions/subscriberList"
            }
        },
        {
            "title": "Delete Email Alert subscriber",
            "href": "/subscribers",
            "method": "DELETE",
            "rel": "self",
            "schema": {
                "$ref": "#/definitions/subscriber"
            }
        }
    ],
    "definitions": {
        "nodeTime" : {
            "type" : "object",
            "properties" : {
                "node": {
                    "type": "string",
                    "description": "Hostname/node id in the cluster."
                },
                "time": {
                    "type": "string",
                    "description": "Host time",
                    "format": "datetime"
                }
            }
        },
        "subscriberList": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/subscriber"
            }
        },
        "subscriber": {
            "type": "object",
            "required": [
                "email"
            ],
            "properties": {
                "email": {
                    "type": "string",
                    "description": "Email address of recipient"
                },
                "options": {
                    "type": "object",
                    "description": "Email subscription options",
                    "required": [
                        "enabled",
                        "severities",
                        "types"
                    ],
                    "properties": {
                        "enabled": {
                            "type": "boolean",
                            "description": "True if the subscriber is enabled to received email alerts"
                        },
                        "severities": {
                            "type": "array",
                            "description": "Subscribed alert severities",
                            "items": {
                                "type": "string",
                                "enum": [
                                    "info", "warning", "critical"
                                ]
                            }
                        },
                        "types": {
                            "type": "array",
                            "description": "Subscribed alert type",
                            "items": {
                                "type": "string",
                                "enum": [
                                    "license", "process", "time", "diskThreshold"
                                ]
                            }
                        }
                    }
                }
            }
        },
        "smtpconfig": {
            "type": "object",
            "description": "Email SMTP config for email alerts",
            "required": [
               "enabled"                
            ],
            "properties": {
                "host": {
                    "type": "string",
                    "description": "SMTP host (IP Address or FDQN)"
                },
                "port": {
                    "type": "integer",
                    "description": "SMTP port"
                },
                "secure": {
                    "type": "boolean",
                    "description": "Is it using SSL ?"
                },
                "username": {
                    "type": "string",
                    "description": "SMTP username"
                },
                "password": {
                    "type": "string",
                    "description": "SMTP password"
                },
                "enabled": {
                    "type": "boolean",
                    "description": "SMTP server enabled ?"
                },
                "isPasswdSet" : {
                    "type": "boolean",
                    "description": "indicates ?"
                }
            }
        },
        "updateSmtpconfig": {
            "type": "object",
            "description": "Email SMTP config for email alerts",
            "required": [
                "host",
                "port",
                "secure",
                "username",
                "enabled"
            ],
            "properties": {
                "host": {
                    "type": "string",
                    "description": "SMTP host (IP Address or FDQN)"
                },
                "port": {
                    "type": "integer",
                    "description": "SMTP port"
                },
                "secure": {
                    "type": "boolean",
                    "description": "Is it using SSL ?"
                },
                "username": {
                    "type": "string",
                    "description": "SMTP username"
                },
                "password": {
                    "type": "string",
                    "description": "SMTP password"
                },
                "enabled": {
                    "type": "boolean",
                    "description": "SMTP server enabled ?"
                },
                "isPasswdSet" : {
                    "type": "boolean",
                    "description": "indicates ?"
                }
            }
        },
        "healthSummary": {
            "type": "object",
            "description": "List health summary, in this release only the list of URLs is provided",
            "properties" : {
                "links": {"$ref" : "common.json#/definitions/APILinkList","description" :"list of urls supported."}
            }
        },
        "thresholdList": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/threshold"
            }
        },
        "diskThresholdValue": {
            "description": "Disk utilization/free space threshold value: it can be either a number (number of free space left, in MB), or string representing either the percentage (80%) or the free disk space in Gb, Mb, Tb ",
            "oneOf": [
                {
                    "type": "integer",
                    "description": "Number of free space in MB",
                    "minimum": 0
                },
                {
                    "type": "string",
                    "description": "Percent of free space of size with postfix ",
                    "pattern": "^(\\d+%)|(\\d+([TKkMmGg][bB]?)?)$"
                }
            ]
        },
        "diskThreshold": {
            "type": "object",
            "description": "Disk utilization/free space thresholds ",
            "required": [
                "id",
                "node",
                "critical",
                "warning",
                "partition"
            ],
            "properties": {
                "id": {
                    "type": "string",
                    "enum": [
                        "diskUtilization"
                    ]
                },
                "node": {
                    "type": "string",
                    "description": "Hostname/node id in the cluster."
                },
                "partition": {
                    "type": "string",
                    "description": "Identify for which partition the threshold is for. The threshold is valid only for that partition and not other mount point, even though it might be under that mount point. I.e if the threshold is for /var and there is another mount point for /var/log, /var/log will not be monitored by /var entry."
                },
                "critical": {
                    "$ref": "#/definitions/diskThresholdValue"
                },
                "warning": {
                    "$ref": "#/definitions/diskThresholdValue"
                }
            }
        },
        "threshold": {
            "type": "object",
            "required": [
                "id"
            ],
            "oneOf": [
                {
                    "$ref": "#/definitions/diskThreshold"
                }
            ]
        },
        "CPUInformation": {
            "type": "object",
            "description": "CPU Information",
            "properties": {
                "pcpu": {
                    "type": "string",
                    "description": "CPU Utilization Percentage in string format between 0 and 100",
                    "pattern" : "[0-9]+(\\.[0-9])?"
                }
            }
        },
        "discSpaceInformation": {
            "type": "object",
            "properties": {
                "total": {
                    "type": "number",
                    "description": "Total space in MB"
                },
                "free": {
                    "type": "number",
                    "description": "Free space in MB"
                },
                "used": {
                    "type": "number",
                    "description": "Used space in MB"
                },
                "usage": {
                    "type": "integer",
                    "description": "Percentage of used space",
                    "minimum": 0,
                    "maximum": 100
                },
                "partition": {
                    "type": "string",
                    "description": "OS mount point"
                }
            }
        },
        "processHealthHistory": {
            "type": "array",
            "$ref": "#/definitions/processHealthEntry"
        },
        "processHealthEntry": {
            "type": "object",
            "properties": {
                "timestamp": {
                    "type": "string",
                    "description": "ISO 8101 timestamp",
                    "format": "datetime"
                },
                "rss": {
                    "type": "integer",
                    "description": "Resident Set Size"
                },
                "vsz": {
                    "type": "integer",
                    "description": "Virtual Set Size"
                }
            },
            "oneOf": [
                {
                    "$ref": "#/definitions/CPUInformation"
                }
            ]
        },
        "processStatus": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string",
                    "description": "Process Name"
                },
                "pid": {
                    "type": "integer",
                    "description": "Process id"
                },
                "user": {
                    "type": "string",
                    "description": "user"
                },
                "group": {
                    "type": "string",
                    "description": "group name"
                },
                "time": {
                    "type": "string",
                    "description": "Duration the process is running",
                    "format": "datetime"
                },
                "cmd": {
                    "type": "string",
                    "description": "Process command"
                },
                "history": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/processHealthHistory"
                    }
                }
            },
            "oneOf": [
                {
                    "$ref": "#/definitions/processHealthEntry"
                }
            ]
        },
        "highAvailabilityRole": {
            "description": "HA Role",
            "enum": [
                "Active",
                "Standby",
                "Coordinator",
                "Standalone"
            ],
            "type": "string"
        },
        "nodeStatus": {
            "type": "object",
            "properties": {
                "nodeType": {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "enum": [
                            "northstar",
                            "dataCollector"
                        ]
                    }
                },
                "node": {
                    "type": "string",
                    "description": "hostname/node id inthe cluster"
                },
                "clusterIPs": {
                    "type": "array",
                    "description": "List of IP address used for clustering for the node, it can be used to identify more uniquely the node if several clusters share the same hostnmaeand internal IP addresses.",
                    "items": {
                        "type": "string",
                        "format": "ipv4",
                        "description": "Node IP address in the cluster"
                    }
                },
                "role": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/highAvailabilityRole"
                    }
                },
                "CPU": {
                    "type": "object",
                    "description": "CPU Information (global and per-CPU)",
                    "properties": {
                        "CPUs": {
                            "type": "array",
                            "description": "Per-CPU utilization.",
                            "items": {
                                "$ref": "#/definitions/CPUInformation"
                            }
                        }
                    },
                    "oneOf": [
                        {
                            "$ref": "#/definitions/CPUInformation"
                        }
                    ]
                },
                "disk": {
                    "type": "object",
                    "description": "disk information",
                    "properties": {
                        "partitions": {
                            "type": "array",
                            "description": "Per-partion utilization.",
                            "items": {
                                "$ref": "#/definitions/discSpaceInformation"
                            }
                        }
                    }
                },
                "memory": {
                    "type": "object",
                    "properties": {
                        "total": {
                            "type": "number",
                            "description": "Free space in MB?"
                        },
                        "free": {
                            "type": "number",
                            "description": "Free space in MB?"
                        },
                        "usage": {
                            "type": "integer",
                            "description": "Used memory in MB?"
                        }
                    }
                },
                "processes": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/processStatus"
                    }
                },
                "status": {
                    "$ref": "#/definitions/hostStatus",
                    "description": "The host Status."
                }
            }
        },
        "hostStatus": {
            "description": "Host Status, timeout specifically indicates a health monitor timeout/communication error/timeout",
            "enum": [
                "Up",
                "Down",
                "Timeout"
            ],
            "type": "string"
        },
        "nodesStatusList": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/nodeStatus"
            }
        }
    }
}
        
